I’m trying to load sectors from the disk into memory with the following assembly code, but as I figured out with some int 0x10 to the terminal, the reason it’s not working is it gets stuck in an infinite loop. I thought loop automatically decremented the cx register for me. Below is the code, with the test show_message left in for you to see how I came to the conclusion that loop is not decrementing cx. What I see is msg_2 “Still in loop” over and over and over again without end.
Another great answer would be why the read never succeeds (why the carry flag is never clear) as I’m very confident the values for the registers are good at the time of the call, but other than those registers’ contents not being right, if someone can see something I did wrong in setting up for int 0x13, that would be great too.
One last note: I know about ch being the low eight bits of the cylinder, the two high bits of cl being the two high bits of the cylinder, and the low 6 bits of cl being the sector number. My stuff is at cylinder 0, sector 2, so [CYLNUM] is 0x00 and [SECTNUM] is 0x02.
;;;Load Memory;;;
load_mem:
mov cx, 3 ;Try to read the drive 3 times
read_loop:
xor ah, ah ;ah=0, reset drive
int 0x13 ;Call drive reset
mov ax, [SYSADDR]
mov es, ax ;Destination- es:bx
mov bx, 0
mov dl, [DRIVENUM]
mov dh, [HEADNUM]
mov al, [NUMKERNELSECTS]
mov ch, [CYLNUM]
mov cl, [SECTNUM]
mov ah, 0x02 ;ah=2, read drive
int 0x13 ;Call read interrupt
jnc exit ;If carry flag is clear, exit
;;test;;
mov si, msg_2
call show_message
;;test;;
loop read_loop
mov si, read_error ;Failed 3 times
call show_message
hang:
jmp hang ;hang for now
exit:
ret
You’re modifying CX in your loop:
CX register consists of CH (Higher byte) and CL (Lower byte).
To avoid that, you could try using PUSH/POP operations on CX (or ECX) before/after the INT invocation (or maybe better at the beginning/end of the loop).
Of course, I may be wrong – I haven’t been programming in assembly for 10 years.