1

I'm trying to make a floppy disk operating system, which right now is in its beta. I tried reserving 2 sectors for configuration, and loaded the data into 0x7100. But even though I made sure the values are 1, it still returns 0. This is the code I'm trying to use to read the variable:

MOV AL, BYTE [0x7101]
CMP AL, 1
JE insertfunctionnamehere

Please note that this process is after I jump out of bootloader code.

This is the code I used in the bootloader to put the values in 0x7100:

  MOV AX, 0x7100
  MOV ES, AX
  MOV CL, 17
  MOV BX, 0
  MOV DH, 0
  MOV CH, 0
  MOV AL, 2
  MOV DL, BYTE [0x7FFF]
  MOV AH, 02h
  INT 0x13
  JC error1
  CMP AL, 2
  JNE error3

I don't know why some values work, but others don't. I tried changing the locations of the stored memory but to no avail. Does anyone know how to help me? I'm using NASM 16-bit if that helps.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Does this answer your question https://stackoverflow.com/questions/34555140/int-0x13-ah-0x08-get-drive-parameters? – 0xh3xa Jul 23 '22 at 23:34

1 Answers1

2

The code does not read from the same memory that was used when loading the two sectors from disk!

MOV AL, BYTE [0x7101]

Most probably your DS segment register is 0, and so this instruction reads one byte from DS:0x7101 which is linear address 0x00007101.

MOV AX, 0x7100
MOV ES, AX
MOV BX, 0

This establishes in ES:BX a far pointer 0x7100:0x0000 to the linear address 0x00071000. Here you load the two sectors holding your data.

The confusion is that in the first snippet you use 0x7100 + 1 as an offset address, and in the second snippet you use 0x7100 as a segment number.


The solution depends on how you setup and use the segment registers.

If ES kept its value 0x7100, you can add a segment override prefix to the instruction and use a small offset address like in : MOV AL, [ES:0x0001].

But maybe it is more convenient to have DS point at the program's data, and then you should first setup DS and then address your variable(s) with (again) a small offset address:

mov ax, 0x7100
mov ds, ax
...
mov al, [0x0001]
Sep Roland
  • 33,889
  • 7
  • 43
  • 76