Hello! I am creating an assembly program that accepts a single character and displays the alphabet in reverse. The requirements are (1) The input character should be displayed (2) The alphabet should be displayed vertically and (3) Only the letter 'Z' should be accepted as input.

I have managed to let my program input a character and display the alphabet in reverse however, it is displayed horizontally. I made a proc named nlcr for new line and carriage return but when I call it inside the loop, some weird characters appear. Also, I have not yet made a validation process for the character input but my idea is that I should use conditional jumps and labels, am I right? Can somebody enlighten me on this topic? I'm pretty much new to assembly language. Thank You!

.model small
.stack
.data
 string db "ODD EVEN$"
 string2 db "Input:$"
.code
org 100h
start:

 main proc
 mov ax,03
 int 10h
 mov ax,@data
 mov ds,ax

 mov ah,9
 lea dx,string
 int 21h

 call nlcr

 mov ah,9
 lea dx,string2
 int 21h

 mov ah,1
 int 21h
 mov dl,al
 mov ah,2
 add dl,20h
 int 21h

 mov cx,25
 y:
 mov ah,2
 dec dl
 int 21h
 loop y

 mov ah,4ch
 int 21h
 main endp

 nlcr proc
 mov ah,2
 mov dl,13
 int 21h
 mov dl,10
 int 21h
 ret
 nlcr endp

end start

The output should be like this:
ODD EVEN
Input: Z
z
y
x
.
.
.
a

Nobody is taught to use comments anymore? It is so important to comment your code in Assembly, ESPECIALLY in ancient 16bit code where functions don't have names but numbers!!

Your getting weird characters because after you get the input character, you are modifying it by adding 20h to dl.

To print each letter on a new line, you need to add a call to your nlcr in your y loop, but you must also save the register dx

This should get you started:

 main proc
        mov     ax,@data
        mov     ds, ax

        mov     ah, 9
        lea     dx, string
        int     21h

        call    nlcr

        mov     ah, 9
        lea     dx, string2
        int     21h

        mov     ah, 1       ; get user input
        int     21h
        mov     dl, al

        call    nlcr        ; print CRLF 

        mov     cx, 25      ; print 25 chars in loop
        inc     dl          ; adjust to print input char on 1st iteration
    PrintChar:
        mov     ah, 2       ; print char
        dec     dl
        int     21h

        call    nlcr        ; print CRLF

        loop    PrintChar   ; repeat loop until cx == 0

        mov     ah, 4ch     ; goodbye
        int     21h
    main endp

    nlcr proc
        push    dx          ; save dx since dl contains char to print

        mov     ah, 2
        mov     dl, 13
        int     21h

        mov     dl, 10
        int     21h

        pop     dx          
        ret
    nlcr endp

Nobody is taught to use comments anymore? It is so important to comment your code in Assembly, ESPECIALLY in ancient 16bit code where functions don't have names but numbers!!

Amen

Thank You GunnerInc! I managed to make the code work by following your instructions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.