Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
karekare0 wrote:But before you go and say 'it doesn't work!!!', you forgot to increment AX (LBA starts at 0, CHS starts at 0,0,1). Just add 'inc ax' to the beginning.
Also, I highly suggest doing such things as this in C and not in ASM as it's much easier to implement an algorithm such as the LBA->CHS conversion in C. Also, the compiler will automatically optimize your code (if -O0 is not set on the command line).
pcmattman wrote:Also, I highly suggest doing such things as this in C and not in ASM as it's much easier to implement an algorithm such as the LBA->CHS conversion in C. Also, the compiler will automatically optimize your code (if -O0 is not set on the command line).
It's a bootloader and when you only have 512 bytes I take it it's hard to write it in C. This isn't stage2 yet.
This is it now:
pcmattman wrote:Also, I highly suggest doing such things as this in C and not in ASM as it's much easier to implement an algorithm such as the LBA->CHS conversion in C. Also, the compiler will automatically optimize your code (if -O0 is not set on the command line).
It's a bootloader and when you only have 512 bytes I take it it's hard to write it in C. This isn't stage2 yet.
This is it now:
LBACHS:;ax = lba
inc ax
div BYTE[sectorspertrack]
push ax
mov [sector],ah
div BYTE[numheads]
mov [cylinder],al
mov [head],ah
ret
EDIT:
The first error is the useless push ax instruction
the second is that this code is very limited,enought for a floppy but not for
a hard disk.the formula is ok.
this is the code i use:
bloodhound23 wrote:why for a hardisk? Maybe because I don't use the max cylinder info?
EDIT: push ax is left over from the old code I had that I revised
Because the numbers are very small. After the first division
al=heads*cylinders but you need at least 16 bits just for the cylinder.
ej: a 4GB disk has 8912 cylindrs 15 heads and 63 sectors.
Also with modern hard disk you will have to use lba instead of chs.