所以基本上程序打印一个数字的因子,并检查输入的数字是否是一个完整的数字。但是,所有程序都要求输入然后崩溃。我假设它在.asm文件中的某个地方有一个无限循环。可能是什么问题呢?任何和所有的建议/回复表示赞赏。 :)
C程序:
#include <stdio.h>
extern int factors(int a);
int main()
{
int a1, x;
ag: printf("Enter a number: ");
scanf("%d", &a1);
if(a1 >= 65536)
{
printf("Invalid number, Enter again\n");
goto ag;
}
x = factors(a1);
if(x == 1)
printf("%d is a perfect number\n", a1);
else
printf("%d is not a perfect number", a1);
getchar();
return 0;
}
NASM计划:
segment .text
global _factors
_factors:
push ebp ; create stack frame
mov ebp, esp ; save stack
mov eax, [ebp + 8] ; first parameter
mov ebx, 00000001 ; initialize ebx to 1. ebx is the countere
mov ecx, eax ; more eax to ecx in order to preserve the number
agn:
cmp ebx, ecx ; check if the counter is equal to the number
je done
mov eax, ecx
xor dx, dx
div bx
inc ebx
cmp dx, 0
jne agn
mov word [fact], ax
lea dx, [fact]
mov ah, 09h
int 21h
jmp agn
done:
leave
ret
section .data
fact times 5 db "$"
sum times 5 db "$"