News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Immediate operands in MASM

Started by AeroASM, March 19, 2005, 08:14:18 AM

Previous topic - Next topic

MichaelW

Hi MazeGen,

When I try to calculate the displacement directly, MASM returns:

"error A2094: operand must be relocatable"

Every method I have tried resulted in this error, some other error, or an incorrect displacement value.

    jmpabs MACRO absaddr
        LOCAL label
        db    0E9h
        ; displacement = absaddr - label
        ; or
        ; displacement = absaddr - ($+4)
        dd    absaddr - label
        dd    absaddr - ($+4)
      label:
    ENDM


The strange thing is that MASM will accept any of these:
absaddr + label
absaddr + ($+4)
label - absaddr
($+4) - absaddr
But the calculated displacement is not correct, and I can find no method of manipulating the calculated result to a correct value that will not at some point return this or another error.
eschew obfuscation

Ratch

AeroASM ,

OP code 0EAH is for intersegment jumps.  INTEL documentation gives the coding as JMP ptr16:32, which is a 6 byte immediate address.  MASM seems to want to convert this coding into a 4 byte relative address, which is shorter and executes quicker.  Since the flat model has only one code segment, seems to me that JMP rel32 covers everything.  Ratch

Bieb

In theory, I guess you could patch the executable to use a constant value there, but there's no telling where it would jump to.

tenkey

Quote from: MichaelW on March 21, 2005, 11:26:14 AM
Every method I have tried resulted in this error, some other error, or an incorrect displacement value.

    jmpabs MACRO absaddr
        LOCAL label
        db    0E9h
        ; displacement = absaddr - label
        ; or
        ; displacement = absaddr - ($+4)
        dd    absaddr - label
        dd    absaddr - ($+4)
      label:
    ENDM


I don't think the linker object files support subtracting a label value. The assembler can subtract a label from another label if they are in the same file (or included into the same file) and in the same segment.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8