0

I'm kinda new to assembly and I want to know how to get a char ASCII code and print out that ASCII code. I'm using MASM (Dosbox).

MOV AX, 'A'  ; -> I want to print out the ASCII code of 'A'

Thanks for the answers!

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
daniel19
  • 67
  • 8

1 Answers1

2

From comments

MOV AX, 'A' MOV BX, 10 DIV BL MOV AH, 2 INT 21h

This byte-sized division will leave a quotient in AL and a remainder in AH.
But the DOS.PrintCharacter function 02h expects its input in the DL register.

After DIV: ADD AH, 48 ADD AL, 48

Fine to convert, but you can do it in one go with ADD AX, 3030h

I got this output: ##

Try next code:

mov ax, 'A'
mov bl, 10
div bl
add ax, 3030h
mov dx, ax      ; Moving tens "6" to DL for printing and preserving the units in DH
mov ah, 02h     ; DOS.PrintCharacter
int 21h
mov dl, dh      ; units "5"
mov ah, 02h     ; DOS.PrintCharacter
int 21h

Displaying numbers with DOS has a detailed explanation about how to deal with even bigger numbers.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
  • 1
    First `mov ah, 02h` clobbers `ah` before loading it into `dl`. Better: `mov dx, ax` and `mov dl, dh` – ecm Oct 18 '21 at 21:28
  • I tried the code, but got this output: ##65. The question is why am i getting this: ## – daniel19 Oct 19 '21 at 07:20
  • @daniel19 Those ## must come from *something earlier on* in your program. The code snippet that I posted can not output by itself those redundant characters. Why don't you edit the question and include the whole program source? – Sep Roland Oct 19 '21 at 18:42