Wie finde ich eine Variable in der AT & T-Assembly richtig?
Ich übe, einen Bootstrap mit Assembly (in AT & T-Syntax und Gnu / Gas) zu schreiben. Das kleine Programm wird zusammengestellt und verknüpft und dann in den ersten Sektor einer virtuellen Festplatte kopiert. BIOS lädt es in0000:7c00
Und hier kommt das Problem. Dascall hello
wird übersetzt voncall 0010
zucall 7c10
während des Laufens. Aber diemovw $message, %as
wird nicht umgesiedelt. Dasax
ist immer noch0026
nicht7c26
. Das Ergebnis ist, dass ich das nicht machen kannHello World
auf dem Bildschirm. Stattdessen einige zufällige Daten bei0000:0026
wird auf dem Bildschirm angezeigt.
Wie kann ich das beim Booten korrigieren? Sollte ich den asm-Quellcode mithilfe einiger Anweisungen ändern? Oder soll ich mein Link-Skript ändern?
Vielen Dank!
.text
.global _start
.code16
_start:
movw %cs, %ax
movw %ax, %ds
movw %ax, %es
call hello
jmp .
.org 0x10
hello:
movw $message, %ax
movw %ax, %bp
movw $13, %cx
movw $0x1301, %ax
movw $0x000c, %bx
movb $0, %dl
int $0x10
ret
message:
.ascii "Hello, World!"
.org 0x01fe
.byte 0x55
.byte 0xaa
Ich benutze die folgenden Assembler- und Link-Skripte
as -o boot.o boot.s
//generate object code
ld -Ttext 0x0 -e _start -s -o boot.out boot.o
//relocate .text to 0x0
//entry is _start
objcopy -O binary -j .text boot.out boot
//copy .text section to boot
vboxmanage convertfromraw boot boot.vdi --format VDI
//create vdi for virtual box