Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use16
- org 0x7c00
- mov [BOOT_DRIVE], dx ; BIOS stores our boot drive in DL, so it’s
- mov dx, [BOOT_DRIVE]
- ; best to remember this for later.
- cli
- xor ax, ax
- ;mov ax, cs
- mov ss, ax
- mov sp, 7C00h
- sti
- mov ds, ax
- mov es, ax
- ;mov dx, 0
- ;mov dl, [BOOT_DRIVE] ; Also , print the first word from the
- call print_hex
- ;mov bp, 0x7000 ; Here we set our stack safely out of the
- ;mov sp, bp ; way , at 0x8000
- ;mov bx, 0x9000 ; Load 5 sectors to 0x0000(ES):0x9000(BX)
- ;mov dh, 4 ; from the boot disk.
- ;mov dl, [BOOT_DRIVE]
- ;mov bx, test_msg
- ;call print_string
- jmp disk_load
- disk_loaded:
- mov bx, test_msg
- call print_string
- ;mov ax, 0x0101
- ;mov [0x9000], ax
- mov dx, [0x9000] ; Print out the first loaded word , which
- call print_hex ; we expect to be 0xdada , stored
- mov dx, [0x9000 + 512] ; Also , print the first word from the
- call print_hex ; 2nd loaded sector: should be 0xface
- mov dx, [0x9000 + 1024]
- call print_hex
- mov dx, [0x7e00]
- call print_hex
- mov dx, [0x7e00 + 512]
- call print_hex
- mov dx, [0x7e00 + 1024]
- call print_hex
- mov dx, [0x7e00 + 1536]
- call print_hex
- call keyboard
- jmp 0x9000
- hex_to_char:
- push ax
- push bx
- push cx
- cmp al, 0x0a
- jg af
- jz af
- jl fa
- fa:
- add al, 0x30
- jmp o
- af:
- sub al, 0x0a
- add al, 0x41
- o:
- add bx, 2
- add bx, cx
- mov [bx], al
- pop cx
- pop bx
- pop ax
- ret
- print_hex:
- push dx
- push cx
- push bx
- push ax
- mov ax, 0000111100001111b
- mov bx, 1111000011110000b
- and ax, dx
- and bx, dx
- shr bx, 4
- mov dx, bx
- mov bx, HEX_OUT
- mov cx, 3
- call hex_to_char
- mov cx, 1
- mov al, ah
- call hex_to_char
- mov cx, 0
- mov al, dh
- call hex_to_char
- mov cx, 2
- mov al, dl
- call hex_to_char
- mov bx, HEX_OUT ; print the string pointed to
- call print_string; by BX
- pop ax
- pop bx
- pop cx
- pop dx
- ret
- print_string:
- pusha
- mov ah, 0x0e
- .loop:
- mov al,[bx]
- cmp al, 0
- je return
- int 0x10
- inc bx
- jmp .loop
- return:
- popa
- ret
- keyboard:
- l:
- mov ah, 0
- int 16h
- cmp al, 13
- jne l
- ret
- disk_load:
- mov ah, 08h
- mov dl, [BOOT_DRIVE]
- int 13h
- jc disk_error
- call print_hex
- mov dx, cx
- call print_hex
- mov dx, bx
- call print_hex
- mov dx, ax
- call print_hex
- mov ah, 02h
- mov dl, [BOOT_DRIVE]
- mov dh, 0
- mov ch, 0
- mov cl, 2
- mov al, 3
- mov bx, 0x9000
- int 13h
- jc disk_error
- mov dx, ax
- call print_hex
- mov bx, msg
- call keyboard
- call print_string
- jmp disk_loaded
- disk_error :
- mov dx, ax
- call print_hex
- mov dl, [BOOT_DRIVE]
- mov ah, 01h
- int 13h
- mov dx, ax
- call print_hex
- mov bx, DISK_ERROR_MSG
- call print_string
- jmp $
- ; Variables
- msg db 'ggggg', 0
- test_msg db 'test', 0
- DISK_ERROR_MSG db "Disk read error!", 0
- ; global variables
- HEX_OUT: db '0x0000', 10, 13, 0
- ; Re-use our print_hex function
- ; Include our new disk_load function
- ; Global variables
- BOOT_DRIVE: db 0
- lba:
- ; +----------------------------------------------------------------------------------+
- ; | Смещение Тип Назначение
- ; |
- ; | 00h byte размер структуры
- ; | 01h byte зарезервировано
- ; | 02h word сколько секторов читать
- ; | 04h dword адрес буфера
- ; | 08h qword стартовый номер сектора для чтения
- ; +----------------------------------------------------------------------------------+
- db 0x10
- db 0x00
- dw 0003h ; нужен всего 1 сектор
- dw 0x0000
- dw 9000h; пишу со смещения 512 байт после 7С00h
- dq 0000000000000001h
- disk_param:
- dw 1Ah
- dw 0x0000
- dd 0x00000000
- dd 0x00000000
- dq 0x0000000000000000
- dw 0x0000
- ; Bootsector padding
- times 446-($-$$) db 0
- db 80h, 0x00, 0x02, 0x00, 0x05, 0x00, 0x05, 0x00
- dd 0x00000001, 0x00000003
- db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- ;db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- dw 0xaa55
- include 'test_second.asm'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement