0% found this document useful (0 votes)
4 views

LAB6_1

LAB6_1LAB6_1LAB6_1

Uploaded by

okeokehuhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

LAB6_1

LAB6_1LAB6_1LAB6_1

Uploaded by

okeokehuhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

.

model small
.stack 150
.data
msg1 db 10,13, 'Enter A = $'
msg2 db 10,13, 'Enter B = $'
msg3 db 10,13, 'Fibonaccy sum of A and B is: $'
msg4 db 10,13, 'The sum is greater than 99! Exit program. $'
a db ?
b db ?
y db ?
.code
main proc
mov ax, @data
mov ds, ax
;Msg input A
mov AH, 09h
lea DX, msg1
int 21h
call input
mov [a], bh

;Msg input B
mov AH, 09h
lea DX, msg2
int 21h
call input
mov [b], bh
mov cl, [a]
add cl, [b]
cmp cl, 99
ja sum_not_valid
jmp calculate_fibo
sum_not_valid:
;Msg output
mov AH, 09h
lea DX, msg4
int 21h
int 20h
calculate_fibo:
mov ch, 0
mov ax, 1 ;f[n-1]
mov bx, 0 ;f[n-2]
mov dx, 0 ;f[n]
fibo:
mov bx, ax
mov ax, dx ;f[n-1](*) = f[n]
mov [y], al
call output
add dx, bx
loop fibo
int 20h
input proc
mov bh, 0
mov ah, 1
int 21h
next:
mov dl, al
sub dl, 48
mov al, bh
mov bl, 10
mul bl
add al, dl
mov bh, al
mov ah, 1
int 21h
cmp al, 13
jne next
mov dx, 10
mov ah, 2
int 21h
ret
input endp
output proc
push cx
push ax
push bx
push dx
mov bh, [y]
mov cx, 0
next_div:
mov al, bh
mov ah, 0
mov bl, 10
div bl
mov dl, ah
mov dh, 0
push dx
inc cx
mov bh, al
cmp al, 0
jne next_div
next_out:
pop dx
add dx, 48
mov ah, 2
int 21h
loop next_out
mov dx, 32
mov ah, 2
int 21h
pop dx
pop bx
pop ax
pop cx
ret
output endp
end main

You might also like