How to locate a variable correctly in AT&T assembly?

半腔热情 提交于 2019-12-01 06:05:34

I see that the main problem is in the way you are compiling your code.

The correct steps to get your code working should be:

as boot.s -c -o boot.o
ld --oformat binary --Ttext 0x7C00 -o boot.bin boot.o

Please note, as others have said, that I'm passing the --Ttext 0x7C00 parameter to ld, to force it relocating your code at that address.

As an additional suggestion, try to structure your code like this:

.text
.global     _start
.code16

_start:
jmp stage1_start

...

stage1_start:

<your bootloader here>

Note that this is compiant with how BIOS code looks at hard drives, since after 2 bytes (the length of the first jump instruction) you should place the Disk Description Table.

Additionally, you can refactor your last instructions in a more as-like syntax like this:

. = _start + 0x0200 - 2
.short 0x0AA55

Where the . variable is the location counter. Look at this page for further information on how this counter works (in the context of ld, not as).

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!