Assembler with possibility to create pseudo mnemonics

Página 2/2
1 |

Por ro

Scribe (5057)

Imagen del ro

13-01-2023, 16:32

".... but love WBASS2"

I hear you bro, it is such a good IDE. It's lightning fast and has a dedicated editor from which you can assemble right away and test your software on the fly with that. No need to compile files, assemble them, write an exec, run that and pray..
An assembler like WBASS2 asks to write clean-code. The ASCII source data it can produce is save to load in any assembler as it doesn't have any proprietary stuff.

/enough praise for that little gem.

I was, on another note, and example, just looking at the original VortexII player routine and almost wanted to cry... I have a new task ahead.

/topicHacking

Por Ped7g

Expert (67)

Imagen del Ped7g

13-01-2023, 17:00

Accumulator wrote:

I have truid to build SJASMPLUS inc LuaBridge, but all fails,

Can you post your distro and build log? Did you follow https://github.com/z00m128/sjasmplus/blob/master/INSTALL.md#... instructions to get full repo? Maybe you didn't clone/update submodules, thus LuaBridge is empty folder in your repo?

Otherwise I have hard time to imagine what would fail, so if you can provide details, I'm very interested in it, to improve sjasmplus for others.

The MACROs in sjasmplus can help to some extend to provide what you are asking for, but they have limits which don't fit your original examples, if you would override `add` instruction with macro `add`, you would also hide original add instruction, you can by some ugly trickery actually check if macro argument was regular register pair or expression, and call from macro `@add` for regular instruction (avoiding recursive macro substitution by "@" prefix), but it's not exactly meant to be used like this, proceed probably only if you are quite familiar with sjasmplus, Z80 assembly, and know what you are doing.

Also you can't overload macros with different number of arguments in sjasmplus and you can't do variable amount of arguments, so you need to be very specific when defining new macro (although you can pass as argument string with comas if you escape it), but that is again not so easy to process in the macro language (although you can always fall back into lua scripting, and do pretty much whatever you want with that argument content and emit machine code from lua, or inject back new symbols/defines constructed from it).

EDIT: hopefully fixed the text to show what I wrote including chevrons...
EDIT2: nope, it's hopeless... removing example.

Por Daemos

Prophet (2165)

Imagen del Daemos

13-01-2023, 16:40

@ped7g: After cloning the Luabridge repro inside the sjasmplus folder everything just builds fine without warnings and errors. I have uploaded the compiled binary.

Por Ped7g

Expert (67)

Imagen del Ped7g

13-01-2023, 16:56

And to be more specific, some sjasmplus examples (also showing some tricks/quirks and how macros may be actually tricky to get right, same as in C preprocessor):

    MACRO ADD_N16 r16?, v16?
        DEFINE ADD_N16_ARG1_TEST_r16?
        IFDEF ADD_N16_ARG1_TEST_hl : push de : ld de, +v16? : add hl,de : pop de : ENDIF
        IFDEF ADD_N16_ARG1_TEST_de : push hl : ld hl, +v16? : add hl,de : ex de,hl : pop hl : ENDIF
        IFDEF ADD_N16_ARG1_TEST_bc : push hl : ld hl, +v16? : add hl,bc : ld bc,hl : pop hl : ENDIF
        UNDEFINE ADD_N16_ARG1_TEST_r16?
    ENDM

    ; show usage
    ADD_N16 hl,$1234
    ADD_N16 de,$1234 + 2 * 4
    ADD_N16 bc,($1234 * 3)
   ; ^ would create memory read `ld hl,($1234*3)` if the macro would contain naive `ld hl,v16?` only

and these assemble to (listing file by --lst option => very useful stuff to verify you get out of macros what you expected):

