Problem trying to convert Babystep2 to AT&T assembler

Programming, for all ages and all languages.
Post Reply
lve
Posts: 3
Joined: Wed Mar 12, 2014 5:19 pm

Problem trying to convert Babystep2 to AT&T assembler

Post 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?
h0bby1
Member
Member
Posts: 240
Joined: Wed Aug 21, 2013 7:08 am

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

Post 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 ?
lve
Posts: 3
Joined: Wed Mar 12, 2014 5:19 pm

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

Post 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?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
lve
Posts: 3
Joined: Wed Mar 12, 2014 5:19 pm

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

Post 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!
Post Reply