GNU Assembler not making sense

Programming, for all ages and all languages.
Post Reply
scanish
Posts: 4
Joined: Sun Aug 29, 2010 1:51 pm

GNU Assembler not making sense

Post 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...
jrepan
Posts: 11
Joined: Sat Feb 27, 2010 8:05 am
Location: Estonia

Re: GNU Assembler not making sense

Post by jrepan »

You can use .intel_syntax directive to use Intel syntax with GNU assembler.
scanish
Posts: 4
Joined: Sun Aug 29, 2010 1:51 pm

Re: GNU Assembler not making sense

Post by scanish »

You can? But the dotted directives are the same as with AT&T? I didn't know as supports Intel, sorry.
jrepan
Posts: 11
Joined: Sat Feb 27, 2010 8:05 am
Location: Estonia

Re: GNU Assembler not making sense

Post 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.
scanish
Posts: 4
Joined: Sun Aug 29, 2010 1:51 pm

Re: GNU Assembler not making sense

Post 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.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: GNU Assembler not making sense

Post by Owen »

It would have helped if you told us specifically where the error was
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: GNU Assembler not making sense

Post 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.
Every good solution is obvious once you've found it.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: GNU Assembler not making sense

Post 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.
scanish
Posts: 4
Joined: Sun Aug 29, 2010 1:51 pm

Re: GNU Assembler not making sense

Post by scanish »

Yes, thanks, that works, because \num is a constant.

Code: Select all

8*\num+2(%ebx)
Works perfectly... thanks a lot!
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: GNU Assembler not making sense

Post by qw »

You're welcome!
Post Reply