Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Printing a string

  1. Sep 27, 2005 #1
    I'd like to print out a string but get stuck at a compile error.

    push offset string "abcdefghijklmnop qrstuvwsyz oh well you see, I am learning abc";
    call printf;

    compiler says error "at string", how i can deal with this little problem ?
  2. jcsd
  3. Sep 27, 2005 #2


    User Avatar
    Staff Emeritus

    What processor are you targetting? In x86 asm the push offset string "abcd...." doesn't make sense. You would allocated space for string and it would contain "abcd.....". Then you would simply do:

    push offset string

    What this will do is push the offset value where string is located onto the stack
  4. Oct 7, 2005 #3
    I think its not a problem with processors, althuogh i also don't know why.
  5. Oct 8, 2005 #4
    Assembly doesn't allow you to directly handle a string like that, but you have to use an alias-like variable representing the string in the program instead, and then you can move it into a register (mov eax, yourAlias) before calling the (call printf), output is what you are expecting...
  6. Oct 8, 2005 #5


    User Avatar
    Science Advisor
    Homework Helper

    Well as I recall, allocate space for the string in RAM, load the data there, then call some assembly-version of a primitive print routine passing it the address of the string. How else would you do it in assembly?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook