Search code examples
assemblydisknasm

NASM and INT13h - what am I doing wrong?


Hey, I'm pretty interested in OS writing, I was for a long time, but still just could not swallow it (I mostly go with "What can't you understand on first read you should not do at all" - and it applies well for everything else I do, like PHP, HTML, AS3.0, C++... a lot more) just now I KIND of got it. The problem is - really, ASM was not that interesting until now that I need a specific bootloader (I KNOW there are others, like GRUB or such, but it is just a long story).

Obviously the most important part is to actually read something from the disk to the image sector and jump there. However, the INT 0x13 with AH 0x02, ie. read sector(s) from disk is not really working (or I just don't get it).

So, I found this info: Click

And after a little research in Bochs I found out the number of sectors, cylinders, heads, everything about the disk.

Now, to test it, I wanted to read the first sector, and print out a few characters from it - because I know on the beginning there is this very bootloader, and I would see a part of the messages used.

But, it just... does not work. I am trying to put the buffer to a different place, the message, different sector... Can anybody show me an example of such reading of a specified point?

Thanks.


Solution

  • Finally got it!

    It seems the Drive Number (DL) was wrong... Since I switched to HDD (instead of floppy) I forgot to change it to 0x80. Also, sector number is in bits 2-7 in CH, not 0-5.

    :D Thanks anyways.