简体   繁体   English

即使将值设置为 1,16 位汇编程序也将 memory 值返回为 0

[英]16-bit assembly program returning memory values as 0 even after setting values to 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.我尝试保留 2 个扇区进行配置,并将数据加载到 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:但即使我确定值是 1,它仍然返回 0。这是我试图用来读取变量的代码:

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:这是我在引导加载程序中用于将值放入 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.我尝试更改存储的 memory 的位置,但无济于事。 Does anyone know how to help me?有谁知道如何帮助我? I'm using NASM 16-bit if that helps.如果有帮助,我正在使用 NASM 16 位。

The code does not read from the same memory that was used when loading the two sectors from disk该代码不会从从磁盘加载两个扇区时使用的相同 memory 读取

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 .很可能您的DS段寄存器为 0,因此该指令从DS:0x7101读取一个字节,即线性地址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 .这在ES:BX中建立了一个指向线性地址0x00071000的远指针 0x7100:0x0000 。 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.令人困惑的是,在第一个片段中,您使用 0x7100 + 1 作为偏移地址,而在第二个片段中,您使用 0x7100 作为段号。


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] .如果ES保持其值 0x7100,您可以在指令中添加一个段覆盖前缀并使用一个小的偏移地址,例如: 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:但也许让DS指向程序的数据更方便,然后你应该首先设置DS ,然后用(再次)一个小的偏移地址来寻址你的变量:

mov ax, 0x7100
mov ds, ax
...
mov al, [0x0001]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM