Assembler Language Assembler Language Macro "Boot Camp" - - PowerPoint PPT Presentation

assembler language assembler language macro boot camp
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

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

slide-2
SLIDE 2

Who am I? Who am I?

Michael Stack, K Cats Consulting

Instructor in Computer Science at Northern Illinois University from 1982 - 2007, including assembler language, data structures (in assembler), and applied systems programming

2

slide-3
SLIDE 3

Available Materials Available Materials

Materials described in these two sessions, as well as the Assembler Boot Camp, can be found at http://www.kcats.org/share

3

slide-4
SLIDE 4

Yesterday's Agenda (Brief Review) Yesterday's Agenda (Brief Review)

Our First Macro Instruction The Second Version of Our ADD Macro The Macro Programming Language

4

slide-5
SLIDE 5

Today's Agenda Today's Agenda

Variable Symbols We Can Change A Bit More on Variable Symbols Finally, the Add Macro Instruction Wrap Up

5

slide-6
SLIDE 6

Variable Symbols Variable Symbols We Can Change We Can Change

(So (So that's that's why they're called why they're called Set Set Symbols) Symbols)

6

slide-7
SLIDE 7

Set Symbols Set Symbols

Now that we have AIf and AGo to control the path of code generation, it will be very useful to have a way to keep assembly-time data Assembler variables which can hold this data are called set symbols, of which there are three data types

Arithmetic Binary (logical) Character

7

slide-8
SLIDE 8

Set Symbol Scope Set Symbol Scope

As with high level languages, set symbol variables have the scope characteristic The value assigned to a local set symbol is known only within one macro expansion, and each expansion of that - or any other - macro has its own copy of that local variable The value assigned to a global set symbol is known throughout the assembly

8

slide-9
SLIDE 9

Set Symbol Declaration Set Symbol Declaration

Modern assemblers do not require that local Set Symbols be declared before use (older assemblers do, though) But it's a good idea to declare (and globals require it), as it's a great place to document the purpose of the variable Declaration describes the variable as

Local or Global Arithmetic, Binary, or Character

9

slide-10
SLIDE 10

Set Symbol Declaration Set Symbol Declaration

To declare a local set symbol of type x (where x is A, B, or C): where seq_sym may be a sequence symbol and each var_symn is a variable symbol To declare a global set symbol of type x: Although more than one set symbol can be declared in one statement, limiting to one leaves room for a descriptive comment

seq_sym Lclx var_sym1,var_sym2,... seq_sym Gblx var_sym1,var_sym2,...

10

slide-11
SLIDE 11

Arithmetic Set Symbol Assignment Arithmetic Set Symbol Assignment

The SetA instruction is used to assign a value to an arithmetic set symbol (from now

  • n called a SetA symbol)

var_sym is a variable symbol and arithmetic_expression (as described earlier) is evaluated as a signed, 32-bit number The default (initial) value of a SetA symbol is zero

var_sym SetA arithmetic_expression

11

slide-12
SLIDE 12

Arithmetic Set Symbol Assignment Arithmetic Set Symbol Assignment Example Example

Here is some sample code: And here's a real oddity: when &Con (whose value now is -6) is used in a model statement, its absolute value is used:

