【发布时间】:2011-12-16 03:07:55
【问题描述】:
我正在尝试访问我在汇编中分配的内存,但我不断地重复出现段错误。我在下面的代码中做错了什么,我确定它很简单但我就是看不到它!
编辑:我正在使用 64 位 NASM 程序集
; Allocate room for 8 integers
mov r8, 8
mov rdi, r8
imul rdi, 8 ; Multiply by 8 (8 bytes per entry in 64bit)
xor rax, rax
call malloc
add rsp, 8
test rax, rax
jz malloc_failure
mov r8, rsp
; r8 now = base of array
; Set the first element to be 100
mov r9, 0
add r9, r8
mov qword [r9], 100
malloc_failure:
deallocate_start:
dealloc_1:
mov rdi, r8
xor rax, rax
call free
add rsp, 8
deallocate_end:
call os_return ; return to operating system
还有段错误(不是很有趣...)
matrix05% ./arr5
Segmentation fault
【问题讨论】:
-
你有调试器吗?
标签: memory-management assembly malloc x86-64 nasm