I want to load a sector into a memory address starting at (0xD000). I use index addressing to complete disk load with 0x13 BIOS interrupt. Using 16bit mode, BIOS, AT& Syntax assembly.
I am having difficulty visualising how I would use these functions to iterate over multiple bytes to continuously print out HEX numbers, to see what is stored in the disk sector. I understand I'd use a register such as 'cx' to create a counter and a loop function. Should I use 'jmp' or 'loop' calls for this?
read_sector:
movw $disk_address_packet, %si
movw $1, 2(%si)
movw $0xD000, 4(%si)
movw $1, 8(%si)
movb $0x42, %ah
movb (boot_device), %dl
int $0x13
jc read_failed
movb (0xD000), %al # Check for non-empty bytes
cmpb $0, %al
je read_failed
I found this function to read bytes and output as HEX
cons_write_hex:
movw $4, %cx
movb $0x0E, %ah
hexloop:
rol $4, %bx # rotate left 4 bits
movw %bx, %si
and $0x000F, %si
movb HexChars(%si), %al
int $0x10
loop hexloop
ret
In the disk_address_packet, if it isn't already the case, then make sure the far pointer at
4(%si)is valid. Possibly you might still need to insert the segment value:That particular code outputs hexadecimal words, so 2 bytes together!
For just bytes it would look like this:
There's more than one solution to this task, but a loop that can hexdumps an entire 512-bytes sector could be written like this:
As you can see, I have neither used the
%cxregister nor theloopinstruction1 in the above loop. In general it is best to abstain from using theloopinstruction and instead rely on conditional jumps like I showed.1 Terminology: it's not a function, nor is it a call.
jmpandloopare instructions.