943,945 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 14042
  • Assembly RSS
Oct 25th, 2006
0

HELP - Printing Integers

Expand 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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
paulfaz is offline Offline
2 posts
since Oct 2006
Nov 20th, 2006
0

Re: HELP - Printing Integers

Click to Expand / Collapse  Quote originally posted by paulfaz ...
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:

Assembly Syntax (Toggle Plain Text)
  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
Reputation Points: 14
Solved Threads: 4
Junior Poster
mathematician is offline Offline
149 posts
since Nov 2006

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: help nedden in MIPS Assembly
Next Thread in Assembly Forum Timeline: Assembly language comparing strings





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


Follow us on Twitter


© 2011 DaniWeb® LLC