Solving Compile Error when Printing a String

  • Thread starter Thread starter brudally
  • Start date Start date
  • Tags Tags
    Printing String
AI Thread 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?
 
I came across a video regarding the use of AI/ML to work through complex datasets to determine complicated protein structures. It is a promising and beneficial use of AI/ML. AlphaFold - The Most Useful Thing AI Has Ever Done https://www.ebi.ac.uk/training/online/courses/alphafold/an-introductory-guide-to-its-strengths-and-limitations/what-is-alphafold/ https://en.wikipedia.org/wiki/AlphaFold https://deepmind.google/about/ Edit/update: The AlphaFold article in Nature John Jumper...
Thread 'Urgent: Physically repair - or bypass - power button on Asus laptop'
Asus Vivobook S14 flip. The power button is wrecked. Unable to turn it on AT ALL. We can get into how and why it got wrecked later, but suffice to say a kitchen knife was involved: These buttons do want to NOT come off, not like other lappies, where they can snap in and out. And they sure don't go back on. So, in the absence of a longer-term solution that might involve a replacement, is there any way I can activate the power button, like with a paperclip or wire or something? It looks...
Back
Top