https://github.com/akkartik/mu/blob/main/510disk.mu

     1 fn load-sectors disk: (addr disk), lba: int, n: int, out: (addr stream byte) {
     2   var curr-lba/ebx: int <- copy lba
     3   var remaining/edx: int <- copy n
     4   {
     5     compare remaining, 0
     6     break-if-<=
     7     # sectors = min(remaining, 0x100)
     8     var sectors/eax: int <- copy remaining
     9     compare sectors, 0x100
    10     {
    11       break-if-<=
    12       sectors <- copy 0x100
    13     }
    14     #
    15     read-ata-disk disk, curr-lba, sectors, out
    16     #
    17     remaining <- subtract sectors
    18     curr-lba <- add sectors
    19     loop
    20   }
    21 }
    22
    23 fn store-sectors disk: (addr disk), lba: int, n: int, in: (addr stream byte) {
    24   var curr-lba/ebx: int <- copy lba
    25   var remaining/edx: int <- copy n
    26   {
    27     compare remaining, 0
    28     break-if-<=
    29     # sectors = min(remaining, 0x100)
    30     var sectors/eax: int <- copy remaining
    31     compare sectors, 0x100
    32     {
    33       break-if-<=
    34       sectors <- copy 0x100
    35     }
    36     #
    37     write-ata-disk disk, curr-lba, sectors, in
    38     #
    39     remaining <- subtract sectors
    40     curr-lba <- add sectors
    41     loop
    42   }
    43 }