; Description: Program to input a character and then output it to the screen
 ; Registers used:   ax, dx
 .model small
 .stack 100h
 .data
.code
 
        mov ah, 02h      ; DOS function call 2, character output
 mov dl, 41h       ; the character 041h (i.e.'A')
        mov cx, 26              ; start the counter at 26 in cx
again: int 21h          ; print character
 inc dl           ; the next character into dl
 loop again           ; subtract 1 from cx, if not zero jump back to again
finish:       mov ax, 4C00h  ; Terminate program
               int 21h   ; correctly
 
end

The above loops from capital A to Z and prints out all charaters.What I'm wondering is could the above loop be used to print out A-Z and its corresponding ASCII value (e.g)

A 65
B 66
C 67

I'm guessing I'll need a unconditional loop,and some sort of comparison check...anyones input as to how I would go about coding this would be very much appreciated.Thanks.

string    db   4 dup( ' ' ), '$'
 
mov al, 41h ; the character 041h (i.e.'A')
mov cx, 26 ; start the counter at 26 in cx
 
again:
push ax                                    ;save character
mov string[ 0 ], al                     ;copy character to start of string
mov bh, 10
div bh                                      ;MS digit of ascii code into al, LS digit into ah
add ax, '00'                              ;convert digits into ascii codes
mov word ptr string[ 2 ], ax       ;copy digits into string
mov ah, 9                                ;print string
int 21h
pop ax                                     ;retrieve character
inc al                                       ;next character
loop again ; subtract 1 from cx, if not zero jump back to again
finish: mov ax, 4C00h ; Terminate program
int 21h ; correctly
string    db   4 dup( ' ' ), '$'
 
mov al, 41h ; the character 041h (i.e.'A')
mov cx, 26 ; start the counter at 26 in cx
 
again:
push ax                                    ;save character
mov string[ 0 ], al                     ;copy character to start of string
mov bh, 10
div bh                                      ;MS digit of ascii code into al, LS digit into ah
add ax, '00'                              ;convert digits into ascii codes
mov word ptr string[ 2 ], ax       ;copy digits into string
mov ah, 9                                ;print string
int 21h
pop ax                                     ;retrieve character
inc al                                       ;next character
loop again ; subtract 1 from cx, if not zero jump back to again
finish: mov ax, 4C00h ; Terminate program
int 21h ; correctly

thanks for the help,and sorry for my late reply...

If you use a mutant form of AAM or AAD (I forget which right now) that uses 16 as its base rather than 10, it will cleanly split the nibbles in AL into AH and AL.

IOW - 0x35 would become 0x0305

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.