printing a digit (as a character)

Reply

Join Date: Oct 2009
Posts: 2
Reputation: andreib is an unknown quantity at this point 
Solved Threads: 0
andreib andreib is offline Offline
Newbie Poster

printing a digit (as a character)

 
-1
  #1
Oct 1st, 2009
Hello!
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:
  1. mov ax, 2005
  2. mov cx, 10
  3. div cx ; now, AH should contain the remainder (5) and AL = 200
  4. mov al, ah ; because AL should contain the character to print
  5. add al, 48 ; because ASCII code for 5 is 53 (decimal).
  6. mov ah, 0Eh; the function for the 10h interrupt
  7. int 10h
I can't understand why 0 is printed to the screen instead of 5. If i change the line
  1. add al, 48
  2. to
  3. 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!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: andreib is an unknown quantity at this point 
Solved Threads: 0
andreib andreib is offline Offline
Newbie Poster

Re: printing a digit (as a character)

 
0
  #2
Oct 1st, 2009
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
  1. mov cl, 10
  2. 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
DIV source
I should have a 8-bit source.

sorry for bothering
andreib
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 133
Reputation: NotNull is an unknown quantity at this point 
Solved Threads: 13
NotNull's Avatar
NotNull NotNull is offline Offline
Junior Poster

Re: printing a digit (as a character)

 
0
  #3
Oct 1st, 2009
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
----------------------------------------------------------
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
Reply With Quote Quick reply to this message  
Reply

Tags
division, int10h, integer, print, remainder

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC