English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. Tutorials (https://eab.abime.net/forumdisplay.php?f=73)
-   -   Creating Macros (https://eab.abime.net/showthread.php?t=69666)

Lonewolf10 17 June 2013 22:26

Creating Macros
 
Hi,

I have already created some macros for use in my own ASM code, but I am wondering if it is possible to create a macro to print text that follows it, for example:

Code:

    Print "text"
I could dump all the text strings together and select them by number, but that is time consuming and these text strings are only going to be for debugging.
I tried doing the following, but it seems to just end up pointing the address registers to nothing!

Code:

    Print    MACRO
            move.l    /1,a1
            ENDM


Is it possible to do this in DevPac 3.18?

Leffmann 17 June 2013 23:13

One way of doing it (you may have to change the syntax for DevPac):
Code:

Print    macro
        lea  .text\@, a0
        ...
        bra  .done\@

.text\@  dc.b  \1
        even
.done\@
        endm


phx 18 June 2013 08:54

You can get rid of the branch instruction when you put the strings into another section (e.g. "data"). Or put them into a second code section and rely on the linker to merge it with your main code section, due to PC-relative references (or force the merge with some small-code option).

A separate section for strings also has the advantage that you don't need to align the address after each definition.

Code:

Print  macro
        section texts,code
.text\@ dc.b    \1
        dc.b    0

        code
        lea    .text\@(pc),a0
        bsr    print_function
        endm

If you want to create absolute output instead of an AmigaDOS executable you can still use sections, but define the layout in memory using a linker script. For example:
Code:

SECTIONS {
        . = 0x10000;
        .text: { *(CODE code) *(texts) }
        . = ALIGN(2);
        .data: { *(DATA data) }
        . = ALIGN(2);
        .sdata: {
                _LinkerDB = . + 0x7ffe;
                _SDA_BASE_ = . + 0x7ffe;
                *(.sdata __MERGED)
        }
        . = ALIGN(2);
        .bss: { *(BSS bss) }
}


Lonewolf10 18 June 2013 22:12

Thanks for the help guys :)


All times are GMT +2. The time now is 03:35.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.04684 seconds with 11 queries