Assembly 程序接收信号SIGSEGV,分段故障。在汇编中调用printf时
我正试图在汇编中编写代码。 当我调用printf-时,它会打印必要的字符串,但在它之后返回seg fault 请帮帮我Assembly 程序接收信号SIGSEGV,分段故障。在汇编中调用printf时,assembly,x86,segmentation-fault,printf,Assembly,X86,Segmentation Fault,Printf,我正试图在汇编中编写代码。 当我调用printf-时,它会打印必要的字符串,但在它之后返回seg fault 请帮帮我 .type pstrijcpy, @function .globl pstrijcpy pstrijcpy: pushl %ebp movl %esp ,%ebp pushl %ebx xorl %ebx ,%ebx xorl %edx ,%edx #set %edx to 0
.type pstrijcpy, @function
.globl pstrijcpy
pstrijcpy:
pushl %ebp
movl %esp ,%ebp
pushl %ebx
xorl %ebx ,%ebx
xorl %edx ,%edx #set %edx to 0
xorl %ecx ,%ecx
xorl %eax ,%eax
movl 8(%ebp) ,%eax #pointer of the dst
movl 12(%ebp) ,%edx #pointer of src
movb 16(%ebp) ,%ch #move char i to %ch
movb 20(%ebp) ,%cl #%cl = j
movb %ch ,%bl
cmpb %cl ,(%eax) #if dst.size < j
jl .printError
leal (%eax, %ebx) ,%eax #move %eax to the beginning of the string after i
cmpb %cl ,(%edx) #if src.size < j
jl .printError
leal (%edx, %ebx) ,%edx #move %edx to the beginning of the string after i
xorl %ebx ,%ebx
.whileISmallerThanJ:
movb (%edx) ,%bl
movb %bl ,(%eax) #dst[i] = src[i]
addb $1 ,%ch #i++
leal 1(%edx) ,%edx
leal 1(%eax) ,%eax
cmpb %cl ,%ch
jle .whileISmallerThanJ
.finishFunctionCopy:
movl 8(%ebp) ,%eax #pointer to the first char of the string, for the return value
popl %ebx
popl %ebp
ret
.printError:
pushl $error #push the string for printf
call printf
jmp .finishFunctionCopy
.section .rodata #read only data
readDecimal: .string "%d" #for scanf
error: .string "invalid input!\n"
。键入pstrijcpy,@function
.globl pstrijcpy
pstrijcpy:
推力%ebp
移动%esp,%ebp
推送%ebx
xorl%ebx,%ebx
xorl%edx,%edx#将%edx设置为0
xorl%ecx,%ecx
xorl%eax,%eax
movl 8(%ebp),%eax#dst的指针
movl 12(%ebp),%edx#src的指针
movb 16(%ebp),%ch#将字符i移动到%ch
movb 20%(ebp),%cl#%cl=j
movb%ch,%bl
cmpb%cl,(%eax)#如果dst.size
我认为您错过了使用cdecl
呼叫约定所需的呼叫方清理。尝试在调用printf后添加添加$4,%esp