Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
Use16 org 0x7C00 start : cli ; mov ax , cs ; mov ds , ax mov es , ax mov ss , ax mov sp , 0x7C00 ; .. , mov ax , 0xB800 mov gs , ax ; mov si , msg call k_puts hlt ; jmp $ ; k_puts : lodsb test al , al jz . end_str mov ah , 0x0E mov bl , 0x07 ; int 0x10 jmp k_puts . end_str ret msg db 'Hello world' , 0x0d , 0x0a , 0 times 510 - ( $ - $$ ) db 0 db 0x55 , 0xaa
jmp start; jump to our code db 0 BS_OEMName db 'MicLib'; any text BPB_BytsPerSec dw 0x200; byte in the sector BPB_SecPerClus db 1; sectors in a cluster BPB_RsvdSecCnt dw 1; number of reserved sectors BPB_NumFATs db 2; number of FAT tables BPB_RootEntCnt dw 0x00E0; number of entries in the root tree BPB_TotSec16 dw 0x0B40 BPB_Media db 0xF0 BPB_FATSz16 dw 9; FAT size in sectors BPB_SecPerTrk dw 0x12; sectors on track BPB_NumHeads dw 2; number of reading heads BPB_HiddSec dd 0 BPB_TotSec32 dd 0
- ;
- ; The procedure for reading the sector of the floppy by absolute number
- ;
- ; Entrance:
- ; dx - absolute sector number
- ; si - buffer address
- ;
- k_read_sector :
- ; S = N mod 18 + 1
- ; T = N / 18
- ; H = T mod 2
- ; C = T / 2
- pusha
- mov ax , dx
- mov cx , [ BPB_SecPerTrk ]
- mov bx si
- xor dx , dx ; Starting from here, we recalculate using the formulas
- div cx
- mov ch , al
- shr ch , 1
- mov cl , dl
- inc cx
- mov dh , al
- and dh , 1
- mov ax , 0x0201
- xor dl , dl
- int 0x13
- jnc @f ; If the C flag is set, an error has occurred.
- mov si , msgErrorRead
- call k_puts ; Let us know
- @@ :
- popa
- ret
- ;
- ; Procedure for sequential reading of multiple sectors
- ;
- ; Entrance:
- ; dx - starting sector
- ; cx - how many sectors to read in a row
- ; si - memory address where to read
- ;
- k_read_sectors :
- push dx
- push cx
- @@ :
- call k_read_sector
- inc dx
- add si , [ BPB_BytsPerSec ]
- dec cx
- jnz @b ; We read yet not 0
- pop cx
- pop dx
- ret
+0 11 File name in the format 'IIIIIIIIRRRR' The file name is 8 characters long, if shorter - filled with spaces. There is no separator point. 3byte extension + 0Bh 1 File Attributes: 01h - Read Only 02h - Hidden 04h - System 08h - Volume Tag 10h - Directory 20h - Archive + 0Ch 10 Reserved + 16h 2 Time to create or modify in filetime format + 18h 2 Date of creation or modification in filetime format + 1Ah 2 Number of the first entry in the chain of FAT + 1Ch 4 Size
- ;
- ; The procedure reads the FAT table into memory.
- ;
- k_read_fat :
- mov dx , 1 ; It is located right behind the boot sector.
- mov cx , [ BPB_FATSz16 ] ; 9 sectors
- mov si , FAT
- call k_read_sectors
- ret
- ;
- ; The procedure reads the root directory into memory.
- ;
- k_read_root_dir :
- mov dx , 19 ; 1 + 9 * 2
- mov cx , 15
- mov si , ROOT
- call k_read_sectors
- ret
- ;
- ; The procedure reads a file from a floppy disk into memory.
- ;
- ; Entrance:
- ; di - buffer address
- ; si - the file name is strictly in the format NNNNNNNNEEE
- ; Output:
- ; ax - 0 if the file is not found, 1 - found
- ;
- k_read_file :
- push di
- mov di , root
- mov cx , 0xE0 ; BPB_RootEntCnt
- . next_item :
- mov al , byte [ di ]
- cmp al , 0xE5 ; Remote file label
- je . space_item
- cmp al , 0 ; Blank entry
- je . space_item
- push di
- push si
- push cx
- mov cx , 11 ; 8 + 3
- repe cmpsb ; Compare the file name with the desired
- cmp cx , 0
- pop cx
- pop si
- pop di
- je . read_file ; break
- . space_item :
- add di , 32 ; record length
- loop next_item
- xor ax , ax
- ; jmp .end_of_file
- ret
- . read_file :
- pop si
- mov bp , word [ di + 0x1A ] ; Initial cell number FAT
- mov bx , word [ di + 0x1C ] ; File size
- . read_next_claster :
- pusha
- mov dx , bp
- sub dx , 3
- add dx , 0x22
- call k_read_sector
- popa
- cmp di , 0xFFF
- je . end_of_file
- mov di , bp
- mov ax , bp ; save for parity check
- mov bx , bp ; save in case there will be 0xFFF
- imul di </ f
Source: https://habr.com/ru/post/107030/
All Articles