HELP - Printing Integers

Reply

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

HELP - Printing Integers

 
0
  #1
Oct 25th, 2006
Hi,

Im just starting out attempting to learn assembly, and ive come across what is probably a really simple stumbling block.. The aid of google has failed me this time and im hoping someone on here can help me.

I started writing a simple program that takes input for an option, and my first option would be to "show the dos version"... Ive ran my code through a debugger and "i think" it is all working correctly, apart from the section of my code that prints the output to screen. Im fairly sure from my limited ASM debugging knowledge that AL contained 05, part of the DOS version after the INT was executed.

My problem is i cant print it to the screen, ive tried INT 21 - 09 and 02 functions... This is my code...


.model small
.stack
.data
.code
main proc

MOV AH, 30h ; Get DOS Version
INT 21h ; Execute INT

MOV DL, AL ; Place return in DL for screen output

MOV AH, 09h ; Print String
INT 21h ; Execute

main endp
end main


Ive ripped all the input/select option stuff out and ended up with the above for the moment while i get this working. I know i could compare whats in AL and print a string such as "this is dos 5", but i realy want to be able to print an integer. The obvious issue i think i have is that INT 21h function 09 and 02 are for printing strings?? Ive gandered through the available functions for INT 21 and i cant seem to find anything that prints an integer.

Ive seen examples on the NET that use C++ functions to print it to the screen, but id much rather do it in raw ASM if possible??

Thanks in advance for your help.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 134
Reputation: mathematician is an unknown quantity at this point 
Solved Threads: 3
mathematician mathematician is offline Offline
Junior Poster

Re: HELP - Printing Integers

 
0
  #2
Nov 20th, 2006
Originally Posted by paulfaz View Post
Hi,

Im just starting out attempting to learn assembly, and ive come across what is probably a really simple stumbling block.. The aid of google has failed me this time and im hoping someone on here can help me.

I started writing a simple program that takes input for an option, and my first option would be to "show the dos version"... Ive ran my code through a debugger and "i think" it is all working correctly, apart from the section of my code that prints the output to screen. Im fairly sure from my limited ASM debugging knowledge that AL contained 05, part of the DOS version after the INT was executed.

My problem is i cant print it to the screen, ive tried INT 21 - 09 and 02 functions... This is my code...


.model small
.stack
.data
.code
main proc

MOV AH, 30h ; Get DOS Version
INT 21h ; Execute INT

MOV DL, AL ; Place return in DL for screen output

MOV AH, 09h ; Print String
INT 21h ; Execute

main endp
end main


Ive ripped all the input/select option stuff out and ended up with the above for the moment while i get this working. I know i could compare whats in AL and print a string such as "this is dos 5", but i realy want to be able to print an integer. The obvious issue i think i have is that INT 21h function 09 and 02 are for printing strings?? Ive gandered through the available functions for INT 21 and i cant seem to find anything that prints an integer.

Ive seen examples on the NET that use C++ functions to print it to the screen, but id much rather do it in raw ASM if possible??

Thanks in advance for your help.

Function 2 is for printing individual ascii characters, and function 9 is for printing strings. In assembly language numbers have to be turned into either a single ascii character, or string of characters before they can be printed. In assembler, you haven't got a compiler to do the leg work for you.

Sample ascii codes: 'A' = 41h, 'B' = 42h, 'C' = 43h, 'a' = 61h, 'b' = 62h
'0' = 30h, '1' = 31h, '2' = 32h, '3' = 33h

Another couple it is useful to know is: 0dh (carriage return), 0ah (line feed)

In your case, with only a single digit to output, the easiest way of proceeding is:

  1.  
  2. mov ah, 30h ;get version number
  3. int 21h
  4. mov dl,al
  5. add dl, 30h ;convert digit to ascii character
  6. mov ah, 2 ;print character
  7. int 21h
  8.  
  9. ;----------------------------- and if you want ---------------------------
  10.  
  11. mov dl, 0dh
  12. mov ah, 2
  13. int 21h ;moves cursor back to start of line
  14. mov dl, 0ah
  15. mov ah, 2
  16. int 21h ;drops cursor down one line
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC