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

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.