Search code examples
assemblyx86interruptbios

How to use int 13 with AH=03h interrupt in assembly to fill a sector with zeroes?


So far i have this:

mov ah,02h
mov cl,11001100001111011101000b ;6,692,584 in dec
mov dl,0
int 13

Solution

  • I can see the following issues with your code:

    • AH should be 3 rather than 2 (2 is for reading).
    • CL is only eight bits so is unlikely to be holding that big honkin' value.
    • You need to set AH, AL, CH, CL, DH, DL and ES:BX as per the following table:

    AH     03h
    AL     Number of sectors to write
    CH     Track number
    CL     Sector number
    DH     Head number
    DL     Drive number
    ES:BX  Buffer to write
    

    And, if you ever need information on interrupts, you should google for "Ralf Brown". This guy created and maintained the definitive interrupt list back in the days before we were insulated from such things. See, for example, the indexed HTML version.

    Your specific needs can be met from the Int 13/AH=03h section.

    A sample, though untested and written in real mode, would be something along the following lines:

          mov  ax, 0301h           ; cmd 3 (write sector), 1 sector
          mov  cx, 0001h           ; track 0, sector 1
          mov  dx, 0000h           ; head 0, drive 0
          mov  es, segment buff    ; segment and offset of buffer
          mov  bx, offset buff
          int  13h                 ; make the call
          jc   errp                ; detect error
          ret
    
    errp:                          ; process error here
          ret
    
    buff: db   0(256)              ; buffer to write