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

3 Answers3

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
  • 9,682
  • 8
  • 54
  • 81
  • 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
0
org 100h

.model small
.data 
     msg1 db 13,10, "Enter an upper case letter: $"
     msg2 db 13,10, "In lower case: $"
.code 
main proc
    
    mov ax,@data
    mov dx,ax
    
    mov dx,offset msg1
    
    mov ah,9
    int 21h

mov ah,1
int 21h 

mov bl,al

add bl,32 ;for lower case to upper case simply sub bl,32

 mov ax,@data
    mov dx,ax
    
    mov dx,offset msg2
    
    mov ah,9
    int 21h

mov dl,bl

mov ah,2
int 21h

mov ah,4ch
int 21h
    
    
  main endp
end main

ret

  • 1
    The code fails to initialize DS. You erroneously write `@data` to the D**X** register instead of to the D**S** register! Also, it's useless to setup DS twice. Please don't post a new answer each time. Click the EDIT button under your answer. – Sep Roland Jul 01 '22 at 20:04
  • why use the DS register when it works completely fine with DX register? – Areeba Hamood Jul 01 '22 at 20:31
  • 1
    Why indeed? What you store in DX is totally bogus; it serves no purpose at all. Why it works nonetheless is because that, due to the `ORG 100h` directive, emu8086 generates a program where DS happens to have the correct value at the start. – Sep Roland Jul 01 '22 at 20:35
  • I have studied this way. – Areeba Hamood Jul 02 '22 at 10:02
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 07 '22 at 17:34