News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

use relative addressing mode in ml64/masm

Started by vamman, December 02, 2013, 01:48:28 PM

Previous topic - Next topic

vamman

I have the following error in MS VS 2010 using MASM.

Error   1   error A2006: undefined symbol : rip

ASM code:
lea rdx, [rip]

Is there something I need to enable in VS? According to this MSDN link this should be possible? http://msdn.microsoft.com/en-us/library/windows/hardware/ff561499%28v=vs.85%29.aspx

What's the work around?

dedndave

you can try this
        call    label0
label0: pop     rdx
        add     rdx,4


the instruction pointer is not normally used as a general register
but, the CALL instruction PUSH's the address of the following instruction on the stack (return address)
you can then POP it off the stack
notice that EDX will have the address of label0
POP EDX is a one byte opcode
ADD RDX,4 is 3 bytes (i believe)

qWord

AFAIK MASM doesn't allow direct usage of RIP. However, RIP-relative addressing is the default modus for x64 and memory operators are corresponding encoded (RIP+displacement). You can see that by duplicating an instruction that access memory:
.const
    foo DWORD ?
.code
    mov eax,foo  ; 8b055f200000 <- size = 6 byte
    mov eax,foo  ; 8b0559200000 <- 59+6=5f (.const section lies above .code) 

MREAL macros - when you need floating point arithmetic while assembling!

dedndave

duh.....    :redface:

now that i look at it, you don't need to use CALL
        mov     edx,label0        ;for code labels, the "offset" operator is implied
label0: