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.

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:

mov ah, 30h                   ;get version number
int 21h
mov dl,al
add dl, 30h                     ;convert digit to ascii character
mov ah, 2                       ;print character
int 21h
 
;----------------------------- and if you want ---------------------------
 
mov dl, 0dh
mov ah, 2
int 21h                            ;moves cursor back to start of line
mov dl, 0ah
mov ah, 2
int 21h                            ;drops cursor down one line
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.