【发布时间】:2016-11-26 16:52:17
【问题描述】:
我在汇编中有一些行为有点奇怪的代码。我有一个 C extern 函数,它使用 asm 调用 .asm 文件中的另一个函数。这个 C 函数将我的函数从 .asm 文件中使用的三个地址放入堆栈。一切顺利,直到出现:
; Let's say we take from the stack first parameter from my C function.
; This parameter is a string of bytes that respect this format:
; - first 4 bytes are the sign representation of a big number
; - second 4 bytes are the length representation of a big number
; - following bytes are the actual big number
section .data
operand1 dd 0
section .text
global main
main:
push ebp
mov ebp, esp
mov eax, [ebp + 8] ; Here eax will contain the address where my big number begins.
lea eax, [eax + 8] ; Here eax will contain the address where
; my actual big number begins.
mov [operand1], eax
PRINT_STRING "[eax] is: "
PRINT_HEX 1, [eax] ; a SASM macro which prints a byte as HEX
NEWLINE
PRINT_STRING "[operand1] is: "
PRINT_HEX 1, [operand1]
NEWLINE
leave
ret
运行此代码时,我在终端得到 [eax] 的正确输出,而对于 [operand1],它会不断打印一个数字,如果我修改 C 函数的第一个参数,该数字不会改变。我在这里做错了什么?
【问题讨论】:
-
请将您问题的答案作为答案发布,并将其标记为正确。然后其他用户可以看到问题解决了。
-
使用 *asm 调用 .asm 文件中的另一个函数*:什么?您不需要使用 inline-asm 来调用在
.asm文件中定义的函数。写一个原型,正常调用就行了。