I'm kind of new in assembly programming and I've been struggling with the following problem today:
How to print an integer, using BIOS interrupt 10h, with its 0Eh in AH register, as its function to print a character to the screen...

For example, how to print the last digit of 2005.
here's what I've tried, using division by 10:

mov ax, 2005
mov cx, 10
div cx     ; now, AH should contain the remainder (5) and AL = 200
mov al, ah ; because AL should contain the character to print
add al, 48 ; because ASCII code for 5 is 53 (decimal).
mov ah, 0Eh; the function for the 10h interrupt
int 10h

I can't understand why 0 is printed to the screen instead of 5. If i change the line

add al, 48
add al, 49

it prints out 1.
... am I missing something? is it because I use decimal format for integers instead of the hexadecimal one?

Thank you in advance!

7 Years
Discussion Span
Last Post by NotNull

I'm replaying to my post...
:) I've found the answer to the problem while posting the question and running the code on my computer... I hope I did well by posting it, maybe someone is having the same integer printing related issue.

The thing is I had to write

mov cl, 10
div cl

because with whole CX instead of its low part (CL), after division the remainder is stored somewhere else (I think in DX, and it's not the right one anyway...) so, in the instruction below

[I]DIV source[/I]

I should have a 8-bit source.

sorry for bothering :)


2005 - 2000 = 5 / 1 = 5 got it???
The actual value of the asci characte '5' is 0x35,
well there you go!

Understanding the DIV instruction:
DIV reg16 = DX:AX / reg16 = quotient AX remainder DX
DIV reg8 = AX / reg8 = quotient AL remainder AH

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.