daily pastebin goal
34%
SHARE
TWEET

Untitled

a guest May 21st, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. org 0
  2. use16
  3.  
  4. jmp 0x7c0:start
  5.  
  6.  
  7.  
  8. bpbOEM                   db "VolTeK01"
  9. bpbBytesPerSector        dw 512
  10. bpbSectorsPerCluster     db 1
  11. bpbReservedSectors       dw 1
  12. bpbNumberOfFATs          db 2
  13. bpbRootEntries           dw 224
  14. bpbTotalSectors          dw 2880
  15. bpbMedia                 db 0xf0
  16. bpbSectorsPerFAT         dw 9
  17. bpbSectorsPerTrack       dw 18
  18. bpbHeadsPerCylinder      dw 2
  19. bpbHiddenSectors         dd 0
  20. bpbTotalSectorsBig       dd 0
  21. bsDriveNumber            db 0
  22. bsUnused                 db 0
  23. bsExtBootSignature       db 0x29
  24. bsSerialNumber           dd 0xa0a1a2a3
  25. bsVolumeLabel            db "VolTeKOSDSK"
  26. bsFileSystem             db "FAT12   "
  27.  
  28.  
  29.  
  30. ;cx, contains loop or how many sectors to load
  31. ;bx, contains what address to load it too
  32. ;ax, contains lba
  33.  
  34. LBA db 0x0000
  35. Sector db 0x00
  36. Track db 0x00
  37. Head db 0x00
  38.  
  39. ReadSectors:
  40.  
  41. mov ax, WORD [LBA] ;;save lba, ax will be used for division and will be modified
  42. push dx            ;;dx will be used in the disk loading operation, so save it, but pop it before ending.
  43.                    ;;we then push cx, pop dx after poping cx
  44. .ReadSectorLoop:
  45. cmp cx, 0
  46. je .ReadSectorEnd  ;put here for loop purposes, cx will have been popped before getting
  47.                    ;here a second time  first time, push wont have been done yet
  48. sub cx,1           ;;read one sector
  49. push cx            ;cx will be used in disk loading operation
  50.  
  51. ;;do calculations
  52.  
  53. ;;calc for track LBA/ (bpbSectorsPerTrack X bpbHeadsPerCylinder)    ;;\  Calc for track
  54. xor ax,ax
  55. xor cx,cx
  56. xor dx,dx
  57. mov cl, BYTE [bpbSectorsPerTrack]
  58. mov al, BYTE [bpbHeadsPerCylinder]
  59. mul cl                 ;ax contains data, perfect for our division. Problem is we are dividing our lba
  60.                        ;;with the data so..
  61. mov dl, al             ;;we arent using this register yet, and we've pushed it anyway
  62. mov ax, WORD [LBA]
  63.  
  64. div dl                 ;ax or al contains new track data.
  65.  
  66. mov [Track], BYTE al    ;data in al after a 16/8 division
  67.  
  68. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  Calc for head
  69. xor cx,cx
  70. xor dx,dx
  71. xor ax,ax               ;al and ah contain quotient and remainder after 16/8 division
  72. mov ax, WORD [LBA]      ;;get head count. (LBA / bpbSectorsPerTrack) / bpbHeadsPerCylinder. Modulus = heads
  73.  
  74. mov cl, BYTE [bpbSectorsPerTrack]  ;;18 is bigger than 15 so its a 5 bit number 5<8 10010 16+2
  75. div cl
  76. xor dx,dx               ;we dont need this remainder
  77. mov cl, BYTE [bpbHeadsPerCylinder]
  78. div cl                  ;ah contains remainder
  79.  
  80. mov [Head], BYTE ah
  81.  
  82. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; calc for Sector
  83. xor ax,ax
  84. xor cx,cx
  85. xor dx,dx
  86.  
  87. mov ax, WORD [LBA]
  88. mov cl, BYTE [bpbSectorsPerTrack]
  89.  
  90. div cl
  91.  
  92. inc ah          ;modulus + 1 16 / 8 remainder is in ah
  93. mov [Sector], BYTE ah
  94.  
  95. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; read sectors
  96. mov ah, 0x02
  97. mov al, 1
  98. mov ch, BYTE [Track]
  99. mov cl, BYTE [Sector]
  100. mov dh, BYTE [Head]
  101. mov dl, 0
  102. int 0x13
  103. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;get ready for next loop
  104. add bx, 512
  105. pop cx
  106. .ReadSectorLoopEnd
  107.  
  108. pop dx
  109. ret
  110.  
  111.  
  112. ;;=================================
  113. ;;=================================
  114. ;;=================================
  115.  
  116. print:
  117. lodsb
  118. cmp al, 0
  119. je done
  120. mov ah, 0xe
  121. int 10h
  122. jmp print
  123. done:
  124. ret
  125.  
  126. ;;=================================
  127. ;;=================================
  128. ;;=================================
  129. WordBuffer: times 6 db 0
  130. base dw 0x000a
  131.  
  132.  
  133. ProcedureEntry:
  134. mov cx, 0
  135. mov bx, WordBuffer+5
  136. loopProcedure:
  137.  
  138.  
  139. cmp ax, 0
  140. je endProcedure
  141.  
  142. jmp DoDivide ;;
  143.  
  144. ;cmp ax, [base] ;;check if already 10
  145. ;jge DoDivide
  146.  
  147.  
  148. ;mov dx, ax ;;process as remainder
  149. ;Getting here, means no division was done, which means there will
  150. ;be no remainder, ax equaled something smaller than 10
  151. ;put as remainder and process it.
  152. ;mov ax,0 ;;end loop
  153.  
  154. ProcessRemainder: ;;put remainder into ASCII and put into buffer
  155. ;;we are working backwards, remainder is small number first, or first
  156. ;;place value.
  157. inc cx
  158.  
  159.  
  160.  
  161. ;procesforzero
  162. dec bx
  163. add dl, '0'
  164. mov byte [bx], dl
  165. jmp loopProcedure
  166.  
  167.  
  168.  
  169. DoDivide:
  170. cwd
  171. xor dx, dx
  172.  
  173. div WORD [base]
  174. jmp ProcessRemainder
  175.  
  176. endWithError:
  177. mov ah, 0xe
  178. mov al, 'E'
  179. int 10h
  180.  
  181. endProcedure:
  182. mov bx, WordBuffer+5
  183. mov byte [bx], 0 ;;null out with 0
  184. sub bx, cx ;;if we return from an error, or 0 letters, prints only NULL
  185. ret
  186.  
  187.  
  188. ;;=================================
  189. ;;=================================
  190. ;;=================================
  191.  
  192.  
  193.  
  194.  
  195. start:
  196. mov ax,0
  197. mov sp,ax
  198. mov ax,0x07c0
  199. mov es, ax
  200. mov ds, ax
  201. mov ss, ax
  202.  
  203. mov ax, 19
  204. mov bx, 0x500
  205. mov cx, 1
  206. cli
  207. hlt
  208. call ReadSectors  
  209.  
  210.  
  211. mov ah, 0
  212. mov al, [Track]
  213. call ProcedureEntry
  214.  
  215. mov si, bx
  216. call print
  217.  
  218. mov ah, 0
  219. int 0x16
  220. cli
  221. hlt
  222.  
  223.  
  224.  
  225.  
  226.  
  227. times 510 - ($-$$) db 0
  228.  
  229. sig dw 0xAA55
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top