【发布时间】:2014-04-14 14:05:04
【问题描述】:
我收到以下汇编代码的分段错误,尽管打印由单独的函数处理,但它只是打印出一条消息,所以我很确定我没有在堆栈上为消息分配正确的空间,并且长度。
代码如下:
section .data
print_msg: DB "H", 10, 0
len: equ $-print_msg
print_msg2: DB "BYE WORLD", 10, 0
len2: equ $-print_msg2
section .text
global main
main:
push ebp
mov ebp, esp
push DWORD len
push print_msg
call _write
push DWORD len2
push print_msg2
call _write
leave
ret
_write:
push ebp
mov ebp, esp
push ebx
mov eax, 4
mov ebx, 1
mov ecx, [ebp+8]
mov edx, [ebp+12]
int 80h
pop ebx
leave
ret
【问题讨论】:
-
不会
push print_msg推送指针,而不是字符? -
@James:确实会。另一个问题是
_write里面的ebp-relative offset是错误的(旧的ebp会在[ebp+0],返回地址会在[ebp+4])。 -
@James Oh 所以指针只有 4 个字节?
-
@Michael 所以你认为我应该摆脱在 _write 中推送 ebp 并解决偏移量。