Solving Compile Error when Printing a String

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

Discussion Overview

The discussion revolves around resolving a compile error encountered when attempting to print a string in assembly language. Participants explore the correct method for handling strings in assembly, particularly in relation to the use of the printf function.

Discussion Character

  • Technical explanation, Debate/contested

Main Points Raised

  • One participant reports a compile error when trying to print a string using the syntax "push offset string".
  • Another participant suggests that the error may stem from the incorrect usage of the push instruction in x86 assembly, indicating that the string should be allocated space first.
  • A different participant expresses uncertainty about whether the issue is related to the processor being targeted.
  • It is proposed that assembly requires using an alias-like variable for the string, which should be moved into a register before calling printf.
  • Another participant recalls that the string must be allocated in RAM and that a primitive print routine should be called with the string's address.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the exact cause of the compile error or the best approach to resolve it, with multiple competing views presented regarding string handling in assembly.

Contextual Notes

Some limitations include the lack of clarity on the specific assembly syntax being used and the assumptions about the processor architecture. The discussion does not resolve the mathematical or technical steps involved in the proposed solutions.

Who May Find This Useful

This discussion may be useful for individuals learning assembly language, particularly those encountering similar compile errors or seeking to understand string handling in assembly programming.

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
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 26 ·
Replies
26
Views
5K
  • · Replies 70 ·
3
Replies
70
Views
5K
Replies
5
Views
2K