944,147 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 2028
  • Assembly RSS
Oct 1st, 2009
-1

printing a digit (as a character)

Expand Post »
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:
Assembly Syntax (Toggle Plain Text)
  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
Assembly Syntax (Toggle Plain Text)
  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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
andreib is offline Offline
2 posts
since Oct 2009
Oct 1st, 2009
0

Re: printing a digit (as a character)

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
Assembly Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
andreib is offline Offline
2 posts
since Oct 2009
Oct 1st, 2009
0

Re: printing a digit (as a character)

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
Reputation Points: 36
Solved Threads: 19
Junior Poster
NotNull is offline Offline
198 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: String to integer
Next Thread in Assembly Forum Timeline: anyone know how to encrypt?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC