Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Дмитро on June 15, 2016, 02:26:20 pm

Title: As the assembler in kodeblok?
Post by: Дмитро on June 15, 2016, 02:26:20 pm
As the assembler in kodeblok?
I inserted assembler, but no, but no compile  end errors occurred.
How can the correct syntax, how to compile this example right?
Please show the code, the correct code is probably the best answer.

Code
#include <stdio.h>
// definition of constant string
char format[] = "%s %s\n";
char hello[] = "Hello";
char world[] = "earth";
int main( void )
{
__asm // start ASM code here
 {
mov  eax, offset world // move the address of world to eax
  push eax         // Push the address of world to the stack
  mov  eax, offset hello // eax = &amp;(hello[0])
  push eax               // push hello to the stack
  mov  eax, offset format // eax = format
  push eax                // push format to the stack
  call printf // here is the problem printf is not define
// at the time of compilation.
// It will be define in run time.
//clean up the stack so that main can exit cleanly
//use the unused register ebx to do the cleanup
  pop  ebx
pop  ebx
pop  ebx
} // end of ASM code
}


||=== Build: Debug in Asmpr (compiler: GNU GCC Compiler) ===|
C:\ETS-22\main.cpp|13|ошибка: expected «(» before «{» token|
C:\ETS-22\main.cpp|14|ошибка: нет декларации «mov» в этой области видимости|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
 :(
Title: Re: As the assembler in kodeblok?
Post by: yvesdm3000 on June 15, 2016, 03:42:35 pm
You should search for the ASM syntax in GCC.

An example:
Code
 __asm__ ("movl %eax, %ebx\n\t"
          "movl $56, %esi\n\t"
          "movl %ecx, $label(%edx,%ebx,$4)\n\t"
          "movb %ah, (%ebx)");
Title: Re: As the assembler in kodeblok?
Post by: Дмитро on June 15, 2016, 03:51:43 pm
Thank you! Yes, that's understandable.
Title: Re: As the assembler in kodeblok?
Post by: Дмитро on June 15, 2016, 06:04:33 pm

And you can still code examples are good to post here? Well all will.
You know, I do not like the syntax is ... Oh I do not like .. The feeling arises distortion present.
Title: Re: As the assembler in kodeblok?
Post by: Дмитро on June 15, 2016, 06:59:10 pm
I found a good description, it is only in Russian.
I have this language very well know, almost as a native language.
http://asmcourse.cs.msu.ru/wp-content/uploads/2013/04/gcc-inline-asm.pdf