954,479 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Adding 2 numbers using debug

I have a problem when adding 2 numbers in assembly because we are using hex.
When add 4+5 (34h + 35h) the output is 9 but if I add 5+5 (35h + 35h) the output displays colon(:) or 3ah instead of 10.

Here's the sample image when i generate the code.
[IMG]http://i42.tinypic.com/35hpkhs.jpg[/IMG]

Here's my code.

Run>debug
5+4 = 9

a100 ;assemble
mov ah,02
mov ch,35 ;5
mov cl,35
add cl,ch ;5+5
sub cl,30 ;-30
mov dl,cl
int 21
int 20

g

Adding 5 + 5 = :

-a100
mov ah,02
mov ch,34 ;4
mov cl,35
add cl,ch
sub cl,30
mov dl,cl
int 21
int 20

-g


Thanks in advance for your reply.

JRE.A
Newbie Poster
2 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

Subtract the 30h before doing the math.
Keep in mind: what you are after is not a single character after you go above 9.
You are dealing with the difference between the ASCII chart, actual values and what a human expects to "see".

Once above 9, you will need to convert the hex to decimal (or value to string).

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: