问题描述:

I'm working on some simple GNU Code just trying to print two strings using a format string and 1 printf. The thing is when I change string1 from "Equal Created Were Women All\0" to "I do not like using Assembly\0" the program breaks after printing the two strings and says a.exe is not working.

 # 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

Above is the working code

 # 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

This is the broke code. I assume that it is not breaking just because of the string but I honestly I have no idea where to go from here. I thought I might not be clearing the whole stack but that didn't seem to be it. Thanks for any help.

相关阅读:
Top