我正在研究一些简单的GNU代码,只是尝试使用格式字符串和1个printf打印两个字符串。问题是当我将string1从“Equal Created Were Women All \ 0”更改为“我不喜欢使用Assembly \ 0”时,程序在打印两个字符串后中断,并说a.exe无效。
# pgm that calls a user function
# set up globals
.text
.globl _main
_string: .ascii "All women were created equal\0"
_string1: .ascii "Equal Created Were Women All\0"
_format: .ascii "%s\n%s\0"
#the main() function - simply call user fn
#push parameters, call function, clear parameters, return
_main:
pushl $_string1
pushl $_string
call _printStr
addl $4, %esp
ret
#function to print a string passed to it on the stack
_printStr:
push %ebp #save old frame pointer
movl %esp, %ebp #set frame pointer
pushl 8(%ebp)
pushl 12(%ebp)
pushl $_format
call _printf
addl $, %esp
leave
ret
以上是工作代码
# pgm that calls a user function
# set up globals
.text
.globl _main
_string: .ascii "All women were created equal\0"
_string1: .ascii "I do not like using Assembly\0"
_format: .ascii "%s\n%s\0"
#the main() function - simply call user fn
#push parameters, call function, clear parameters, return
_main:
pushl $_string1
pushl $_string
call _printStr
addl $4, %esp
ret
#function to print a string passed to it on the stack
_printStr:
push %ebp #save old frame pointer
movl %esp, %ebp #set frame pointer
pushl 8(%ebp)
pushl 12(%ebp)
pushl $_format
call _printf
addl $, %esp
leave
ret
这是破解码。我认为它不是因为字符串而破坏但我老实说我不知道从哪里开始。我以为我可能不会清理整个堆栈,但似乎不是这样。谢谢你的帮助。