assembly - 在汇编 x86 中使用 INVOKE 和 PROTO
问题描述
我正在创建一个计算 GCD 的程序。代码在主过程中运行良好,当我创建一个单独的文件来尝试使用 INVOKE 时,它不再工作,说存在堆栈溢出
TITLE GCD Calculator
INCLUDE Irvine32.inc
INCLUDE gcd.inc
.data
.code
GCD PROC,
num1: DWORD,; how to use PROTO? mov eax, num1
num2: DWORD; mov ebx = num2
mov eax, num1
mov ebx, num2
push ebp
mov ebp, esp
mov eax, [ebp + 12]
mov ebx, [ebp + 8]
cmp ebx, 0
je L1
mov edx,0
div ebx
mov eax, edx
push ebx ; Overflow occurs here
push eax
call GCD
L1:
pop ebp
ret 8
GCD ENDP
END
如果需要,这是我的主要功能,我提示用户输入两个数字,然后通过调用 GCD 函数计算 GCD
TITLE Project 4
INCLUDE Irvine32.inc
INCLUDE gcd.inc
.data
input1 BYTE "Enter the First Integer:", 0
input2 BYTE "Enter the Second Integer:", 0
result BYTE "The GCD of the Two Numbers is: ", 0
.code
main PROC
mov edx, OFFSET input1
call WriteString
call Crlf
call ReadInt
push eax; pushes the first input onto stack
mov edx, OFFSET input2
call WriteString
call Crlf
call ReadInt
push eax; pushes the second input onto stack
INVOKE GCD, eax, ebx; how to use INVOKE?
mov edx, OFFSET result
call WriteString
call Crlf
call WriteDec
main ENDP
end main
解决方案
.data
array DD 5 DUP (?)
average PROTO a: PTR DWORD
.code
main PROC
INVOKE average, ADDR array
call DumpRegs
exit
main ENDP
average PROC a: PTR DWORD
;;;;WORKING
ret
average ENDP
END main
推荐阅读
- python - 在 tkinter 中清除以前的标签
- javascript - 元素在数组中被放置了两次,即使我只是在 Nextjs/React App 中添加了一次
- java - 找到结果后 Java 跳出 for 循环
- python - 当只能通过遍历发现数据结构时,如何使用 Python 枚举有向无环图结构中的所有路径?
- java - 如何显示共享相同属性的对象列表?
- blazor-webassembly - 如何在 ABP Blazor UI 中用其他组件库完全替换 Blazorize
- c - linux上的一个c程序文件变绿了,现在我无法编辑它
- javascript - TypeScript 中的 FormEvent 类型不存在属性“值”
- multithreading - 防止上下文取消在业务逻辑中间停止函数执行
- javascript - 在添加新选项时删除 css 类的内容丰富的文本