Title Find all factors (factors.asm)
; An assembly program calls external C/C++ functions.
INCLUDE Irvine32.inc
askForInteger PROTO C
showInt PROTO C, value:SDWORD, outWidth:DWORD
OUT_WIDTH = 8
.data
save DWORD ?
.code
;--------------------------------------------------------------
; Inputs an integer n and displays all factors of the integer.
;--------------------------------------------------------------
DisplayFactors PROC C
INVOKE askForInteger ; call C++ function
mov save, eax
cmp eax, 0 mov ecx, eax
L1: mov eax, save ; EAX = input
cdq ; dividend = EDX:EAX
idiv ecx ; divisor = ECX
.IF ( edx == 0 ) ; remainder == 0
push ecx ; save ECX
INVOKE showInt, ecx, OUT_WIDTH ; call C++ function
call Crlf
pop ecx ; restore ECX
.ENDIF
loop L1
L2: ret
DisplayFactors ENDP
END
|
|