Solving Compile Error when Printing a String

  • Thread starter Thread starter brudally
  • Start date Start date
  • Tags Tags
    Printing String
Click For Summary
SUMMARY

The discussion addresses a compile error encountered when attempting to print a string in x86 assembly language. The error arises from the incorrect usage of the 'push offset string' command, which does not directly handle string literals. Instead, participants recommend allocating space for the string in RAM, using an alias-like variable to represent the string, and then moving the string's address into a register before invoking the 'call printf' function. This method ensures proper handling of string data in assembly programming.

PREREQUISITES
  • Understanding of x86 assembly language syntax
  • Knowledge of memory allocation in assembly
  • Familiarity with the 'call' instruction and function calls in assembly
  • Basic concepts of using registers in assembly programming
NEXT STEPS
  • Research memory allocation techniques in x86 assembly
  • Learn about using registers for data manipulation in assembly
  • Explore the 'printf' function and its usage in assembly language
  • Study aliasing concepts in assembly programming
USEFUL FOR

Assembly language programmers, computer science students, and anyone troubleshooting compile errors in x86 assembly code.

brudally
Messages
8
Reaction score
0
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
 
Computer science news on Phys.org
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
 
I think its not a problem with processors, althuogh i also don't know why.
 
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...
 
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?
 

Similar threads

Replies
6
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
8
Views
1K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 26 ·
Replies
26
Views
4K
  • · Replies 70 ·
3
Replies
70
Views
5K
Replies
5
Views
2K