5

I'm slowly trying to get into osdev just to play around.

This tutorial has a piece of assembly that waits for a drive to become ready:

reset_drive:
   mov ah, 0
   int 13h
   or ah, ah
   jnz reset_drive

I get that after the interrupt, ah will be zero if the device is ready. But what does or ah,ah do? Seems a bit redundant... it appears to do nothing. (at least by my logic) What does it do?

Matthew Sainsbury
  • 1,470
  • 3
  • 18
  • 42
  • 1
    It's [an inefficient alternative to `test ah,ah`](https://stackoverflow.com/a/33724806/224132), which is especially bad for a high-8 register because writing them creates partial-register merging issues on Intel CPUs, even Skylake. – Peter Cordes Aug 04 '17 at 00:28

1 Answers1

12

It sets/unsets the ZERO flag depending on whether ah is zero.

Depending on the status of the flag, jnz reset_drive will jump: Only if ah is not zero.

In other words, it waits for the device to become ready since it stops repeating after ah becomes zero.

phant0m
  • 16,595
  • 5
  • 50
  • 82