I am reading sectors from my extended drive in Real Mode using the interrupt 0x13
with the function of extended drives 0x42
.
I define DAP to be 16 bytes in the following structure:
DAP:
db 0x10 ; size of DAP
db 0 ; Reserved zero
dw 0x0001 ; Number of sectors to read
dd 0x00000200 ; Memory Location to load the sector (s)
dq 0 ; Start of the sectors to be read
The DAP segment is of 8-bytes length as you could notice. During seeking for my sector (looping over sectors), I increment the segment and compare it to the real size of my drive. The wrong code that I am using to increment is limited to 16-bit mode:
mov ax, [DAP+0x08]
inc ax
mov [DAP+0x08], ax
I don't want to use several general purpose registers in a complicated addressing mode to achieve my purpose, I guess you have some simple and efficient way.
To increment a 64-bit QWORD, you can use the add
and adc
instructions:
ADD WORD [DAP+ 8], 1
ADC WORD [DAP+10], 0
ADC WORD [DAP+12], 0
ADC WORD [DAP+14], 0
Or, if you aren't targeting an 8088, 8086, or 80286, you can also use a 32-bit add/adc:
ADD DWORD [DAP+ 8], 1
ADC DWORD [DAP+12], 0
Note that you can't use INC WORD [DAP+ 8]
instead of ADD WORD [DAP+ 8], 1
because the former doesn't set the carry flag.