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

Displaying numeric data

Hi, I'm new to 80x86 Assembler...

My question is very simple one: how should i print number on screen?

I used the following code to print ascii data:

mov ah,09h    ;load code of print function
  lea dx, Var     ;load address of variable to be printed
  int 21h           ;DOS call 
 
..........................
Var db 'SOME_DATA','$'


When i needed to define numeric data, i changed this to:

Var db 4 ; an integer to be printed

and used the same sequence to print as it was with the string data. But program printed out only unreadable set of ascii characters

What's wrong with my code?

Also,how i could print data stored in one of the registers?

Thank you in advance

vov4ik
Newbie Poster
16 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

Var contains data which will be evaluated as ASCII , but as 4 is in deciaml it will be evaluated as ASCII value 4 , which is a nonprintable chracter.

You need to convert 4 to ASCII "4" . To convert 4 to ASCII "4" you need to add 30(deciaml) . AS in ASCII "0" starts from 30 and "9" at 39.

You need to separate each digit and change that to ASCII ( in range 30 to 39).

that is to print 17 (decimal) you have to separate 1 and 7 and change it to 1 => 31h and 7 => 37h.

And print as
data db 2dup(0)

mov [data],31h
mov [data+1],37h
lea dx,data
mov ah,09h
int 21h

thandermax
Newbie Poster
14 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

Separation code you need to develop .

It's easy, just mask the upper nibble(4 bit) and get lower nibble .
mask the lower nibble and shift 4 times to left and get the upper nibble.


AND the data with 0fh to mask upper nibble, and with f0h to mask lower nibble.

Hope you got the idea

thandermax
Newbie Poster
14 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

Thank thandermax for your reply... i think i got idea...

vov4ik
Newbie Poster
16 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You