汇编:将代码块移至单独的功能后,代码失败

时间:2019-08-03 14:44:58

标签: assembly nasm x86-16

当我将代码块分成另一个函数时,我的代码不起作用。我一直无法弄清楚问题出在哪里。

工作代码片段如下:

; Filename: bootloader.asm
... code omitted ...

call load_kernel    ; Load our kernel
call switch_to_pm       ; Note that we never return from here.

jmp $           ; Jump here - infinite loop!

%include "print_string.asm" 
%include "gdt.asm" 
%include "print_string_pm.asm" 
%include "switch_to_pm.asm"
%include "disk_load.asm"

[bits 16]
; load_kernel 
load_kernel: 
    mov si, MSG_LOAD_KERNEL ; Print a message to say we are loading the kernel 
    call print_string

    ;   This block will be moved into a function called disk_load
    mov si, DAPACK      ; address of "disk address packet"
    mov ah, 0x42        ; AL is unused
    mov dl, 0x80        ; drive number 0 (OR the drive # with 0x80)
    int 0x13
    jc disk_error       ; Jump only only if the carry flag was set

    ret

... code omitted ...

当我将用于将磁盘扇区加载到另一个功能的代码块分开时,它不起作用。更改如下。

; Filename: bootloader.asm
... code omitted ...

[bits 16]
; load_kernel 
load_kernel: 
    mov si, MSG_LOAD_KERNEL ; Print a message to say we are loading the kernel 
    call print_string
    call disk_load ; Code block moved into disk_load function
    ret
... code omitted ...

以下是带有disk_load函数的相关文件:

; filename: disk_load.asm
disk_load:
    mov si, DAPACK      ; address of "disk address packet"
    mov ah, 0x42        ; AL is unused
    mov dl, 0x80        ; drive number 0 (OR the drive # with 0x80)
    int 0x13
    jc disk_error       ; Jump only only if the carry flag was set
    ret

disk_error:
    mov si, DISK_ERROR_MSG 
    call print_string

DISK_ERROR_MSG: 
    db 'Disk Read Error',0
DAPACK:
    db  0x10
    db  0
blkcnt: dw  15      ; int 13 resets this to # of blocks actually read/written
db_add: dw  0x1000      ; memory buffer destination address (0:9dd0h)
    dw  0       ; in memory page zero
d_lba:  dd  1       ; put the lba to read in this spot
    dd  0       ; more storage bytes only for big lba's ( > 4 bytes )

0 个答案:

没有答案