0

I am trying to read the next sector of a disk through bios functions. Here is my code

[org 0x7c00]

; Jump past bios paramater
jmp 0x0000:0x7c16
times 0x16 - ($ - $$) db 0x00

; Set ds register to 0
mov ax, 0x0000
mov ds, ax
mov [DISK], dl

; Read from disk
mov ah, 0x02   ; Function
mov al, 0x01   ; Sectors to read
mov ch, 0x00   ; Cylinder 
mov cl, 0x02   ; Sectors
mov dh, 0x00   ; Head
mov dl, [DISK]   ; Disk

mov ax, 0x0000 
mov es, ax     ; Offset
mov bx, 0x7e00

int 0x13 

; Print char
mov al, [0x7e01]
mov ah, 0x0e
int 0x10

jmp $

DISK: db 0

times 0x1fe - ($ - $$) db 0x00
db 0x55, 0xaa

times 1024 db 'a'

But it just prints out one space. Here is how I assemble and run it.

nasm -f bin test.asm -o test.bin
qemu-system-x86_64 -drive format=raw,file=test.bin

If there is a better way to do this please tell me. Also please don't just say to write this on dos instead of bare metal.

  • `mov dl, DISK` puts the address of the variable into `dl`, truncated to 8 bits. Just leave `dl` alone or put `mov dl, [DISK]` – ecm Dec 16 '21 at 11:11
  • Yeah that was just a typo when posting it on stack overflow, but it still gives the same error – ZeroSkill Gaming Dec 16 '21 at 11:15
  • 2
    `mov ax, 0x0000` is overwriting the function code and amount of sectors to read in `ah` and `al` because those are both parts of `ax` – ecm Dec 16 '21 at 11:21
  • 1
    Always copy/paste code you've actually tried so typos are impossible, so you don't risk wasting people's time with errors you didn't actually have. – Peter Cordes Dec 16 '21 at 11:49

0 Answers0