flat assembler
Message board for the users of flat assembler.

Index > Main > Jump table

Author
Thread Post new topic Reply to topic
woody



Joined: 18 Jun 2005
Posts: 14
woody 18 Jun 2005, 20:55
Hi all Very Happy
I was woundering if anybody could help me with this particular problem Question
Here is some pseudo code that will try to explain what I cannot achieve.

Code:
use64
org 0x0000000000000000
;;;EAX= function numvber to call
call [Table+EAX*16]
jmp $
Entry:

Table:
.Func1 dq address of F1

F1:         ;;;Some code
              ret
    


I hope that someone can understand what I'am doing.

Thanks in advance
Woody Very Happy
Post 18 Jun 2005, 20:55
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 18 Jun 2005, 21:03
Shouldn't you use RAX for 64-bit code?
Post 18 Jun 2005, 21:03
View user's profile Send private message Visit poster's website Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 18 Jun 2005, 21:40
64bit addresses are 8bytes so
Code:
call [JMPTable+RAX*8]

JMPTable dq F1, F2, F3

F1:
...ret
F2:
...ret
F3:
...ret
    


When RAX = 0, F1 will be called
When RAX = 1, F2 will be called
etc.
Hopefully that helps.
Post 18 Jun 2005, 21:40
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
woody



Joined: 18 Jun 2005
Posts: 14
woody 18 Jun 2005, 23:48
Thanks r22. Much appreciated.
Don't think you have to use the rax register to use as an index, eax seems to work just fine.
I think the natural register to uses in th x64 range is still 32 bit with the option of 64 its unless of course when it comes to addressing memory.
But anyway thanks for help.

Woody.
Post 18 Jun 2005, 23:48
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 19 Jun 2005, 03:47
Please forgive my ignorance, but how does this apply to reference variables too? I am trying to learn them as the next portion of my own project will require them I suspect. Like so:

Code:
Functions:
CallTableAddress     rq 1           ;  0.call-table address.
Function1            rq 1           ;  1.
Function2            rq 1           ;  2. 

...

call [Function1]
    


Is this correct?
Post 19 Jun 2005, 03:47
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav 19 Jun 2005, 10:19
woody, this code is the part of microsoft optimization compiler

Code:

proc _selecttable, lpParam
  mov eax,[lpParam]
  cmp eax,3
  jb .case4
  jmp dword [.jmptbl+eax*4]

.case1:
  mov eax,1
  jmp .out

.case2:
  mov eax,2
  jmp .out

.case3:
  mov eax,3
  jmp .out

.case4:
 or eax,-1

.out:
  ret

.jmptbl:
dd .case1
dd .case2
dd .case3

endp
    

_________________
[not enough memory]
Post 19 Jun 2005, 10:19
View user's profile Send private message Reply with quote
woody



Joined: 18 Jun 2005
Posts: 14
woody 19 Jun 2005, 13:09
Hi all.
The code I'am writing is for an operating system based on unix as it was years ago.. Suppose the question should have been posted in the OS section of this forum but it seemed like a much more general assembler
question (my ignorance in the use of FASM).
The use of a jump table seems like a natural choice in my case as yours is Vasilev Vjacheslav.
Which processor are you in the use of 32, 64bit . The trouble with using
64 bit registers that an extra byte is required in the make up of the instruction. I don't ever see the OS calls allowed been more than
4294967296 (hope that number is right!) so that is why I used a 32 bit register saves memory and it's just what I need.

Woody
Post 19 Jun 2005, 13:09
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.