News:

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

Main Menu

Jump table not working for me

Started by ateneo, August 24, 2015, 02:17:53 AM

Previous topic - Next topic

ateneo

Hi, i'm new to the board. It's been 10 years since i don't use assembly. Those days x64 architecture was recently launched and now im looking for answers to x64 arch.
Anyway my question could fit in masm32 too.

Im using masm x64 and i want to make a static jump table of 256 entries, but it seems masm doesn't recognize the "labels"

I have looked for an answer googling it and found one, but it's for PROC and i want it for labels:

What i'm doing is the following:


.data
jump_table:
dq offset label0
dq offset label1
dq offset label2
dq offset label3
        ;and so on...
.code
LookJumbTable PROC LEAF
    mov rax, [case]
    mov rdx, offset jump_table
    mov rcx, [rdx + 8 * rax]
    jmp qword ptr [rcx]

    label0:
    label1:
    label2:
    label3:
    ;... and so on
LookJumbTable ENDP

In the above example [case] is what should be loaded for indexing the jump table.

The thing is that masm is not recognizing my labels:
1) Thorws me the error "ivalid operad for offset" for the static jump table
2) It doesn't recognize my lables "undefined symbol label0"

Hope you can help me.

jj2007

Use two colons:
    label0::
    label1::
    label2::

Otherwise the label is valid only inside the proc.

P.S.: Welcome to the Forum :icon14:

ateneo

Thanks for the help. I also discoverd that i have to delete "offset".
Now assembles fine.  :biggrin:

Mikl__

Hi, ateneo!.data
jump_table dq label0, label1, label2, label3
        ;and so on...
.code
LookJumbTable PROC LEAF
    mov rax, [case]
    jmp  jump_table[8 * rax]

    label0::
    label1::
    label2::
    label3::
    ;... and so on
LookJumbTable ENDP

ateneo

Thanks very much Mikl__. Anyway i should checked "Notify me of replies" cos i spent a whole day to figure out that i had made bad my jump table. The thing was it's 256 labels and missed in one label. If you read the question i'm going to post you will know why...

Gunther

Hi ateneo,

welcome to the forum.

Gunther
You have to know the facts before you can distort them.