-1
在以下代碼中,當我取消註釋push
指令時,我在運行可執行文件時收到錯誤Segmentation fault (core dumped)
。我試圖找出錯誤原因,但找不到原因。當我執行按下指令時,我收到:分段錯誤(核心轉儲)
section .data
; Message contains app purpose
msg db 'This app calculates 2^3+5^2',0x0a
mlen equ $-msg
msg1 db 'Computation is done',0x0a
lmsg1 equ $-msg1
num1 dd 2
lnum1 equ $-num1
pow1 dd 3
lpow1 equ $-pow1
num2 dd 5
lnum2 equ $-num2
pow2 dd 2
lpow2 equ $-pow2
section .text
global _start
_start:
xor edx, edx ; clear registers
xor ecx, ecx
xor ebx, ebx
xor eax, eax
xor esi, esi
xor edi, edi
xor esp, esp
xor ebp, ebp
mov edx, mlen
mov ecx, msg
mov ebx, 1
mov eax, 4
int 0x80 ; print message
mov edx, dword [pow2]
mov ecx, dword [num2]
mov ebx, dword [pow1]
mov eax, dword [num1]
;push edx
;push ecx ; --> When I un-comment any push command,
;push ebx ; --> I receive: Segmentation fault (core dumped)
;push eax ;
jmp end
end:
mov edx, lmsg1 ; length
mov ecx, msg1 ; memory location
mov ebx, 1
mov eax, 4
int 0x80 ; print a newline i.e. 0x0a
mov ebx, 0
mov eax, 1
int 0x80
什麼'push'ed必須'流行',或者你不平衡的堆棧。這是seg故障的常見原因。無論如何,「推」指令的目的是什麼?你想做什麼?另外,順便說一句,你不需要'imp end';無論如何,執行都會落到那裏! –
@CodyGray這段代碼只是開發函數來計算一些數學的開始。 'push'命令正在準備將要開發的函數的參數 – user3405291
'''''''''''''''''''''''''''''''''您可以將堆棧指針清零,duh。如果你想使用堆棧,你會意識到這有點不好,對吧? – Jester