710   C8B9                  MACRO ADD_N16 r16?, v16?
711   C8B9 ~                    DEFINE ADD_N16_ARG1_TEST_r16?
712   C8B9 ~                    IFDEF ADD_N16_ARG1_TEST_hl
712   C8B9 ~              push de
712   C8B9 ~              ld de, +v16?
712   C8B9 ~              add hl,de
712   C8B9 ~              pop de
712   C8B9 ~              ENDIF
713   C8B9 ~                    IFDEF ADD_N16_ARG1_TEST_de
713   C8B9 ~              push hl
713   C8B9 ~              ld hl, +v16?
713   C8B9 ~              add hl,de
713   C8B9 ~              ex de,hl
713   C8B9 ~              pop hl
713   C8B9 ~              ENDIF
714   C8B9 ~                    IFDEF ADD_N16_ARG1_TEST_bc
714   C8B9 ~              push hl
714   C8B9 ~              ld hl, +v16?
714   C8B9 ~              add hl,bc
714   C8B9 ~              ld bc,hl
714   C8B9 ~              pop hl
714   C8B9 ~              ENDIF
715   C8B9 ~                    UNDEFINE ADD_N16_ARG1_TEST_r16?
716   C8B9                  ENDM
717   C8B9                  ADD_N16 hl,$1234
717   C8B9             >        DEFINE ADD_N16_ARG1_TEST_r16?
717   C8B9             >        IFDEF ADD_N16_ARG1_TEST_hl
717   C8B9 D5          >  push de
717   C8BA 11 34 12    >  ld de, +$1234
717   C8BD 19          >  add hl,de
717   C8BE D1          >  pop de
717   C8BF             >  ENDIF
717   C8BF             >        IFDEF ADD_N16_ARG1_TEST_de
717   C8BF ~           >  push hl
717   C8BF ~           >  ld hl, +v16?
717   C8BF ~           >  add hl,de
717   C8BF ~           >  ex de,hl
717   C8BF ~           >  pop hl
717   C8BF             >  ENDIF
717   C8BF             >        IFDEF ADD_N16_ARG1_TEST_bc
717   C8BF ~           >  push hl
717   C8BF ~           >  ld hl, +v16?
717   C8BF ~           >  add hl,bc
717   C8BF ~           >  ld bc,hl
717   C8BF ~           >  pop hl
717   C8BF             >  ENDIF
717   C8BF             >        UNDEFINE ADD_N16_ARG1_TEST_hl
718   C8BF                  ADD_N16 de,$1234 + 2 * 4
718   C8BF             >        DEFINE ADD_N16_ARG1_TEST_r16?
718   C8BF             >        IFDEF ADD_N16_ARG1_TEST_hl
718   C8BF ~           >  push de
718   C8BF ~           >  ld de, +v16?
718   C8BF ~           >  add hl,de
718   C8BF ~           >  pop de
718   C8BF             >  ENDIF
718   C8BF             >        IFDEF ADD_N16_ARG1_TEST_de
718   C8BF E5          >  push hl
718   C8C0 21 3C 12    >  ld hl, +$1234 + 2 * 4
718   C8C3 19          >  add hl,de
718   C8C4 EB          >  ex de,hl
718   C8C5 E1          >  pop hl
718   C8C6             >  ENDIF
718   C8C6             >        IFDEF ADD_N16_ARG1_TEST_bc
718   C8C6 ~           >  push hl
718   C8C6 ~           >  ld hl, +v16?
718   C8C6 ~           >  add hl,bc
718   C8C6 ~           >  ld bc,hl
718   C8C6 ~           >  pop hl
718   C8C6             >  ENDIF
718   C8C6             >        UNDEFINE ADD_N16_ARG1_TEST_de
719   C8C6                  ADD_N16 bc,($1234 * 3)
719   C8C6             >        DEFINE ADD_N16_ARG1_TEST_r16?
719   C8C6             >        IFDEF ADD_N16_ARG1_TEST_hl
719   C8C6 ~           >  push de
719   C8C6 ~           >  ld de, +v16?
719   C8C6 ~           >  add hl,de
719   C8C6 ~           >  pop de
719   C8C6             >  ENDIF
719   C8C6             >        IFDEF ADD_N16_ARG1_TEST_de
719   C8C6 ~           >  push hl
719   C8C6 ~           >  ld hl, +v16?
719   C8C6 ~           >  add hl,de
719   C8C6 ~           >  ex de,hl
719   C8C6 ~           >  pop hl
719   C8C6             >  ENDIF
719   C8C6             >        IFDEF ADD_N16_ARG1_TEST_bc
719   C8C6 E5          >  push hl
719   C8C7 21 9C 36    >  ld hl, +($1234 * 3)
719   C8CA 09          >  add hl,bc
719   C8CB 44 4D       >  ld bc,hl
719   C8CD E1          >  pop hl
719   C8CE             >  ENDIF
719   C8CE             >        UNDEFINE ADD_N16_ARG1_TEST_bc
Página 2/2
1 |