Solving Compile Error when Printing a String

  • Thread starter Thread starter brudally
  • Start date Start date
  • Tags Tags
    Printing String
Click For Summary
To print a string in assembly, it is essential to allocate space for the string in memory rather than attempting to push the string directly onto the stack. The correct approach involves using an alias-like variable that represents the string, which can then be moved into a register before calling a print function like printf. The process includes allocating memory for the string, loading the string data into that memory, and passing the address of the string to the print routine. This method ensures compatibility with assembly language requirements and avoids compilation errors related to string handling.
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?
 
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...

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