0

I am playing around with bootloader code. My code is supposed to print an 'A' on the top left corner of the display. I use NASM:

BITS 16

mov al, 0x41          ; hex code for 'A'
mov ebx, 0xB8000      ; text screen video memory
mov byte [ebx], al    ; write 'A' into video memory

; hlt machine
end:
    hlt
    jmp end

; MBR signature
times 510-($-$$) db 0
db 0x55, 0xAA

My code is working so far, as I can run it with

nasm boot.asm -o boot.bin && qemu-system-x86_64 boot.bin

When I disassemble my boot.bin file with objdump -D -b binary -mi386 boot.bin I get the following output:

Disassembly of section .data:

00000000 <.data>:
   0:   b0 41                   mov    $0x41,%al
   2:   66 bb 00 80             mov    $0x8000,%bx
   6:   0b 00                   or     (%eax),%eax
   8:   67 88 03                mov    %al,(%bp,%di)
   b:   f4                      hlt    
   c:   eb fd                   jmp    0xb
    ...
 1fe:   55                      push   %ebp
 1ff:   aa                      stos   %al,%es:(%edi)

I fully understand the output except the part or (%eax),%eax.

What is the purpose of this instruction and why has NASM generated it?

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
EsterTron
  • 11
  • 2
  • You are using a 32-bit register (ebx), objdump does not seem to handle that correctly and plows ahead assuming everything is 16-bit code. The 0x0b+0x00 bytes came from the 0xB8000 literal. – Hans Passant Sep 11 '18 at 12:39
  • According to the help, you should be using `-m i8086` or `-M i8086` to disassemble in 16 bit mode. However neither seem to work with my versions (2.22 and 2.24.51) – Jester Sep 11 '18 at 13:12
  • 2
    Thank you both. When I use `objdump -D -b binary -mi8086 boot.bin` to disassemble the binary, it works. – EsterTron Sep 11 '18 at 13:23
  • Out of curiosity what version of objdump do you have? – Jester Sep 11 '18 at 14:45
  • 1
    My version is 2.31.1. The version of my binutils is also 2.31.1. – EsterTron Sep 11 '18 at 15:25

0 Answers0