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.

1

1 Answer 1

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]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.