I just start to program IA-32 assemble and boot loader and I can't understand one command: mov [bootdrv], dl. dl is the low 8 bits of data register, but I dont know what is [bootdrv]. Is it a variable or something? How could a register be placed in [bootdrv]?

start:
    mov ax,0x7c0    ; BIOS puts us at 0:07C00h, so set DS accordinly
    mov ds,ax       ; Therefore, we don't have to add 07C00h to all our data

    mov [bootdrv], dl ; quickly save what drive we booted from

This is the beginning 3 line of a boot loader and [bootdrv] just appear without any definition, I couldn't understand.

Any information would be helpful and appreciated, thank you!

有帮助吗?

解决方案

[bootdrv] is a specification of an absolute memory address. The code:

mov [bootdrv], dl

copies the contents of the 8-bit DL register into a byte in memory, at the address resulting of multiplying the current value of DS by 16, then add the value bootdrv. bootdrv itself is a label, which a value that represents where in the current data segment is the memory position located.

On the other hand, the symbol bootdrv must be defined somewhere. Otherwise, the assembler will stop with a "symbol not defined" error. Maybe it's defined past the code (assemblers do two passes through the source code in order to get all symbols so they can be used even if they are defined after the code sequence that uses them). Maybe it's in a separate .INC file.

其他提示

mov [bootdrv], dl indicates a segment:offset memory access. In the previous instruction, you configured the Data Segment register with an address, so the mov [bootdrv], dl instruction writes to the segment:offset address 0x7c0:bootdrv, whatever bootdrv might be.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top