-1

I'm just trying to read data from disk, but I get an error:

[org 0x7c00]                ; Offset to the boot sector for NASM

mov [BOOT_DRIVE], dl        ; Remember boot drive
mov bp, 0x8000              ; Set up base of the stack
mov sp, bp                  ; Set up top of the stack

mov bx, 0x0000
mov es, bx
mov bx, 0x9000
mov dh, 5
mov dl, [BOOT_DRIVE]
call disk_load

end:                        ; System end
    jmp end                 ; Endless scrolling

BOOT_DRIVE: db 0

; load DH sectors to ES:BX from drive DL
disk_load:
    pusha
    mov ah, 0x02            ; BIOS read sector
    mov al, dh          ; Read DH sectors
    mov ch, 0x00            ; Cylinder 0
    mov dh, 0x00            ; Head 0
    mov cl, 0x02            ; Sector 2
    int 0x13            ; BIOS read
    jc disk_load_error  ; If error, error <<< this jump happens
    popa
    ret
disk_load_error:
    mov ax, DISK_ERROR
    call print_string
    jmp $

DISK_ERROR: db "Disk error!", 0

; ... utility print procedures omitted

times 510-($-$$) db 0       ; Fitting into 512 bytes
dw 0xaa55                   ; Magic for the BIOS

times 256 dw 0xdada         ; Test data
times 256 dw 0xface         ; Test data
Max Yankov
  • 12,551
  • 12
  • 67
  • 135
  • Is this 16 bit real mode ? – User.1 Oct 04 '14 at 11:42
  • Is [THIS QUESTION](http://stackoverflow.com/questions/19381434/cannot-read-disk-sectors-in-assembly-language) related to your problem ? I can't tell how similar they are at first glance – User.1 Oct 04 '14 at 11:43
  • I can't see an initialisation of `DS` for `mov [BOOT_DRIVE], dl`. – rkhb Oct 04 '14 at 16:19
  • You try setting up sp = 0x8000 first, then push dx to save the drive number in dl, then later pop dx, mov dh, 5. This would eliminate issues with ds for now. – rcgldr Oct 05 '14 at 00:32

1 Answers1

0

From your code I see you consider DS=0 and SS=0. Are you sure about that?
Why don't you make the same assumption for ES?

By setting up your stack at 0x8000 you obtain just 512 bytes of stackspace. This might not be enough! Most BIOSes don't do stack switching before servicing your call. Why not initialize SP with MOV SP,0x7C00 ?
This would eliminate the possibility of BIOS overwriting your bootsector.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76