(Don't ask)

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

slide-13
SLIDE 13

Arithmetic Set Symbol Assignment Arithmetic Set Symbol Assignment Example Example

Here is some more sample code, this one to generate all of the register equates:

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

slide-14
SLIDE 14

Arithmetic Set Symbol Assignment Arithmetic Set Symbol Assignment Example Example

Here is the output (assembler source) from EQURegs (first time only!)

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

slide-15
SLIDE 15

Arithmetic Set Symbol Assignment Arithmetic Set Symbol Assignment Example Example

Here is a slightly different version of the same macro (loop test at top):

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

slide-16
SLIDE 16

Binary (Logical) Set Symbol Binary (Logical) Set Symbol Assignment Assignment

The SetB instruction is used to assign a value to a binary set symbol (from now on called a SetB symbol) var_sym is a variable symbol and binary_value (described in the next slide) is evaluated as a 0 or 1 The default (initial) value of a SetB symbol is zero

var_sym SetB binary_value

16

slide-17
SLIDE 17

Binary (Logical) Set Symbol Binary (Logical) Set Symbol Assignment Assignment

A full description of the binary_value

  • perand of SetB is beyond the scope of

these sessions; simplified, it can be one of

A binary digit (0 or 1) A binary value enclosed in parentheses An arithmetic value enclosed in parentheses If the value is 0, the assembler assigns a value of 0 to the symbol in the name field; if the value is not 0, the assembler assigns a value of 1 A logical expression enclosed in parentheses

17

slide-18
SLIDE 18

Binary (Logical) Set Symbol Binary (Logical) Set Symbol Assignment Examples Assignment Examples

Each &X starts with initial &A, &B, & &C

&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

slide-19
SLIDE 19

Character Set Symbol Character Set Symbol Assignment Assignment

The SetC instruction is used to assign a value to a character set symbol (from now

  • n called a SetC symbol)

character_string is a sequence of characters and variable symbols (followed by '.' for concatenation) interpreted as characters The initial value of a SetC symbol is the null string

var_sym SetC 'character_string' note quotes!

19

slide-20
SLIDE 20

Character Set Symbol Character Set Symbol Assignment Examples Assignment Examples

Here is a SetC example: &X evaluates to the string A4B1CXYZ

Note that the arithmetic and binary values have been converted to character values (See Concatenation in the next section)

&A SetA 4 &B SetB 1 &C SetC 'XYZ' * &X SetC 'A&A.B&B.C&C.' &X = ?

20

slide-21
SLIDE 21

Substrings of SetC Symbols Substrings of SetC Symbols Definition Definition

SetC operands can also be substrings by placing two arithmetic expressions, separated by commas and enclosed in parentheses, immediately following the character expression

The first arithmetic expression identifies the first character of the substring The second arithmetic expression gives the length of the substring

21

slide-22
SLIDE 22

Substrings of SetC Symbols Substrings of SetC Symbols Examples Examples

'ABCDEF'(3,2) evaluates to 'CD' If &VAR evaluates to 2 and &STR evaluates to 'ABCD' then '&STR.%'(2,&VAR*2) evaluates to 'BCD%' 'AB'.'CD'.'EFG'(1,2).'H' evaluates to 'ABCDEFH' (For . see concatenation in the next section)

22

slide-23
SLIDE 23

A Bit More on A Bit More on Variable Symbols Variable Symbols

Then we can Then we can really really go to work! go to work!

Meeting in Progress

23

slide-24
SLIDE 24

Concatenation Concatenation

Concatenation can sometimes be without ambiguity

&this&that (variable.variable) this&that (ordinary.variable)

Others are a problem

&thisthat (variable.ordinary intended)

We use the concatenation operator '.' to avoid the ambiguity

&this.that

24

slide-25
SLIDE 25

Symbolic Parameter Sublists Symbolic Parameter Sublists

A single macro operand can be a list of elements, called a sublist, with one or more items enclosed in parentheses and separated by commas

(X,2,Y)

An individual sublist item can be referred to by a subscripted symbolic parameter, so if &ABC has the value (W,15)

&ABC(1) has the value W &ABC(2) has the value 15 But &ABC.(1) has the value (W,15)(1)

25

slide-26
SLIDE 26

Keyword Symbolic Parameters Keyword Symbolic Parameters

Macro prototype statements may have keyword operands as well as positional These are coded on the prototype as

&Keyword=[default] The default value is optional

The advantages of keyword parameters are

They can have a default value They can be coded in any order when invoked But positionals look more like operands

26

slide-27
SLIDE 27

System Variable Symbols System Variable Symbols

The third kind of variable symbol after symbolic parameters and set symbols is the set of system variable symbols

These all begin with &SYS so this prefix should be avoided in programmer-created variable symbols

Some popular examples

&SYSTIME - time of the assembly &SYSDATC - Y2K-compliant date of assembly &SYSNDX - (see the following slides)

27

slide-28
SLIDE 28

System Variable Symbol &SYSNDX System Variable Symbol &SYSNDX

Here is a macro - what's its problem?

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

slide-29
SLIDE 29

System Variable Symbol &SYSNDX System Variable Symbol &SYSNDX

The way it's written, it can be used only

  • nce in an assembly (because of FWrd)

We can fix this by concatenating &SYSNDX

&SYSNDX has a new value assigned by the assembler each time a macro is called For the first macro, &SYSNDX is 0001 It increases by 1 for any macro invocation Until it goes past 9999, it is four characters

This can provide unique labels for macros

29

slide-30
SLIDE 30

System Variable Symbol &SYSNDX System Variable Symbol &SYSNDX

Here is the macro rewritten using &SYSNDX

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

slide-31
SLIDE 31

Attributes of Symbols Attributes of Symbols

As should be expected in a HLL (!) like assembler, symbols have attributes We will be concerned with only three

Type, which distinguishes one form of named

  • bject from another, such as character data

from binary data Count, which gives the number of characters required to represent the data as a character string Number, which gives the number of sublist entries in a macro instruction operand

31

slide-32
SLIDE 32

Attributes of Symbols Attributes of Symbols

We can refer to these attributes inside macro instructions by using a single letter followed by a single quote: T' K' and N' For example in the Add1 macro

T'FWrd&SYSNDX is F And if we invoke as Add1 F4,18 then K'&num is 2 N'&num is 1

We will see more in the next slides

32

slide-33
SLIDE 33

Finally, The Add Finally, The Add Macro Instruction Macro Instruction

In which we analyze and In which we analyze and demonstrate an overloaded Add demonstrate an overloaded Add

33

slide-34
SLIDE 34

Add Macro Definition: Add Macro Definition: Prototype and Doc Box 1 Prototype and Doc Box 1

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

slide-35
SLIDE 35

Add Macro Definition: Add Macro Definition: Prototype and Doc Box 2 Prototype and Doc Box 2

.* .* 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

slide-36
SLIDE 36

.* .* 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 .* .******************************************************************** .*

Add Macro Definition: Add Macro Definition: Prototype and Doc Box 3 Prototype and Doc Box 3

36

slide-37
SLIDE 37

Add Macro Definition: Add Macro Definition: Set Symbol Declaration & Init Set Symbol Declaration & Init

.* .* 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

slide-38
SLIDE 38

Add Macro Definition: Add Macro Definition: Initial Check, Main Loop Initial Check, Main Loop

.* .* 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

slide-39
SLIDE 39

Add Macro Definition: Add Macro Definition: Process Binary and Decimal Process Binary and Decimal

.* .* 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

slide-40
SLIDE 40

Add Macro Definition: Add Macro Definition: Add Dec Summand, Dec Result Add Dec Summand, Dec Result

.* .* 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

slide-41
SLIDE 41

.* .* 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

Add Macro Definition: Add Macro Definition: Store Result, Gen Temp Storage Store Result, Gen Temp Storage

41

slide-42
SLIDE 42

Add Macro Output: Add Macro Output: Example 1 Example 1

* 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 *

This is similar to the code in ADD2, except that this uses the RX add instead of RR (A instead of AR)

42

slide-43
SLIDE 43

Add Macro Output: Add Macro Output: Example 2 Example 2

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

slide-44
SLIDE 44

Wrap Up Wrap Up

In Which We Learn That Only In Which We Learn That Only a Small Fraction of the Macro a Small Fraction of the Macro Language Has Been Covered Language Has Been Covered

44

slide-45
SLIDE 45

Summary Summary

Two hours is just a start, but a good one For further information, John Ehrman often gives sessions at SHARE on advanced macro techniques: 'Assembler as a Higher Level Language'

Basic Conditional Assembly and Macro Concepts Applied macro techniques

45

slide-46
SLIDE 46

Some of What Wasn't Covered Some of What Wasn't Covered

Set symbols

Subscripted set symbols and extended Set statements SetAF and SetCF Created set symbols

Many data attributes (length, scaling, integer, etc.) Many system variable symbols

&SYSLIST in particular

46

slide-47
SLIDE 47

Some of What Wasn't Covered Some of What Wasn't Covered

Controlling macro expansion listing using PRINT GEN / NOGEN Defining macros within macros (!) Using macros to create job streams (SYSGEN) - important to understand SMP/E Using conditional assembly in open code (outside macros)

47

slide-48
SLIDE 48

Nevertheless... Nevertheless...

You now have a basic understanding of S/390 and z/OS assembler macro language You have seen what comprises a macro written in assembler language And you are ready, if you wish, to begin writing macros (the best way to learn) and go on to the next step So, ...

48

slide-49
SLIDE 49

Congratulations! Congratulations!

49