Pennington— The Name in Software Engineering Automation

XTRAN Demonstration:  Analyze HP (Compaq, Digital) MACRO-11

If you want to translate a body of assembly code to a higher level language, one of the tasks facing you is to identify all symbol definitions that are shared across separately assembled modules.

There are two common ways such definitions are shared in assembly code:

Therefore, in order to find all shared definitions, we must find and report every definition that is either global or defined in the body of macro.  For the latter case, we would like to know in which macro each shared name is defined.  This is complicated by the fact that in many assemblers, macro definitions can be nested; that is, a macro can define another macro when it is invoked.

The following set of XTRAN rules accomplishes this task.  The rules are an English paraphrase of the XTRAN rules language ("meta-code") actually used for the demonstration.  We use a push-down stack to track the name of each macro we find defined, so that when we exit from a nested macro definition, we know what macro definition we "pop" back up into.

The input to and output from XTRAN are untouched, except that line numbers have been added to the input for reference.



* Rules:

Set macro level to 0
For each MACRO-11 statement:
    If start of macro definition
        Increment macro level ("push")
        Remember name of macro at this level
    Else if end of macro definition
        Decrement macro level ("pop")
        Restore name of macro at now current level
    Else if local symbol definition
        If macro level > 0
            Output analysis line, including macro name
    Else if global symbol definition
        Output analysis line, including macro name if any


* MACRO-11 code to be analyzed (demanl-a.mac):

 1         BITB    #1,R0
 2 VAR0    ==      0               ;GLOBAL, NOT IN MACRO
 3         BEQ     10$
 4 .MACRO  MAC1
 5         MOV     R0,R1
 6 VAR1    =       1               ;LOCAL, IN "MAC1" MACRO
 7         MOV     R1,R0
 8 VAR2    ==      2               ;GLOBAL, IN "MAC1" MACRO
 9 .MACRO  MAC2
10 VAR3    =       3               ;LOCAL, IN "MAC2" MACRO
11 .ENDM   MAC2
12 VAR4    =       4               ;LOCAL, IN "MAC1" MACRO
13 .ENDM   MAC1
14 ILLVAR  =       ILLEGAL         ;LOCAL, NOT IN MACRO
15 VAR5    ==      5               ;GLOBAL, NOT IN MACRO
16         MOV     #1,R0


* Output from XTRAN:

File                                                Line Macro  Defn   G?
-------------------------------------------------------------------------
demanl-a.mac                                           2        VAR0   G
                                                       6 MAC1   VAR1    
                                                       8 MAC1   VAR2   G
                                                      10 MAC2   VAR3    
                                                      12 MAC1   VAR4    
                                                      15        VAR5   G


COPYRIGHT 2012; reproduction prohibited without permission.  Revised 2009-09-11

XTRAN is a trademark of Pennington Systems Incorporated, PDP-11 and MACRO-11 of Hewlett-Packard.

  Pennington Systems Incorporated
2820 N. Pinal Avenue, Suite 12
Casa Grande, Arizona 85122-7927
USA


  Phone:  +1(480)626-5503
Fax:  +1(480)626-7618
Email:  Info@Pennington.com
Web:  http://WWW.Pennington.com