Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- org 0
- use16
- jmp 0x7c0:start
- bpbOEM db "VolTeK01"
- bpbBytesPerSector dw 512
- bpbSectorsPerCluster db 1
- bpbReservedSectors dw 1
- bpbNumberOfFATs db 2
- bpbRootEntries dw 224
- bpbTotalSectors dw 2880
- bpbMedia db 0xf0
- bpbSectorsPerFAT dw 9
- bpbSectorsPerTrack dw 18
- bpbHeadsPerCylinder dw 2
- bpbHiddenSectors dd 0
- bpbTotalSectorsBig dd 0
- bsDriveNumber db 0
- bsUnused db 0
- bsExtBootSignature db 0x29
- bsSerialNumber dd 0xa0a1a2a3
- bsVolumeLabel db "VolTeKOSDSK"
- bsFileSystem db "FAT12 "
- ;cx, contains loop or how many sectors to load
- ;bx, contains what address to load it too
- ;ax, contains lba
- LBA db 0x0000
- Sector db 0x00
- Track db 0x00
- Head db 0x00
- ReadSectors:
- mov ax, WORD [LBA] ;;save lba, ax will be used for division and will be modified
- push dx ;;dx will be used in the disk loading operation, so save it, but pop it before ending.
- ;;we then push cx, pop dx after poping cx
- .ReadSectorLoop:
- cmp cx, 0
- je .ReadSectorEnd ;put here for loop purposes, cx will have been popped before getting
- ;here a second time first time, push wont have been done yet
- sub cx,1 ;;read one sector
- push cx ;cx will be used in disk loading operation
- ;;do calculations
- ;;calc for track LBA/ (bpbSectorsPerTrack X bpbHeadsPerCylinder) ;;\ Calc for track
- xor ax,ax
- xor cx,cx
- xor dx,dx
- mov cl, BYTE [bpbSectorsPerTrack]
- mov al, BYTE [bpbHeadsPerCylinder]
- mul cl ;ax contains data, perfect for our division. Problem is we are dividing our lba
- ;;with the data so..
- mov dl, al ;;we arent using this register yet, and we've pushed it anyway
- mov ax, WORD [LBA]
- div dl ;ax or al contains new track data.
- mov [Track], BYTE al ;data in al after a 16/8 division
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Calc for head
- xor cx,cx
- xor dx,dx
- xor ax,ax ;al and ah contain quotient and remainder after 16/8 division
- mov ax, WORD [LBA] ;;get head count. (LBA / bpbSectorsPerTrack) / bpbHeadsPerCylinder. Modulus = heads
- mov cl, BYTE [bpbSectorsPerTrack] ;;18 is bigger than 15 so its a 5 bit number 5<8 10010 16+2
- div cl
- xor dx,dx ;we dont need this remainder
- mov cl, BYTE [bpbHeadsPerCylinder]
- div cl ;ah contains remainder
- mov [Head], BYTE ah
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; calc for Sector
- xor ax,ax
- xor cx,cx
- xor dx,dx
- mov ax, WORD [LBA]
- mov cl, BYTE [bpbSectorsPerTrack]
- div cl
- inc ah ;modulus + 1 16 / 8 remainder is in ah
- mov [Sector], BYTE ah
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; read sectors
- mov ah, 0x02
- mov al, 1
- mov ch, BYTE [Track]
- mov cl, BYTE [Sector]
- mov dh, BYTE [Head]
- mov dl, 0
- int 0x13
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;get ready for next loop
- add bx, 512
- pop cx
- .ReadSectorLoopEnd
- pop dx
- ret
- ;;=================================
- ;;=================================
- ;;=================================
- print:
- lodsb
- cmp al, 0
- je done
- mov ah, 0xe
- int 10h
- jmp print
- done:
- ret
- ;;=================================
- ;;=================================
- ;;=================================
- WordBuffer: times 6 db 0
- base dw 0x000a
- ProcedureEntry:
- mov cx, 0
- mov bx, WordBuffer+5
- loopProcedure:
- cmp ax, 0
- je endProcedure
- jmp DoDivide ;;
- ;cmp ax, [base] ;;check if already 10
- ;jge DoDivide
- ;mov dx, ax ;;process as remainder
- ;Getting here, means no division was done, which means there will
- ;be no remainder, ax equaled something smaller than 10
- ;put as remainder and process it.
- ;mov ax,0 ;;end loop
- ProcessRemainder: ;;put remainder into ASCII and put into buffer
- ;;we are working backwards, remainder is small number first, or first
- ;;place value.
- inc cx
- ;procesforzero
- dec bx
- add dl, '0'
- mov byte [bx], dl
- jmp loopProcedure
- DoDivide:
- cwd
- xor dx, dx
- div WORD [base]
- jmp ProcessRemainder
- endWithError:
- mov ah, 0xe
- mov al, 'E'
- int 10h
- endProcedure:
- mov bx, WordBuffer+5
- mov byte [bx], 0 ;;null out with 0
- sub bx, cx ;;if we return from an error, or 0 letters, prints only NULL
- ret
- ;;=================================
- ;;=================================
- ;;=================================
- start:
- mov ax,0
- mov sp,ax
- mov ax,0x07c0
- mov es, ax
- mov ds, ax
- mov ss, ax
- mov ax, 19
- mov bx, 0x500
- mov cx, 1
- cli
- hlt
- call ReadSectors
- mov ah, 0
- mov al, [Track]
- call ProcedureEntry
- mov si, bx
- call print
- mov ah, 0
- int 0x16
- cli
- hlt
- times 510 - ($-$$) db 0
- sig dw 0xAA55
Add Comment
Please, Sign In to add comment