PDA

View Full Version : asm gcc problem



VyegreS
December 26th, 2010, 03:12 PM
I have the code:



char scanCode, inpChar;
asm {
mov ah,0 ;
int 16h ;
mov scanCode,ah ;
mov inpChar,al ;
}

Can somebody translate this to AT&T style.
I try something like this:

asm("movb $0,%ah \n\t"
"int $0x16 \n\t"
"movb %%ah, %0": "=g"(scanCode) :"0" (scanCode)
);
but it is don't work.

I must to do something like this http://cs.haifa.ac.il/courses/com_org/2006/int16.htm on gcc

help me please!

Zugzwang
December 26th, 2010, 05:57 PM
You do know that the functions provided by the "interrupt 16h" are *not* available in Linux, right? So your code wouldn't run in Linux anyway (except in a dosbox, but then, you won't use gcc for compiling).

VyegreS
December 26th, 2010, 08:43 PM
Yes, I know about this. I write my own system (OS), this is my laboratory work at University.

I use gcc only for compiling. (gcc -ffreestanding -c -o file.o file.c)

Can you help me?

Arndt
December 26th, 2010, 09:04 PM
Yes, I know about this. I write my own system (OS), this is my laboratory work at University.

I use gcc only for compiling. (gcc -ffreestanding -c -o file.o file.c)

Can you help me?

I haven't used this myself before, but I get the code to pass the compiler if I use %% in the first line, just as in the third line.

VyegreS
December 26th, 2010, 09:15 PM
I haven't used this myself before, but I get the code to pass the compiler if I use %% in the first line, just as in the third line.




asm("movb $0,%%ah \n\t"
"int $0x16 \n\t"
"movb %%ah, %0": "=g"(scancode) :"0" (scancode)
);

ktty.c: Assembler messages:
ktty.c:80: Error: too many memory references for `mov'
ktty.c:85: Error: suffix or operands invalid for `mov'


Please write example.

Arndt
December 26th, 2010, 09:39 PM
ktty.c: Assembler messages:
ktty.c:80: Error: too many memory references for `mov'
ktty.c:85: Error: suffix or operands invalid for `mov'


Please write example.

I just did this:


int foo()
{
char scanCode;

asm("movb $0,%%ah\n\t"
"int $0x16\n\t"
"movb %%ah, %0": "=g"(scanCode) :"0" (scanCode)
);
}

VyegreS
December 26th, 2010, 09:49 PM
It's cool. Thanks you very much!

VyegreS
December 27th, 2010, 12:48 PM
If processor works in protected mode use this:


char getch(void) {
char x;
asm(
"inb $0x60, %%al\n\t"
"movb %%al, %0 \n\t": "=g"(x)
);
return x;
}