What does OFFSET in 16 bit assembly code mean?

后端 未结 6 1113
不思量自难忘°
不思量自难忘° 2020-12-31 02:43

I am going through some example assembly code for 16-bit real mode.

I\'ve come across the lines:

    mov    bx, cs
    mov    ds, bx
    mov    si,          


        
6条回答
  •  生来不讨喜
    2020-12-31 03:25

    From MASM Programmer's Guide 6.1 (Microsoft Macro Assembler)

    The OFFSET Operator

    An address constant is a special type of immediate operand that consists of an offset or segment value. The OFFSET operator returns the offset of a memory location, as shown here:

        mov     bx, OFFSET var  ; Load offset address
    

    For information on differences between MASM 5.1 behavior and MASM 6.1 behavior related to OFFSET, see Appendix A.

    Since data in different modules may belong to a single segment, the assembler cannot know for each module the true offsets within a segment. Thus, the offset for var, although an immediate value, is not determined until link time.

    If you read carefully, the final value is determined after you "link" your object code to create a DLL/EXE. Prior to linking, all you have is an immediate value which represents the offset from the segment's base address.

提交回复
热议问题