12.07.2015 Views

MAXQ Core Assembly Guide - Maxim

MAXQ Core Assembly Guide - Maxim

MAXQ Core Assembly Guide - Maxim

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>MAXQ</strong> <strong>Core</strong> <strong>Assembly</strong> <strong>Guide</strong>Macros with Input ParametersThe macro example below contains two parameters which must be passed in each time the macro is called. Thefirst line of the macro definition defines the parameter list.swap macro param Reg1, Reg2This macro has two parameters, Reg1 and Reg2. When the macro is called, each of these parameters must beprovided with a value, such asswap A[0], A[1]When the macro code is expanded, each occurrence of Reg1 will be replaced by A[0], and each occurrence ofReg2 will be replaced by A[1], in the same way that the #define directive operates. However, macro parametersare not #defines, and so they cannot be referenced by #ifdef and #ifndef in the body of the macro.Note that defines and equates used in the macro calling line are processed before the macro code is expanded, sothat for#define REG1 A[0]VAL1 equ 011hswap REG1, VAL1the macro will be expanded with Reg1 replaced by A[0] (not REG1) and Reg2 replaced by 011h (not VAL1). Thefollowing additional rules apply when replacing parameters in the expanded macro body.• The correct number of parameters must be used when calling the macro. If too many parameters are given, aMacro error will result. If too few parameters are given, the missing parameters will not be replaced with valuesin the body of the macro, which will most likely result in an assembler error.• Parameters are not replaced inside comments or double-quoted strings.• Parameters will only be replaced in the macro body where they appear as separate words, that is, for themacro given above, “Reg1” will be replaced in the macro body, but “Reg1Reg2” will not. This is identical to theoperation of #define.source fileswap macro param Reg1, Reg2 ; Could also be "swap macro Reg1 Reg2"move GR, Reg1move Reg1, Reg2move Reg2, GRendm; swap A[0], A[1], A[2] ; Too many parameters (error)swap A[0], A[1]swap; Too few parametersendVersion 1.2 39 of 43 March 7, 2007

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!