Assembler Language Assembler Language Macro "Boot Camp" Macro "Boot Camp" Part 2 Part 2
SHARE in Austin SHARE in Austin March 1 - 6, 2009 March 1 - 6, 2009 Session 8159 Session 8159
1
Assembler Language Assembler Language Macro "Boot Camp" - - PowerPoint PPT Presentation
Assembler Language Assembler Language Macro "Boot Camp" Macro "Boot Camp" Part 2 Part 2 SHARE in Austin SHARE in Austin March 1 - 6, 2009 March 1 - 6, 2009 Session 8159 Session 8159 1 Who am I? Who am I? Michael
1
2
3
4
5
6
7
8
9
seq_sym Lclx var_sym1,var_sym2,... seq_sym Gblx var_sym1,var_sym2,...
10
var_sym SetA arithmetic_expression
11
LclA &S Counter LclA &Con Assigned "constant" &S SetA 3 Initial value &S SetA &S+1 Increment by 1 &Con SetA 2*(1-&S) Set &Con to -6 DC F'&Con' Generates 00000006
12
Macro EQURegs GblA &EQURegs Recall if already done LclA &Reg Counter (initially 0) AIf (&EQURegs NE 0).Done &EQURegs SetA 1 Don't generate again .Loop ANOP R&Reg EQU &Reg &Reg SetA &Reg+1 Increment reg number AIf (&Reg LE 15).Loop .Done MEnd
13
EQURegs +R0 EQU 0 +R1 EQU 1 +R2 EQU 2 +R3 EQU 3 +R4 EQU 4 ... +R12 EQU 12 +R13 EQU 13 +R14 EQU 14 +R15 EQU 15
14
Macro EQURegs GblA &EQURegs Recall if already done LclA &Reg Counter (initially 0) AIf (&EQURegs NE 0).Done &EQURegs SetA 1 Don't generate again .Loop AIf (&Reg GT 15).Done R&Reg EQU &Reg &Reg SetA &Reg+1 Increment reg number AGo .Loop .Done MEnd
15
var_sym SetB binary_value
16
17
&A SetA 4 &B SetB 1 (Note no parentheses) &C SetC 'XYZ' (This is a preview of SetC!) * &X SetB (&B) &X = ? &X SetB (NOT &B) &X = ? &X SetB (&A LE 15) &X = ? &X SetB ('&C' EQ 'XYZ') &X = ? &X SetB ((NOT &B) AND (&A LT 15)) &X = ? &X SetB ((&A GT 0) AND (&A LT 15)) &X = ? &X SetB (&B OR ('&C' EQ 'YES')) &X = ? &X SetB (&B AND NOT (&A GT 5)) &X = ?
18
var_sym SetC 'character_string' note quotes!
19
&A SetA 4 &B SetB 1 &C SetC 'XYZ' * &X SetC 'A&A.B&B.C&C.' &X = ?
20
21
22
Meeting in Progress
23
24
25
26
27
Macro &name AddVal &num,&val .* .* Macro to add &val to &num .* L 0,&num A 0,FWrd ST 0,&num B FWrd+4 FWrd DC F'&val' MEnd
28
29
Macro &name Add1 &num,&val .* .* Macro to add &val to &num .* L 0,&num A 0,FWrd&SYSNDX ST 0,&num B FWrd&SYSNDX+4 FWrd&SYSNDX DC F'&val' MEnd
30
31
32
33
Macro &Name Add &List,&Sum,&R=1,&WKR=0 .******************************************************************** .* .* Function: .* This macro generates assembler instructions to add multiple .* values held in storage as fullword, halfword, and packed data. .* The first operand is a sublist of the labels on the numbers .* to be added. The sum will be returned in register R= as a .* binary value. Optionally, the sum may be returned in storage .* at the location given by the second operand, which must be of .* the fullword, halfword, or packed data type. Instructions .* will be generated appropriate to the data types. .* .* Prototype Statement: .* &Name Add &List,&Sum,&R=1,&WKR=0 .*
34
.* .* Symbolic Parameters: .* &List is a sublist of the values to be added, consisting of .* labels of storage areas of types F, H, and P (required) .* &Sum is a label of type F, H or P and is the calculated sum .* (optional) .* &R= is the sum accumulation register; it is required and .* must be different from &WKR=; &R always has the result .* &WKR= is a scratch register for CVB and CVD instructions in .* case the sum or any summand is type P (required if any .* binary<->decimal conversion is necessary) .* .* Error Conditions: .* Missing summand sublist (8) .* Incorrect sum or summand type (4) .*
35
.* .* Notes: .* Two registers are altered and not saved. By default these .* are R0 and R1. .* .* This exercise and solution are patterned after the ADD macro .* in _Assembler Language Programming for the IBM 370, ASSIST .* Edition_, by Frank M. Carrano, p. 18.34 .* .******************************************************************** .*
36
.* .* Define and initialize local set symbols .* LclA &J &List loop counter LclB &P 1 if decimal summand seen, else 0 LclC &A Current binary operation (L or A) LclC &DEC Current decimal op (ZAP or AP) LclC &H 'H' if LH or AH, '' if L or A LclC &D Unique label for work area LclC &NM &Name for flexibility in use .* &J SetA 1 Start with first summand &P SetB 0 No decimal summands yet &A SetC 'L' First time use L, then A &DEC SetC 'ZAP' First time use ZAP, then AP &H SetC '' Set to 'H' if binary is halfword &D SetC 'DWrd&SYSNDX' Unique label for D work area &NM SetC '&Name' &NM can be cleared, &Name cannot .*
37
.* .* Sublist &List is required - quit if not present, CC=8 .* AIf (K'&List NE 0).Loop MNote 8,'** Error: Required list of summands missing ***' MExit , .* .* Begin loop to process summands .* .Loop AIf (T'&List(&J) EQ 'P').Decimal AIf (T'&List(&J) EQ 'F').FullBin AIf (T'&List(&J) EQ 'H').HalfBin MNote 4,'** Warning: Invalid summand type - &List(&J) **' &J SetA &J+1 Increment loop counter AIf (&J LE N'&List).Loop Continue if more summands AGo .EndList Else done with list .*
38
.* .* Process binary load or add, either halfword or fullword .* .HalfBin ANOP , &H SetC 'H' .FullBin ANOP , &NM &A&H &R,&List(&J) Increment binary part of sum &A SetC 'A' Use A after first L &H SetC '' and set fullword default AGO .LoopEnd Continue .* .* Process decimal zero and add, or add .* .Decimal ANOP , &NM &DEC &D,&List(&J) Increment decimal part of sum &DEC SetC 'AP' Use AP after first ZAP &P SetB 1 We have seen a decimal summand .* .LoopEnd ANOP ,
39
.* .* Bottom of loop - check if any more summands .* &J SetA &J+1 Increment loop counter &NM SetC '' Clear &NAME holder after first use AIf (&J LE N'&List).Loop Continue if more summands .* .* All summands processed - if any were dec, get binary of their sum .* .EndList AIf (NOT &P).NoDSum Skip if no decimal summand CVB &WKR,&D Get binary sum of decimal summands &A.R &R,&WKR Add to sum of binary summands .* .* If the result is to be decimal, convert result to dec, then save .* .NoDSum AIf (T'&Sum EQ 'O').CKD If omitted, don't save result AIf (T'&Sum NE 'P').NoDRes Skip if no decimal result CVD &R,&D Get decimal sum of summands ZAP &Sum,&D Copy to target AGO .CKD Go generate DWORD
40
.* .* If the result is to be binary, save as halfword or fullword .* .NoDRes AIf (T'&Sum EQ 'F').SaveSum AIf (T'&Sum EQ 'H').HalfSum MNOTE 4,'** Warning: Invalid sum type - &Sum **' AGO .CKD Bad type, don't save sum .HalfSum ANOP , &H SetC 'H' .SaveSum ST&H &R,&Sum Save result .* .* If any decimal summands or result, generate scratch doubleword .* .CKD AIf (T'&Sum NE 'P' AND NOT &P).MEnd B &D+8 Branch around doubleword &D DS D Scratch area .* .MEnd MEnd
41
* Add (Word1,Word2),Word3 + L 1,Word1 Increment binary part of sum + A 1,Word2 Increment binary part of sum + ST 1,Word3 Save result ... * Word1 DC F'4' Word2 DC F'6' Word3 DS F *
42
AddDemo Add (One,Two,Three,Two,Three,One),Three +AddDemo L 1,One Increment binary part of sum + AH 1,Two Increment binary part of sum + ZAP DWrd0009,Three Increment decimal part of sum + AH 1,Two Increment binary part of sum + AP DWrd0009,Three Increment decimal part of sum + A 1,One Increment binary part of sum + CVB 0,DWrd0009 Get binary sum of dec summands + AR 1,0 Add to sum of binary summands + CVD 1,DWrd0009 Get decimal sum of summands + ZAP Three,DWrd0009 Copy to target + B DWrd0009+8 Branch around doubleword +DWrd0009 DS D Scratch area ... * One DC F'1' Two DC H'2' Three DC PL2'3'
43
44
45
46
47
48
49