Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;cx, contains loop or how many sectors to load
- ;bx, contains what address to load it too
- ;ax, contains lba
- LBA dw 0x0000
- Sector db 0x00
- Track db 0x00
- Head db 0x00
- ReadSectors:
- mov [LBA], WORD ax ;;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 ah, 0 ;we dont need remainder from last divide so ax isnt a big number remainder|quotient
- mov cl, BYTE [bpbHeadsPerCylinder]
- div cl ;ah contains remainder we need this one tho
- 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
- .ReadSectorEnd:
- pop dx
- ret
Add Comment
Please, Sign In to add comment