Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!gatech!hubcap!ncrcae!ncr-sd!hp-sdd!hplabs!ucbvax!CITHEX.CALTECH.EDU!carl From: carl@CITHEX.CALTECH.EDU (Carl J Lydick) Newsgroups: comp.os.vms Subject: Re: MACRO Puzzle Message-ID: <870618005830.020@CitHex.Caltech.Edu> Date: Thu, 18-Jun-87 04:21:59 EDT Article-I.D.: CitHex.870618005830.020 Posted: Thu Jun 18 04:21:59 1987 Date-Received: Mon, 22-Jun-87 01:59:30 EDT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: world Organization: The ARPA Internet Lines: 48 > Consider the following program (originally written in MACRO-11): > .MACRO BLUE > .IF NDF BLACK > BLACK=0 > .ENDC > BLACK=BLACK+1 > .ENDM > ; > BLUE > RED: .WORD BLACK > .END > The question is: "What value does the assembler place in RED?" > The interesting observation: "The value depends upon whether you run this > code through the VAX MACRO or through the MACRO-11 assembler." A further observation: When you assemble this program in with the command: > MAC TEMP,TEMP/LI:ME/-SP=TEMP the expansion of the macro and conditional is as follows: 1 .MACRO BLUE 2 .IF NDF BLACK 3 BLACK=0 4 .ENDC 5 BLACK=BLACK+1 6 .ENDM 7 ; 8 000000 BLUE .IF NDF BLACK BLACK=0 .ENDC 000002 BLACK=BLACK+1 9 000000 000002 RED: .WORD BLACK 10 000001 .END Notice that the the condition "NDF BLACK" apparently evaluated FALSE: the MACRO-11 assembler is apparently expanding the MACRO twice: presumably once during an earlier pass, at the end of which it stored the value BLACK had attained, and in the first encounter this pass, BLACK is already defined and resumes its value from the first pass. If you initialize BLACK by inserting the record: BLACK=0 either prior to the first reference to it as an r-value or after the last other reference to it as an l-value, then the MACRO-32 and MACRO-11 assemblers produce the same results.