Question

As you can see in the code below, I called int 0x13. It failed and I now want to find out why.

mov si,bx                   ; BX points to my DAP
mov ah,0x42
mov dl,[BOOTDRIVE]
int 0x13
jc .fail

           ...
.fail:
cmp ah,0xFF                           ;what is the error code?
jg .something_wrong

           ...

.something_wrong:
mov ah,0xe
mov al,'E'                   ; 'E' stands for "ERROR"
int 0x10
jmp $

But I can't! Because the jg instruction is executed! When I run this code in QEMU it prints an 'E'. But hey, AH can't contain a value higher than 0xFF! So how is that possible?!

Was it helpful?

Solution

jg will jump depending upon the setting of flags ZF, SF and OF after the execution of the cmp which sets these flags. In this context cmp ah,0xFF and jg together are comparing ah as a signed value with -1 (which is what 0xFF is when viewed as a 2's complement 8-bit value). If ah is between 0 and 0x7f (greater than -1), it will be true (takes the jump). Otherwise, false (does not take the jump).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top