Make macros for assembler language (178 Views)
Reply
Occasional Contributor
Sacha Hnatiuk
Posts: 5
Registered: ‎11-16-2000
Message 1 of 6 (178 Views)

Make macros for assembler language

I have a short code in asm, and i want to duplicate it a lot of time with minor change.
I found a begin of explication in m4. But i don't have example on my hp server.
I cannot use #define because i need, when the macro is expanded, to repect the asm format:
label opcode opcode_param information
and each line must on separte line (not as C).

Somebody can help me?
Please use plain text.
Honored Contributor
Rainer_1
Posts: 252
Registered: ‎10-31-2000
Message 2 of 6 (178 Views)

Re: Make macros for assembler language

save your macro to a file.
Edit with vi you main code.
At every line where you want to insert your macro code do

:r

this inserts the contents of into your vi
Of course this is a manual procedure, hope this is what you need.
Please use plain text.
Honored Contributor
Dan Hetzel
Posts: 926
Registered: ‎07-25-2000
Message 3 of 6 (178 Views)

Re: Make macros for assembler language

Hi,

Instead of typing
:r file
to insert the file at cursor position from within vi
you could as well use the include statement, like in
#include "you_macro_file"

The disadvantage of these 2 solutions is that the same file will be used.
To allow for minor changes, you should probably modify your initial asm file with some conditional steps like
#ifdef
#else
#endif

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Please use plain text.
Valued Contributor
Andy Bennett
Posts: 22
Registered: ‎10-24-1999
Message 4 of 6 (178 Views)

Re: Make macros for assembler language

It would be worth your looking at the "Program Structure" section of the "HP Assembler Reference Manual" (available at http://docs.hp.com -> development tools and distributed computing -> Assembler) since this indicates that you can combine several assembly language instructions on the same line by separating them with "!" and using the ".LABEL" directive for the labels.
Please use plain text.
Occasional Contributor
Sacha Hnatiuk
Posts: 5
Registered: ‎11-16-2000
Message 5 of 6 (178 Views)

Re: Make macros for assembler language

To make macro for assembly code, you must:
-put a "!" between each instructions
-put a "\" to change line in the declaration like for C
-Use .LABEL directive to make a LABEL inside the macro and don't add any instruction after: use ! between the label and the instruction.
-To create local label use macro's arguments like the exemple at the end; the #arg will keep the "#" inside the label name!!!!
-Don't forget the "; macro" at the end of the description.

Exemple
#define Toto(var1,var2) .EXPORT label#var1#var2,CODE ! .LABEL label#var1#var2 ! ldi var1,r1 ! ldi var2,r2 ; macro
In source write this:
Toto(13,14)
will create this:
.EXPORT label#13#14,CODE
label#13#14
ldi 13,r1
ldi 14,r2

in c code, add this to know address (and jum perhaps...): extern "C" void label#13#14();
Please use plain text.
Occasional Contributor
Sacha Hnatiuk
Posts: 5
Registered: ‎11-16-2000
Message 6 of 6 (178 Views)

Re: Make macros for assembler language

I said an error about extern directive:
it's impossible, i think, to export in a C source the label, because the "#" cause an error in compilation. But inside assembly code it's work.
But the declaration work fine if you use good declaration like: extern "C" void label_13_14();
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation