Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use16
  2. org 0x7c00
  3. mov [BOOT_DRIVE], dx ; BIOS  stores  our  boot  drive  in DL, so it’s
  4. mov dx, [BOOT_DRIVE]
  5. ; best to  remember  this  for  later.
  6.  
  7.  
  8. cli
  9. xor     ax, ax
  10. ;mov     ax, cs
  11. mov     ss, ax
  12. mov     sp, 7C00h
  13. sti
  14. mov     ds, ax
  15. mov     es, ax
  16.  
  17. ;mov dx, 0
  18. ;mov dl, [BOOT_DRIVE] ; Also , print  the  first  word  from  the
  19. call print_hex
  20.  
  21. ;mov bp, 0x7000         ; Here we set our  stack  safely  out of the
  22. ;mov sp, bp             ; way , at 0x8000
  23. ;mov bx, 0x9000         ; Load 5 sectors  to 0x0000(ES):0x9000(BX)
  24. ;mov dh, 4               ; from  the  boot  disk.
  25. ;mov dl, [BOOT_DRIVE]
  26. ;mov bx, test_msg
  27. ;call print_string
  28. jmp disk_load
  29. disk_loaded:
  30. mov bx, test_msg
  31. call print_string
  32. ;mov ax, 0x0101
  33. ;mov [0x9000], ax
  34. mov dx, [0x9000]      ; Print  out  the  first  loaded  word , which
  35. call print_hex         ; we  expect  to be 0xdada , stored
  36.  
  37. mov dx, [0x9000 + 512] ; Also , print  the  first  word  from  the
  38. call print_hex           ; 2nd  loaded  sector: should  be 0xface
  39.  
  40. mov dx, [0x9000 + 1024]
  41. call print_hex
  42.  
  43. mov dx, [0x7e00]
  44. call print_hex
  45.  
  46. mov dx, [0x7e00 + 512]
  47. call print_hex
  48.  
  49. mov dx, [0x7e00 + 1024]
  50. call print_hex
  51.  
  52. mov dx, [0x7e00 + 1536]
  53. call print_hex
  54. call keyboard
  55. jmp 0x9000
  56.  
  57.  
  58. hex_to_char:
  59. push ax
  60. push bx
  61. push cx
  62.  
  63. cmp al, 0x0a
  64.  
  65. jg af
  66. jz af
  67. jl fa
  68.  
  69. fa:
  70.     add al, 0x30
  71.     jmp o
  72. af:
  73.     sub al, 0x0a
  74.     add al, 0x41
  75. o:
  76. add bx, 2
  77. add bx, cx
  78. mov [bx], al
  79.  
  80. pop cx
  81. pop bx
  82. pop ax
  83. ret
  84.  
  85. print_hex:
  86. push dx
  87. push cx
  88. push bx
  89. push ax
  90.  
  91. mov ax, 0000111100001111b
  92. mov bx, 1111000011110000b
  93. and ax, dx
  94. and bx, dx
  95. shr bx, 4
  96. mov dx, bx
  97.  
  98. mov bx, HEX_OUT
  99. mov cx, 3
  100. call hex_to_char
  101.  
  102. mov cx, 1
  103. mov al, ah
  104. call hex_to_char
  105.  
  106. mov cx, 0
  107. mov al, dh
  108. call hex_to_char
  109.  
  110. mov cx, 2
  111. mov al, dl
  112. call hex_to_char
  113.  
  114. mov bx, HEX_OUT    ; print  the  string  pointed  to
  115. call print_string; by BX
  116.  
  117. pop ax
  118. pop bx
  119. pop cx
  120. pop dx
  121. ret
  122.  
  123.  
  124. print_string:
  125.     pusha
  126.     mov ah, 0x0e
  127.  
  128. .loop:
  129.     mov al,[bx]
  130.     cmp al, 0
  131.     je return
  132.     int 0x10
  133.     inc bx
  134.     jmp .loop
  135.  
  136. return:
  137.     popa
  138.     ret
  139.  
  140.  
  141. keyboard:
  142. l:
  143.  
  144. mov ah, 0
  145. int 16h
  146.  
  147. cmp al, 13
  148. jne l
  149.  
  150. ret
  151.  
  152.  
  153. disk_load:
  154.  
  155.  
  156. mov ah, 08h
  157. mov dl, [BOOT_DRIVE]
  158.  
  159. int 13h
  160.  
  161. jc disk_error
  162.  
  163. call print_hex
  164. mov dx, cx
  165. call print_hex
  166. mov dx, bx
  167. call print_hex
  168. mov dx, ax
  169. call print_hex
  170.  
  171.  
  172. mov ah, 02h
  173. mov dl, [BOOT_DRIVE]
  174. mov dh, 0
  175. mov ch, 0
  176. mov cl, 2
  177. mov al, 3
  178. mov bx, 0x9000
  179.  
  180. int 13h
  181.  
  182. jc disk_error
  183.  
  184. mov dx, ax
  185. call print_hex
  186.  
  187.  
  188. mov bx, msg
  189. call keyboard
  190. call print_string
  191.  
  192.  
  193. jmp disk_loaded
  194.  
  195. disk_error :
  196. mov dx, ax
  197. call print_hex
  198. mov dl, [BOOT_DRIVE]
  199. mov ah, 01h
  200. int 13h
  201.  
  202. mov dx, ax
  203. call print_hex
  204.  
  205. mov bx, DISK_ERROR_MSG
  206. call print_string
  207. jmp $
  208. ; Variables
  209. msg db 'ggggg', 0
  210. test_msg db 'test', 0
  211. DISK_ERROR_MSG   db "Disk  read  error!", 0
  212. ; global  variables
  213. HEX_OUT: db '0x0000', 10, 13, 0
  214.  
  215. ; Re-use  our  print_hex  function
  216. ; Include  our new  disk_load  function
  217. ; Global  variables
  218. BOOT_DRIVE: db 0
  219.  
  220. lba:
  221. ; +----------------------------------------------------------------------------------+
  222. ; | Смещение  Тип                       Назначение                                          
  223. ; |                                                                                                          
  224. ; |   00h     byte                       размер структуры                                      
  225. ; |   01h     byte                       зарезервировано                                      
  226. ; |   02h     word                   сколько секторов читать                              
  227. ; |   04h     dword                         адрес буфера                                      
  228. ; |   08h     qword             стартовый номер сектора для чтения
  229. ; +----------------------------------------------------------------------------------+
  230. db 0x10
  231. db 0x00
  232. dw 0003h                       ; нужен всего 1 сектор
  233. dw 0x0000
  234. dw 9000h; пишу со смещения 512 байт после 7С00h
  235. dq 0000000000000001h
  236.  
  237. disk_param:
  238. dw 1Ah
  239. dw 0x0000
  240. dd 0x00000000
  241. dd 0x00000000
  242. dq 0x0000000000000000
  243. dw 0x0000
  244.  
  245.  
  246. ; Bootsector  padding
  247. times 446-($-$$) db 0
  248. db 80h, 0x00, 0x02, 0x00, 0x05, 0x00, 0x05, 0x00
  249. dd 0x00000001, 0x00000003
  250. db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  251. db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  252. db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  253. ;db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  254. dw 0xaa55
  255. include 'test_second.asm'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement