title: Read a write a sector from hard drive with int 13h
body: <p>I have a simple program. It must read first sector from hard drive (not mbr), and write it to the 0 sector (mbr). But it doesnt work. I think it is connected with wrong DAP. Thanks.</p>
  
  <pre><code>    [bits   16]
      [org    0x7c00]
  
  ;clear screen
  start:
      mov     ax, 0x3
      int     0x10
  
  ;reset the hard drive
      xor     ah, ah
      mov     dl, 0x80
      int     0x13
      jnz     error
  
  ;read the second sector
      mov     si, DAP
      mov     ah, 0x42
      int     0x13
  
      mov     si, data
      call    print_string
      jmp     $
  
  DAP:
      db      0x10    ;size of DAP
      db      0x0     ;zero
      db      0x1     ;number of sectors to read
      db      0x0     ;zero
  ;point to memory
      dw      0x0     ;offset
      dw      0x0     ;segment
      dq      0x1     ;disk address
  
  DAP2:
      db      0x10
      db      0x0
      db      0x1
      db      0x0
      dw      0x0
      dw      0x0
      dd      0x0
      dd      0x0            
  
  print_string:
      mov     ax, 0xb800
      mov     es, ax
      xor     di, di
      mov     cx, 8
      rep     movsw
      ret
  data: db 'H',2,'e',2,'l',2,'l',2
  error:db 'E',2,'r',2,'r',2
      times   510 - ($ - $$) db 0
      dw      0xaa55   
  </code></pre>
  
  <p>UPD: new code</p>
  
  <pre><code>    [bits   16]
      [org    0x7c00]
  
  ;clear screen
  start:
  ;    mov     ah, 0
  ;    push    ax
  ;    pop     ds
      mov     ax, 0x3
      int     0x10
  
  ;reset the hard drive
      xor     ah, ah
      mov     dl, 0x80
      int     0x13
      jc      error
  
  ;read the second sector
      mov     si, DAP
      mov     ah, 0x42
      int     0x13
  
      mov     si, data
      call    print_string
      jmp     $
  
  DAP:
      db      0x10    ;size of DAP
      db      0x0     ;zero
      db      0x1     ;number of sectors to read
      db      0x0     ;zero
  ;point to memory
      dw      0x0     ;offset
      dw      0x8c00  ;segment
      dq      0x1     ;disk address
  
  DAP2:
      db      0x10
      db      0x0
      db      0x1
      db      0x0
      dw      0x0
      dw      0x8c00
      dq      0x2            
  
  print_string:
      mov     ax, 0xb800
      mov     es, ax
      xor     di, di
      mov     si, 0x8c00
      mov     cx, 8
      rep     movsw
      ret
  
  data: db 'H',2,'e',2,'l',2,'l',2
  error:db 'E',2,'r',2,'r',2
  endp:
      times   510 - ($ - $$) db 0
      dw      0xaa55 
  </code></pre>
  
  <p>P.S. I'm using Bochs.</p>