Page 1 of 1

Problem trying to convert Babystep2 to AT&T assembler

Posted: Wed Mar 12, 2014 5:49 pm
by lve
Hi,

I am trying to convert the Babystep2 (http://wiki.osdev.org/Babystep2) tutorial to AT&T assembler format:

Code: Select all

	.code16

main:
	movw	$0x07c0,%ax
	movw	%ax,%ds

	movw	$msg,%si # XXX $msg translated to 0x0???
ch_loop:
	lodsb
	or	%al,%al
	jz	hang
	movb	$0xe,%ah
	int	$0x10
	jmp	ch_loop

hang:
	jmp	hang

msg: .asciz	"Hello, World!\r\n"
	.org	510
	.hword	0xaa55
However, when looking at the disassembled code, I see that $msg gets translated to 0x0. Changing $msg to $(msg-main) gives the correct value, but that is just ugly :) When googling around I see similar code just using the single label ($msg).

I am puzzled, can anyone explain why this happens and how to fix it properly?

Re: Problem trying to convert Babystep2 to AT&T assembler

Posted: Wed Mar 12, 2014 6:02 pm
by h0bby1
either use segment register, or set an [ORG] address ?

either you'd set ds to zero, and si to msg, without [ORG], or set [ORG] to the value you use for the segment register ?

Re: Problem trying to convert Babystep2 to AT&T assembler

Posted: Wed Mar 12, 2014 6:18 pm
by lve
Do you know what the AT&T equivalent of Intel's [ORG] is? I don't think it's .org, because that actually grows the output file (I use it in the code to zero-fill the boot sector up to the signature). I don't think Intel's [ORG] does that.

Am I right to think that [ORG] just adds an offset to all labels?

Re: Problem trying to convert Babystep2 to AT&T assembler

Posted: Thu Mar 13, 2014 12:37 am
by Combuster
However, when looking at the disassembled code, I see that $msg gets translated to 0x0.
No, it gets translated to a relocation. The problem with GAS is that you need to use a linker first.

Re: Problem trying to convert Babystep2 to AT&T assembler

Posted: Thu Mar 13, 2014 2:31 am
by lve
I figured that out this morning :) Thanks!

Previously I used

Code: Select all

objcopy -b binary boot.o boot
which apparently throws away the relocation info, but now I use

Code: Select all

ld --oformat binary -o boot boot.o
and it just works. Yay!