Friday, October 24, 2008

Gets the sum of two single digit numbers in assembly

This is a program that calculates the sum of two numbers that are single digit using assembly language.

jmp start
mess1 db 10,13,"Enter 1st value: $"
mess2 db 10,13,"Enter 2nd value: $"
mess3 db 10,13,"Total sum value: $"
mess4 db 10,13,"Do you want ot continue (y/n): $"
sum db 0
start:
mov ax,3
int 10h

lea dx,mess1
mov ah,9
int 21h

mov ah,1
int 21h
sub al,30h

cmp al,0
jl start
cmp al,9
jg start

mov bl,al

lea dx,mess2
mov ah,9
int 21h

mov ah,1
int 21h
sub al,30h

cmp al,0
jl start
cmp al,9
jg start

add al,bl ; adds the two numbers
mov sum,al

lea dx,mess3
mov ah,9
int 21h
cmp al,9
mov al,sum
cmp al,9
jg twodigit
mov dl,al
or dl,30h
mov ah,2
int 21h
jmp continue
int 20h


continue:
xor dx,dx
lea dx,mess4
mov ah,9
int 21h

mov ah,1
int 21h

cmp al,'y'
je start
cmp al,'n'
je quit

twodigit: ; prints sum if above 9
xor ax,ax
mov al,sum
mov bl,10
div bl
mov bh,ah
mov dl,al
or dl,30h
mov ah,2
int 21h
mov dl,bh
or dl,30h
mov ah,2
int 21h
jmp continue

quit:
int 20h

No comments: