I want to write a bootloader that just prints "Hello World!". on the screen and I donβt know why my bytes are messed up. I am trying to write it in AT & T syntax (please do not recommend Intel syntax) and try to convert the code from this lesson to AT & T syntax.
Now here is a pretty short code for my bootloader:
start:
.code16
.text
.org 0x0
.globl _main
_main:
movw hello, %si
movb $0x0e, %ah
loophere:
lodsb
or %al, %al
jz halt
int $0x10
jmp loophere
halt:
cli
hlt
hello: .ascii "Hello world!\0"
filloop:
.fill (510-(.-_main)),1,0
end:
.word 0xaa55
Now, if I compile this with
$as -o boot.o boot.as
$ld -Ttext 0x07c00 -o boot.elf boot.o
$objcopy -O binary boot.elf boot.bin
next command
$objdump -d boot.elf
gives me this showdown
Disassembly of section .text:
0000000000007c00 <_main>:
7c00: 8b 36 mov (%rsi),%esi
7c02: 11 7c b4 0e adc %edi,0xe(%rsp,%rsi,4)
0000000000007c06 <loophere>:
7c06: ac lods %ds:(%rsi),%al
7c07: 08 c0 or %al,%al
7c09: 74 04 je 7c0f <halt>
7c0b: cd 10 int $0x10
7c0d: eb f7 jmp 7c06 <loophere>
0000000000007c0f <halt>:
7c0f: fa cli
7c10: f4 hlt
0000000000007c11 <hello>:
7c11: 48 rex.W
7c12: 65 6c gs insb (%dx),%es:(%rdi)
7c14: 6c insb (%dx),%es:(%rdi)
7c15: 6f outsl %ds:(%rsi),(%dx)
7c16: 20 77 6f and %dh,0x6f(%rdi)
7c19: 72 6c jb 7c87 <filloop+0x69>
7c1b: 64 21 00 and %eax,%fs:(%rax)
0000000000007c1e <filloop>:
...
0000000000007dfe <end>:
7dfe: 55 push %rbp
7dff: aa stos %al,%es:(%rdi)
if i hexdump it (you can also see bytes in the parsing above) my first 6 bytes
8b 36
11 7c b4 0e
be 10 7c b4 0e ( ). , ac lodsb (loadstringbyte), b4 0e 0e %ah, be 10 7c %si hello 7c10 ( ). , . , :
0000000000007c00 <_main>:
7c00: be 10 7c b4 0e mov $0xeb47c10,%esi
7c05: ac lods %ds:(%rsi),%al
"S". - , -?
64- Debian 9 qemu-system-x86_64 .