manuhg
manuhg

Reputation: 460

what is wrong with following inline assembly code?

What is wrong with the following code?

__asm__("mov %0, %%eax" : :"a" (ptr));
__asm__(".intel_syntax noprefix");//switch to intel syntax.
asm("lidt [eax]");

I get error in compilation like this:

/tmp/cciOoSro.s: Assembler messages: /tmp/cciOoSro.s:1737: Error: no such instruction: popl %ebp

This is to load interrupt descriptor table IDT for my Os. But seems something wrong. I am not used to at&t syntax. I am used to intel syntax.

the function is to load the pointer of my idt to the processor using lidt.

void setup_idt(uint32 ptr) //to setup the idt i.e to load the idt's pointer
{
   __asm__("mov %0, %%eax" : :"a" (ptr));
   __asm__(".intel_syntax noprefix");//switch to intel sytax.     
   __asm__("lidt [eax]");
}

Upvotes: 1

Views: 909

Answers (1)

ugoren
ugoren

Reputation: 16441

I think the .intel_syntax noprefix line applied to everything until the end of the source. So it tried to interpreted gcc's assembly code as Intel code.

You should:
1. Merge all assembly line into one __asm__ statement (__asm__("line one\n" "line two\n"). 2. The last line should do .att_syntax prefix, to return to AT&T syntax.

Or just use AT&T syntax. It isn't so hard.

Upvotes: 3

Related Questions