Operating System - HP-UX
1751832 Members
5440 Online
108782 Solutions
New Discussion юеВ

Re: Make macros for assembler language

 
Sacha Hnatiuk
Occasional Contributor

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?
5 REPLIES 5
Rainer_1
Honored Contributor

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.
Dan Hetzel
Honored Contributor

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
Andy Bennett
Valued Contributor

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.
Sacha Hnatiuk
Occasional Contributor

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();
Sacha Hnatiuk
Occasional Contributor

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();