1

Mam/Sir Somebody can help me!!!!

I did the format that displayed of the horizontal position after input the single character and so that is a requirement of the output

So this is a expected output

The output should be like this: EVEN EVEN

Input: X

xyz

The requirement should be one input character, first problem is, i didn't not displayed of the lowercase letter when you inputting the uppercase letter, and the last problem is validation instead of the typing the single lowercase it converts to displayed of the uppercase, The validation it should be type the uppercase and it converts to displayed the lowercase, when you type the single lowercase letter it should be not displayed the output this is one of the problem!!!!

Here is my code

.model small
.stack
.data
    input db "Input: $"
.code
org 100h

start:

    main proc

        mov ax,03
        int 10h

        mov ax,@data
        mov ds,ax   

        mov ah,9     
        lea dx, input
        int 21h

        mov ah,01
        int 21h

        mov dh,al
                mov ah,02
                mov dl,9
                int 21h
                mov dl,13
                int 21h

        mov cx,11
        W:
            mov dl,10
            int 21h
            LOOP W

        mov al,dh

        mov bl,al

        cmp bl, 'a'
        jb main
        cmp bl, 'z'
        ja main

        mov dl,al
        sub dl,20h

        mov ah,02
        int 21h

        mov cx,26
        mov dh,dl

            letters:

                 mov bx,cx

                 mov dl,dh

                 cmp dl,'Z'
                 je exit

                 inc dl
                 int 21h
                 mov dh,dl
                 mov cx,bx

            loop letters



        mov ah,4ch
        int 21h
    main endp

    down proc
                mov dl,13
                int 21h
                mov dl,10
                int 21h
                ret
            down endp

            exit proc

        mov cx,12
        Q:
            call down
            LOOP Q
            mov ah, 9

                mov ah,4ch
                int 21h
            exit endp

end start
Jezer Gùtierrez
  • 21
  • 1
  • 1
  • 3
  • 3
    You can detect if a letter is upper case by comparing its value from 'A' to 'Z'. To convert to lower case, you only need to 'or' in a single bit of info. Just look at an ASCII table and compare the distance between 'A' and 'a' and you should be able to see. – Michael Dorgan Feb 18 '17 at 00:28

2 Answers2

1

Assuming that edi contains your character:

lea     edx, [edi - ('A')]     ; we substract the value of the letter A
mov     eax, edi     ; return value set to input value
or      edi, 0x20    ; create a lowercase version
cmp     edx, 'Z'-'A' ; that we will use only if we were facing an upper case character
cmovb   eax, edi     ; if it was, we move value from edi to eax

Credit: Peter Cordes for the shorter code and the bug fix.

You could also use a lookup table.

Antonin GAVREL
  • 7,991
  • 4
  • 44
  • 60
  • 1
    You don't need to create a boolean in a register and `test` it. Also, your code has a bug if ECX has any non-zero bytes above CL, because you test the full reg after writing the low 8. Use `lea` to copy-and-subtract and OR *before* CMP. – Peter Cordes Apr 20 '20 at 03:22
  • 1
    Ok that works, although IDK if TASM even has a `.686` option that would let it assemble `cmov`. In 16-bit code, `lea dx, [di - 'A']` is still a valid addressing mode so you could still do that if you were using the same register-args layout as x86-64 System V. – Peter Cordes Apr 20 '20 at 03:51
0

use xor with 32. But be aware it could change upper to lower and vise versa.

xor al, 32              
mov array[esi], al
  • Related: [What is the idea behind ^= 32, that converts lowercase letters to upper and vice versa?](https://stackoverflow.com/a/54585515) If you want to force lowercase, use `or` not `xor`. But if you need to leave non-letter unmodified, you need a conditional anyway. – Peter Cordes Nov 02 '21 at 12:43