flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Macro translation woes - NASM <> FASM |
Author |
|
Tarkin 29 Aug 2010, 16:32
Hello all,
I've roamed around a bit, and found pieces of whta I need to do, but have so far been unable to fit them all together. Basically, I am trying to convert jonesforth to fasm syntax. After much weeping and gnashing of teeth, I translated jonesforth.S to NASM syntax. My trouble is, of course macros, which are different across gAS, NASM, and fasm. Here is an example, in gAS (original), and my translated NASM eqiuvalent: gAS: Code: .macro defcode name, namelen, flags=0, label .section .rodata .align 4 .globl name_\label name_\label : .int link // link .set link,name_\label .byte \flags+\namelen // flags + length byte .ascii "\name" // the name .align 4 // padding to next 4 byte boundary .globl \label \label : .int code_\label // codeword .text //.align 4 .globl code_\label code_\label : // assembler code follows .endm NASM: Code: %macro defcode 4 SECTION .rodata ALIGN 4 GLOBAL name_%4 name_%4: dd link ; link %define link name_%4 ; update link db %2 + %3 ; flags + length byte db %1 ; the name ALIGN 4 ; padding to next 4 byte boundary GLOBAL %4 %4: dd code_%4 ; codeword SECTION .text ALIGN 4 GLOBAL code_%4 code_%4: ; assembler code follows %endmacro TIA, Tarkin[/code] |
|||
29 Aug 2010, 16:32 |
|
bitRAKE 29 Aug 2010, 22:57
Code: defcodeArr equ link equ 0 macro defcode nm,fl,lb { match any, defcodeArr \{ defcodeArr equ defcodeArr,nm,fl,lb \} match , defcodeArr \{ defcodeArr equ nm,fl,lb \} align 4 label code_#lb } macro rodata [nm,fl,lb] { local temp,length display `nm,13,10 name_#lb dd link link equ name_#lb db fl or length temp: db nm length = $-temp align 4 ; NOTE: leading underscores for reserved word labels __#lb dd code_#lb } macro NEXT { lodsq jmp rax } ; testing... defcode "DROP",0,DROP ; drop top of stack pop rax NEXT defcode "SWAP",0,SWAP ; swap top two elements on stack pop rax pop rbx push rax push rbx NEXT defcode "DUP",0,DUP ; duplicate top of stack push qword [rsp] NEXT match def, defcodeArr { rodata def } |
|||
29 Aug 2010, 22:57 |
|
Tarkin 29 Aug 2010, 23:08
I found it !!
I've been poring through fasm-related posts in comp.lang.forth, and I found my answer here: http://groups.google.com/group/comp.lang.forth/msg/f7cf0479bcadeaaf? bitRAKE: I thought being able to update sections/segments as you went along was one of the primary goals in the docs for fasm- though I may have misuderstood the docs... But I am not trying to 'combine' sections, just update entries in the respective sections/segments as I go along, preserving my 'programming context'; i.e. I don't want (and should have) to have two monlithic sections in my source, and have to constantly scroll back and forth between them to update related code/data in the sections. Also, this is rather elf-specific... As for passing the length as a parameter, rather than processing it in the macro itself, well, it was that way when I found it... Without further ado, here is the 'defcode' macro in fasm syntax- cheking it with FASMPRE.EXE (under wine, as I develop mostly on GNU/Linux) shows that fasm is generating what I want... Code: macro defcode _name,len,flags,_label { align 4 section '.rodata' name_#_label: public name_#_label dd link link = name_#_label db flags + len db _name align 4 _label: public _label dd code_#_label section '.text' align 4 code_#_label: public code_#_label ; assebler code follows } I got really mixed up at some point, trying to use match, macros to generate the label names, all sorts of blind alleys...I will report back if the sections give me any trouble. Thanks, Tarkin |
|||
29 Aug 2010, 23:08 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.