Page 1 of 1

GNU Assembler not making sense

Posted: Sun Aug 29, 2010 2:00 pm
by scanish
For reasons unknown I have to rewrite my startup assembly code for my kernel compatible for the GNU toolchain. I used the Netwide before, with Intel syntax, and my chums told me they want to stick strictly to the GNU chain. So I thought of it as a very nice opportunity to get familiar with AT&T syntax. But now it drives me mad.
I worked through a small reference on Memory Reference in Intel and in AT&T, but the hints there just give me errors I cannot work out.
This is the code I need to translate:

Code: Select all

	mov eax, _isr%1
	mov word [idt + 8 * %1], ax
	mov word [idt + 8 * %1 + 2], OS_CODE_DESC
	mov word [idt + 8 * %1 + 4], 0x8e00
	shr eax, 16
	mov word [idt + 8 * %1 + 6], ax
And my tries look like this:

Code: Select all

	movl isr\num, %eax
	movl idt, %ebx
	movw %ax, 0(%ebx, 8, \num)
	movw $OS_CODE_DESC, 2(%ebx, 8, \num)
	movw $0x8e00, 4(%ebx, 8, \num)
	shrl $16, %eax
	movw %ax, 6(%ebx, 8, \num)
So. The problem is basically: Any position I try for the references either makes AS tell me it's a wrong syntax or a wrong scale.

Please help...

Re: GNU Assembler not making sense

Posted: Sun Aug 29, 2010 2:07 pm
by jrepan
You can use .intel_syntax directive to use Intel syntax with GNU assembler.

Re: GNU Assembler not making sense

Posted: Sun Aug 29, 2010 2:11 pm
by scanish
You can? But the dotted directives are the same as with AT&T? I didn't know as supports Intel, sorry.

Re: GNU Assembler not making sense

Posted: Sun Aug 29, 2010 2:16 pm
by jrepan
scanish wrote:But the dotted directives are the same as with AT&T?
I am quite sure they are (but I may be wrong, because I use NASM too). The simplest way to know for sure, is to just try and see if it works.

Re: GNU Assembler not making sense

Posted: Sun Aug 29, 2010 2:43 pm
by scanish
Thanks for the help. The .intel_syntax is not quite the same as with nasm, it still expects % on registers and $ on who knows what, but there was no quick documentary on it :roll:

It turned out the entire problem was that the gas does not like to have direct values in memory references. It wants them in a register, unlike nasm. But no documentary or translation site had any hint on that.

Sorry to have made that thread.

Re: GNU Assembler not making sense

Posted: Sun Aug 29, 2010 2:48 pm
by Owen
It would have helped if you told us specifically where the error was

Re: GNU Assembler not making sense

Posted: Mon Aug 30, 2010 1:15 am
by Solar
scanish wrote:Thanks for the help. The .intel_syntax is not quite the same as with nasm, it still expects % on registers and $ on who knows what, but there was no quick documentary on it :roll:
There's always ".intel_syntax no_prefix" to try.

Yes, GAS is somewhat under-documented.

Re: GNU Assembler not making sense

Posted: Mon Aug 30, 2010 1:47 am
by qw
This is incorrect:

Code: Select all

0(%ebx, 8, \num)
GAS syntax is

Code: Select all

displacement(base, index, scale)
So it should be

Code: Select all

8 * \num(%ebx)
I haven't tested this, additional errors may occur.

Re: GNU Assembler not making sense

Posted: Mon Aug 30, 2010 10:18 am
by scanish
Yes, thanks, that works, because \num is a constant.

Code: Select all

8*\num+2(%ebx)
Works perfectly... thanks a lot!

Re: GNU Assembler not making sense

Posted: Mon Aug 30, 2010 12:40 pm
by qw
You're welcome!