1
我試圖訪問內存我在程序集中使用了malloced,但是我只是一再地收到段錯誤。我在下面的代碼中做了什麼錯誤,我確定它很簡單,但我看不到它!在程序集中訪問malloc'd內存
編輯:我使用的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
你有一個調試器呢? – 2011-12-16 04:29:25