From: lonetunes on
i need help in adding numbers in assembly language using masm. i want
to know how to add decimal numbers in assembly language and then
display it. i dont know the procedure for displaying numbers.

i know the procedure to display characters is as follows:


mov dx, offset message
mov ah, 9h ;
int 21h ;

do i use a different interrupt to display decimal number

need help urgently

From: Dirk Wolfgang Glomp on
lonetunes(a)yahoo.com schrieb:
> i need help in adding numbers in assembly language using masm.

Simply use the "add dest,source" instruction.
Example: "add eax, ebx".

> i want
> to know how to add decimal numbers in assembly language and then
> display it. i dont know the procedure for displaying numbers.
>
> i know the procedure to display characters is as follows:
>
>
> mov dx, offset message
> mov ah, 9h ;
> int 21h ;
>
> do i use a different interrupt to display decimal number

No, there is no softint to display a different output.
You must selfconvert the value in ASCII-digits.

A 32bit number are max. 10 decimal ASCIIs.
To split the values in parts, just divide the value by 1000000000,
and the following by 10.
Example:
mov ecx, 1000000000
xor edx, edx ; set edx to zero(faster than "mov edx, 0")
div ecx ; eax divide by ecx
; result in eax

ASCII-numbers begin at 30h,
so it is easy to add 30h to every splited byte.
Example: "add al, 30h".

Dirk

From: JGCASEY on

lonetunes(a)yahoo.com wrote:
> i need help in adding numbers in assembly
> language using masm. i want to know how to
> add decimal numbers in assembly language
> and then display it. i dont know the
> procedure for displaying numbers.
>
>
> i know the procedure to display characters
> is as follows:
>
>
> mov dx, offset message
> mov ah, 9h ;
> int 21h ;
>
>
> do i use a different interrupt to display
> decimal number
>
>
> need help urgently


Why is it urgent I wonder. What is your tutorial
material. Google for assembler tutorials.

You don't mention what kind of decimal numbers?
How many bits? Signed numbers? Floating point?
They aren't binary coded decimal numbers are they?

Assuming unsigned 16 bit numbers you add them
like this,

Put your values in,

CLC ;clear carry flag
MOV AX,34 ;ax = 34
MOV CX,60 ;cx = 60

ADD AX,CX ;ax = ax + cx

You must test for no carry in case the result
is bigger than 16 bits.

JNC OK


There is no interrupt to display decimal numbers.
You have to convert the number, which is the binary
format, into a string of asc characters which
you can than print.

If you keep dividing a number by 10 the remainder
will be a single digit value 0 to 9 which you convert
into its asc code by adding 48 (30h).

;***********************************************************;
;CONVERTS NUMBER IN AX TO ASC STRING POINTED TO BY DI ;
;IN: AX = number ;
;OUT: DI -> buffer (-> means points to) ;
;***********************************************************;

putnum PROC
push ax
push dx ;save regs note we are NOT saving DI
push cx ;to make it easy to concatenate two
push bx ;answers together
mov bx,10 ;bx = base 10
sub cx,cx ;clear cx = number of digits
pnl1:
sub dx,dx ;clear most significant word for DIV
div bx ;divide by 10
add dl,'0' ;remainder in dl make it an ASCII

character
push dx ;and save it on the stack
inc cx ;update the digit count
or ax,ax ;is the quotient 0?
jnz pnl1 ;now we have all the digits on the stack
pnl2:
pop ax ;get last digit first
stosb ;save it in output buffer
loop pnl2 ;cx=cx-1:If cx<>0 then goto pnl2
sub al,al ;al = 0
stosb ;make it a null terminated string
pop bx ;restore registers
pop cx
pop dx
pop ax
ret
putnum ENDP

This above example produces a null terminated string.
I am not sure but the interrupt above might require
this be changed to a $ character?

From: randyhyde@earthlink.net on

lonetunes(a)yahoo.com wrote:
> i need help in adding numbers in assembly language using masm. i want
> to know how to add decimal numbers in assembly language and then
> display it. i dont know the procedure for displaying numbers.
>
> i know the procedure to display characters is as follows:
>
>
> mov dx, offset message
> mov ah, 9h ;
> int 21h ;
>
> do i use a different interrupt to display decimal number
>
> need help urgently

You might want to take a look at the UCR Standard Library for 80x86
assembly language programmers. It contains lots of wonderful routines
for printing numbers and other things. You can find a copy here, with
lots of other MASM resources:

http://webster.cs.ucr.edu/AsmTools/MASM/MASMLibs.html
http://webster.cs.ucr.edu/AsmTools/MASM/index.html

And you might have your instructor check out this:
http://webster.cs.ucr.edu/

As it provides lots of resources for learning assembly language
programming.
Cheers,
Randy Hyde