I want to do something simple in assembly language.
addition two numbers, and print the result on the screen.
I did that code:
.Model SMALL
.Stack 100h
.Code
start:
MOV ax, 10
ADD ax, 5
MOV ah, 02h
INT 21h
MOV ah, 01h
INT 21h
MOV ah, 4ch
INT 21h
end start
After compile the code without any error, tells me a strange character .
Modified:
MOV dl, 10
ADD al,5
MOV dl, al
MOV ah,02h
INT 21h
but still print a strange character I don't know what can I do to print number on the screen
Yes, you will most likely get a strange character because int 21/ah=02 requires the character to print to be in the
dl
register, and you haven't populateddl
with anything.You may want to transfer the value with something like:
However, keep in mind that, even if you do transfer the value from
al
todl
, character number 15 may not be what you expect. 15 is one of the ASCII control characters and I'm not sure what the DOS interrupts will output for them.If you want to print out the digits
15
, you will need two calls, one withdl = 31h
and the second withdl = 35h
(the two ASCII codes for the1
and5
characters).If you want to know how to take a number in a register and output the digits for that number in readable form, there's some pseudo-code in an earlier answer of mine.
From that answer, you have the pseudo-code:
Now you need to translate that into x86 assembly. Let's start with the desired value in
ax
:Now that code segment (notwithstanding any errors due to the fact it's been a while since I did assembly) should print out the hundreds digit and leave ax with only the tens and units digit.
It should be a simple matter to duplicate the functionality twice more to get the tens and units places.