flat assembler
Message board for the users of flat assembler.

Index > Main > Jump tables in the DATA segment

Author
Thread Post new topic Reply to topic
Bernhard Schornak



Joined: 19 Dec 2009
Posts: 5
Location: Augsburg, Germany
Bernhard Schornak 19 Dec 2009, 10:15
Is fasm able to create jump tables in the DATA segment like the GNU asssembler (as) does? Actually, these jumptables are offsets to the application's base address. Regardless of the physical address where the program code is executed, local labels always have the same offset to it.

I want to port my OS/2 libraries and applications to Win-64 (OS/2 still is 32 bit, only), hence I need a usable compiler capable to create GUI aplications from pure assembler sources. Testing minGW 'impressed' me to look for alternatives ... I dislike to search the entire include directory for urgently required information about WinAPI definitions which, unfortunately, are distributed in more than 20 headers.
Post 19 Dec 2009, 10:15
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 19 Dec 2009, 10:33
What file format are you using? PE? MZ? Binary? ELF?
Post 19 Dec 2009, 10:33
View user's profile Send private message Visit poster's website Reply with quote
Bernhard Schornak



Joined: 19 Dec 2009
Posts: 5
Location: Augsburg, Germany
Bernhard Schornak 19 Dec 2009, 11:58
While my code runs on OS/2, it's probably LX (the native compressed executable format). On the other hand, I definitely want to port my stuff to 64 bit Windoze.

Okay, I have some minor problems to attach some sample code, so I add it here:

Quote:

.include "..//..//..//include//yasm.h"
.include "hasm.h"

.data

.p2align 4,0x00
jt0:.long L03 # 1302 select
.long L05 # 1303 abort
.long L02 # 1304 help
.long L36 # 1305 -
.long L04 # 1306 external

.text

.align 2,0x90
.globl _SelectS
_SelectS:
subl $0x7C,%esp
nop
nop
movl %edx,0x64(%esp)
movl %ecx,0x68(%esp)
movl %ebx,0x6C(%esp)
movl %edi,0x70(%esp)
movl %esi,0x74(%esp)
movl %ebp,0x78(%esp)
movl 0x80(%esp),%edi # EDI = HWND
movl 0x84(%esp),%eax # EAX = msg
movzwl 0x88(%esp),%ecx # ECX = W0MP(mp1)
movl _BNR,%esi # ESI = BNR
cmpl $0x20,%eax # WM_COMMAND
je L00
cmpl $0x30,%eax # WM_CONTROL?
jne 0f
cmpl $0x1305,%ecx # listbox?
jne L36
cmpw $0x05,0x8A(%esp) # LN_ENTER?
je L03
0:cmpl $0x3B,%eax # WM_INITDLG?
jne L36
/*
snip
*/
/*
WM_COMMAND
*/
L00:subl $0x1302,%ecx
js L36
cmpl $0x04,%ecx
ja L36
jmp *jt0(, %ecx, 4) # jump table 0
/*
help
*/
L02:movl $0x06,0x00(%esp)
call _Help
jmp L37
/*
snip (more dialog procedures)
*/
/*
default dialog proc
*/
L36:movl 0x6C(%esp),%ecx
movl 0x74(%esp),%edi
movl 0x78(%esp),%esi
addl $0x80,%esp
jmp _DefDP
/*
common exit
*/
L37:movl 0x64(%esp),%edx
movl 0x68(%esp),%ecx
movl 0x6C(%esp),%ebx
movl 0x70(%esp),%edi
movl 0x74(%esp),%esi
movl 0x78(%esp),%ebp
addl $0x7C,%esp
xorl %eax,%eax
ret
/*
snip (
*/
.comm _MHSTR,4
.comm _BNR,4
[/quote]


Last edited by Bernhard Schornak on 19 Dec 2009, 12:03; edited 1 time in total
Post 19 Dec 2009, 11:58
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 19 Dec 2009, 12:02
In short, yes you can create jump tables in any segment you want. But depending upon the file format, some are easier to do than others.

A PE64 or PE32 output format will automatically create OS link/tables and things.

But I am not sure what you want to do with the jump tables. If it just for OS interaction then there will be no problem with binding it in, the output formatters can do that for you.

There are no attachments in this thread, did you attach to another thread?
Post 19 Dec 2009, 12:02
View user's profile Send private message Visit poster's website Reply with quote
Bernhard Schornak



Joined: 19 Dec 2009
Posts: 5
Location: Augsburg, Germany
Bernhard Schornak 19 Dec 2009, 12:07
I attached a file several times, but it didn't work. Hence, I added the code in the last reply.

Greetings from Augsburg

Bernhard Schornak

(How could I forget this two times???)
Post 19 Dec 2009, 12:07
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 19 Dec 2009, 12:20
'.long' is just a dword absolute value of the link time code address.

In fasm just do this:
Code:
format ...

segment ...

jt0:
  dd lable0
  dd lable1

segment ...

lable0:
  mov eax,Something
  ret

lable1:
  call Somewhere
  ret

...    
Post 19 Dec 2009, 12:20
View user's profile Send private message Visit poster's website Reply with quote
Bernhard Schornak



Joined: 19 Dec 2009
Posts: 5
Location: Augsburg, Germany
Bernhard Schornak 20 Dec 2009, 19:45
Thank you!

I will give it a try if I find some time this week. What I'm going to do is to port this stuff http://schornak.sc.ohost.de/st-open/st7/e/700.htm to Windoze. Seems to be a nightmare or two... Wink

As a short test I hacked the usual beginner's MBR sample together and compiled it with fasm. The 249 byte binary looks okay, I check it with one of my old HDs later on.

Greetings from Augsburg

Bernhard Schornak
Post 20 Dec 2009, 19:45
View user's profile Send private message Send e-mail 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.