check number is perfect or not in assembly language programming
[org 0x0100]
mov ax,30
mov si,2
mov di,0
;assuming 1 is not included in perfect squares as given in example
;dx:counter
start:
mov dx,1
mov bx,si
calcSqr: ;calculate square of a number and check if it is smaller than 'n'
add bx,si
add dx,1
cmp dx,si
jne calcSqr
cmp bx,ax
jle next
jmp exit
next: ;perfect square is found: move it to memory
mov word[answer+di],bx
add di,2
add si,1
jmp start
exit
mov ax,0x4c00
int 21h
answer: dw 0
mov ax,30
mov si,2
mov di,0
;assuming 1 is not included in perfect squares as given in example
;dx:counter
start:
mov dx,1
mov bx,si
calcSqr: ;calculate square of a number and check if it is smaller than 'n'
add bx,si
add dx,1
cmp dx,si
jne calcSqr
cmp bx,ax
jle next
jmp exit
next: ;perfect square is found: move it to memory
mov word[answer+di],bx
add di,2
add si,1
jmp start
exit
mov ax,0x4c00
int 21h
answer: dw 0
Comments
Post a Comment