Printing a string

  • Thread starter brudally
  • Start date
  • #1
8
0

Main Question or Discussion Point

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 ?
Thanks
 

Answers and Replies

  • #2
dduardo
Staff Emeritus
1,898
3
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
 
  • #3
46
0
I think its not a problem with processors, althuogh i also don't know why.
 
  • #4
96
0
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...
 
  • #5
saltydog
Science Advisor
Homework Helper
1,582
2
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?
 

Related Threads for: Printing a string

  • Last Post
Replies
13
Views
3K
  • Last Post
Replies
3
Views
2K
  • Last Post
Replies
6
Views
2K
  • Last Post
Replies
2
Views
1K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
13
Views
5K
Top