Description: This is Assembly Language 8086 programming example in which there is a sub-routine named isPerfect which takes a number as input and tells whether the number is a Perfect number or not. If the number is Perfect, the sub-routine returns 1, else returns 2.
[org 0x0100]
mov dx , [input]
sub sp , 2
push dx
call isPerfect
mov ax , 0x4c00
int 0x21
isPerfect:
mov bp , sp
mov dx , [bp+2]
mov ax , 0
mov bx , 1
mov cx , dx
check:
sub cx , bx
cmp word cx , 0
jz true
jl refresh
jg check
refresh:
mov cx , dx
inc bx
cmp bx
,dx
jl check
cmp ax , dx
jz positive
jnz negative
true:
add ax , bx
jmp refresh
positive: ;number is perfect
mov word [bp+4] , 1
ret 2
negative: ;number is not perfect
mov word [bp+4] , 2
ret 2
input:dw 28
No comments
Post a Comment