Assembly x86无代码和can输出';t调试MASM32
大家好,我的任务是编写我的第一个汇编代码,它接受用户输入的1-12之间的数字并输出阶乘。我需要写3个程序一个用于输入,一个用于计算阶乘,一个用于打印结果。我相信我写的是正确的(我没有写),但是在得到用户的输入后,程序终止了。我从未看到“打印”过程的结果。 尝试调试我的代码时,我遇到错误:Assembly x86无代码和can输出';t调试MASM32,assembly,x86,procedure,masm,masm32,Assembly,X86,Procedure,Masm,Masm32,大家好,我的任务是编写我的第一个汇编代码,它接受用户输入的1-12之间的数字并输出阶乘。我需要写3个程序一个用于输入,一个用于计算阶乘,一个用于打印结果。我相信我写的是正确的(我没有写),但是在得到用户的输入后,程序终止了。我从未看到“打印”过程的结果。 尝试调试我的代码时,我遇到错误: include c:\asmio\asm32.inc includelib c:\asmio\asm32.lib includelib c:\asmio\User32.lib ; SAS
include c:\asmio\asm32.inc
includelib c:\asmio\asm32.lib
includelib c:\asmio\User32.lib ; SASM files for I/O
includelib c:\asmio\Kernel32.lib ; SASM files for I/O
input proto ; 0 parameters
Factorial proto nvx: dword ; 1 parameter
Print proto nax: dword, nf: dword ; 2 parameters
; -------------------------------------------------------
.const ; Section to declare and initialize constants
NULL = 0
; -------------------------------------------------------
.data ; Section to declare and initialize variables
nvx dword ?
nfx dword ?
nf dword ?
ask byte "Enter a number between 1-12: ", NULL
fin byte "! is ", NULL
; -------------------------------------------------------
.code ; The actual code begins here: Main program
main proc ; Just like C++ this is the main program
invoke input
mov nvx, eax
invoke Factorial, nvx
mov nfx, eax
invoke Print, nvx, nfx
ret 0 ; need this line to return to caller
main endp ; End of the procedure main
; -------------------------------------------------------
input proc
mov edx, OFFSET ask
call WriteString
call ReadInt
ret
input endp
; -------------------------------------------------------
Factorial proc USES ECX EAX EBX nv: dword
mov ecx, nv ;start loop counter at value given by user because we need to multiply this many times to find the factorial.
mov ebx, nv ; hold value of nv as divisor
inc nv ; This is to account for 0! We increment by one and after the loop divide by nv
mov eax, nv ; stores the largest number for multiplication
L1:
dec nv ; becomes next largest number
mul nv ; multiplication
mov eax, edx ; stores product into eax for next multiplication
loop L1
inc ebx
cdq
idiv ebx ; divide final product by original number +1 for the correct factorial
ret
Factorial endp
Print proc nax: dword, na: dword
mov eax, nvx
call WriteString
mov eax, OFFSET fin
call WriteString
mov eax, na
call WriteString
ret
Print endp
end main ; End of the entire program
; -------------------------------------------------------
但我不知道如何解决这个问题。
有什么想法吗?非常感谢今天在stack上帮助我的每个人 仍然不是您的问题,但是现在
使用EAX
将指示汇编程序为您保留EAX
,因此您不能将其用作返回值;)@Jester你,我的朋友,比我更需要你的头脑…大多数调试器可以在数字地址上设置断点。或者最近的GDB有一个starti
命令,该命令在第一条用户空间指令之前运行但停止,不管地址是什么。@PeterCordes感谢您的回复!我看到了在行上设置断点的选项,但我不确定如何设置这些点以使调试器工作。我不太熟悉MASM32,但它看起来编译得很好,并且达到了入口点,因为您说它需要输入。什么时候、什么原因会引发此错误?错误本身似乎表明您需要一个main:
(GCC)或start:
(其他)标签,就在proc main
之前,但我对它是如何执行的有点困惑,同时抛出一个错误,即它无法找到执行的主要入口点。我还看到您包括Windows库,MASM32是否有使用Windows链接器的选项?如果是这样,你应该使用它。
Entry point was not found! Entry point should have label "main" (if gcc linker is used) or "start" (otherwise).