Solving Compile Error when Printing a String

In summary, the conversation discusses the issue of getting a compile error when trying to print out a string. The speaker suggests allocating space for the string and using an alias-like variable to represent it before calling a print routine in assembly. They also mention that this method may not be suitable for all processors.
  • #1
brudally
8
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
  • #2
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
I think its not a problem with processors, althuogh i also don't know why.
 
  • #4
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
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?
 

What is a compile error?

A compile error is an error that occurs during the process of compiling or converting source code into machine code. It means that the code cannot be translated into a program that the computer can understand and execute.

Why am I getting a compile error when I try to print a string?

There could be several reasons for this, including syntax errors in the code, incompatible data types, missing or incorrect function calls, or missing libraries or imports. It is important to carefully review the code and check for any mistakes or missing elements.

How can I fix a compile error when printing a string?

The first step is to carefully review the code and check for any errors or missing elements. If the code appears to be correct, try restarting the compiler or IDE and recompiling the code. If the issue persists, try searching for solutions online or consulting with a more experienced programmer.

Is there a way to prevent compile errors when printing strings?

While it is impossible to completely eliminate the possibility of compile errors, there are steps that can be taken to minimize the chances. These include using proper coding practices, testing the code frequently, and carefully reviewing all changes before compiling.

What other resources can I use to troubleshoot compile errors when printing strings?

There are many online forums and communities where programmers can ask for help with specific issues. Additionally, most compilers and IDEs have built-in debugging tools that can help identify and fix errors. It can also be helpful to consult with more experienced programmers or attend coding workshops or classes.

Similar threads

Replies
6
Views
1K
  • Programming and Computer Science
Replies
10
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
  • Art, Music, History, and Linguistics
Replies
13
Views
453
  • Programming and Computer Science
Replies
3
Views
1K
  • Computing and Technology
Replies
1
Views
2K
  • Programming and Computer Science
3
Replies
70
Views
3K
  • Programming and Computer Science
Replies
5
Views
872
  • Science and Math Textbooks
Replies
1
Views
916
  • Science and Math Textbooks
Replies
25
Views
2K
Back
Top