Professional Documents
Culture Documents
CTS-PAC
Version 2.0
Assembler/Session 1
CTS-PAC
Version 2.0
Assembler/Session 1
COURSE SCHEDULE
Introduction
SESSION 1 Day 1
SESSION 2 Day 1
SESSION 3 Day 2
CTS-PAC
Addressing
Machine Instructions
Version 2.0 3
Assembler/Session 1
COURSE SCHEDULE
SESSION 4 Day 3
SESSION 5 Day 3
Program Sectioning
Assembler Directives
Assembler/Session 1
COURSE SCHEDULE
SESSION 8 Day 4 SESSION 9 Day 5 Macro Language Other Topics
CTS-PAC
Version 2.0
Assembler/Session 1
Assembler Language
SESSION 1
CTS-PAC
Version 2.0
Assembler/Session 1
Objectives INTRODUCTION
INTRODUCTION
An assembler language is a symbolic form of machine language Assembler translates assembler language program to machine language An assembler program consists of many statements In general, one assembler language statement corresponds to one machine language instruction
CTS-PAC Version 2.0 7
Assembler/Session 1
Objectives
16 operands
30 comments
LA R5,4
;INITIALISE REGISTER 5
Rules for choosing labels: maximum 8 characters Alphabets, digits, @, #, $ First character should not be a digit label should begin in column 1
CTS-PAC Version 2.0 8
Assembler/Session 1
Col1
Col10 L A ST
.. .. A B
CTS-PAC
DC DC
Version 2.0
F15 F20
9
Assembler/Session 1
Objectives
Operation One of the 200 M/C instruction mnemonics (eg. MVC) Operand can be a register or memory location Continuing a statement Place any character in column 72 of the line to be continued Continue the statement from column 16 of next line Maximum 2 continuation lines for a statement
CTS-PAC Version 2.0 10
Assembler/Session 1
Objectives
Comment Statement * in column 1 Any text in columns 2 - 71 Note : Fields separated by one or more blanks
CTS-PAC
Version 2.0
11
Assembler/Session 1
Objectives
CTS-PAC
Version 2.0
12
Assembler/Session 1
Registers are storage areas inside the processor Advantages: - No need to retrieve data from main storage (saves time) - Shared resource that allows inter communication between programs
Objectives
REGISTERS REGISTERS
CTS-PAC
Version 2.0
13
Assembler/Session 1
Objectives
General purpose registers: * 16 registers available * Numbered 0 - 15 * Holds 32 bits (4 bytes) of data (1 Full word) Floating point registers: * 4 registers available * Numbered 0,2,4,6 * Holds 64 bits (8 bytes) of data
Note : The registers 0, 1, 13, 14 and 15 are reserved for special purpose By IBM convention these registers are used for calling subprograms
CTS-PAC Version 2.0 14
REGISTERS REGISTERS
Assembler/Session 1
Objectives
Binary fields - Always fixed in length, either 2 or 4 bytes (Full word or Half word) - Negative numbers stored in 2s complement form Examples: A DC B DC
H295 H-75
01 27 FF 35
CTS-PAC
Version 2.0
15
Assembler/Session 1
Objectives
How to identify a negative number? - Leading bit contains a 1 (In Hex 8 to F) How to convert to a negative number? -First switch the bits (1 to 0 , 0 to 1) -Finally add 1
CTS-PAC
Version 2.0
16
Assembler/Session 1
Objectives
Full word Should begin in a full word boundary (Achieved by aligning with 0F) Half word Should begin in a half word boundary (Achieved by aligning with 0H) How to find: The starting address of Full word should end with 0, 4, 8 or C and Half words should end with 0, 2, 4, 6, 8, A, C or E
CTS-PAC Version 2.0 17
Assembler/Session 1
Objectives
Characters - One byte (EBCDIC form) - Character representation of decimal digits is called Zoned Decimal (first nibble is zone and next is digit) Zone digit
0-9 +, - , blank Zone + Blank Code C, A,E,F D, B F
CTS-PAC
Version 2.0
18
Assembler/Session 1
Objectives
CTS-PAC
Version 2.0
19
Assembler/Session 1
Objectives
753C
Version 2.0 20
Assembler/Session 1
Objectives
Addressing Operands Register addressing Base, displacement addressing Base, index and displacement addressing
CTS-PAC
Version 2.0
21
Objectives
B1 D1
SI
opcode
I2
SS
opcode
B1
D1
B2
D2
SS
opcode L1 L2 B1
D1
B2
D2
RX
opcode R1 X2 B2
D2
RS
opcode R1 R3 B2
CTS-PAC
D2
22
Version 2.0
Assembler/Session 1
CTS-PAC
Version 2.0
23
Assembler/Session 2
CTS-PAC
Version 2.0
24
Assembler/Session 2
Objectives
Two ways to define fields : 1. Define a field and initialize the data in it using the DC assembler directive 2. Define a field without initializing using the DS assembler directive
CTS-PAC
Version 2.0
25
Assembler/Session 2
Objectives
Format:
label {DS/DC} dtLnvalue
where :
label d t Ln : Label used to name the field (optional) : Duplication factor (optional) : Type of data ( required) : The letter L followed by the length of the field in bytes (optional) value : Represents the value enclosed in apostrophes
CTS-PAC Version 2.0 26
Assembler/Session 2
Objectives
CABC EF 3CL2 H29 F-10 X03 PL4-72
Examples:
ALPHA FLDS H1 F2 F1 F3 DC DS DC DC DC DC
Note : for character constants truncation or padding is to the right and for almost all others it is to the left.
CTS-PAC Version 2.0 27
Assembler/Session 2
Objectives
Alignment None None None Full word Half word Full word Double word Double word None
Version 2.0
DC TYPES
Type C X B F H E D L P Implied Length 4 2 4 8 16 CTS-PAC
Data Representation Character Hex digits Binary digits Binary Binary Floating point Floating point Floating point Packed decimal
28
Assembler/Session 2
Objectives
COBOL
PASCAL
BASIC
Assembler/Session 2
STORAGE DEFINITIONS
Objectives
Literals
A literal is a constant preceded by an equals sign =.
R4,=F1
Version 2.0 30
Assembler/Session 2
Objectives
Exercise 1 Q 1 and Q2. 2.What will happen in the following cases DC CL5123 DC CL5123456 DC XA1245 DC XL2A1245 DC XL5A1245 DC F19 DC FL1513
CTS-PAC Version 2.0 31
Assembler/Session 2
Objectives
EQU (Assembler directive) The EQU statement is used to associate a fixed value with a symbol R4 EQU 4 DRBACK EQU OUT+25
CTS-PAC
Version 2.0
32
Assembler/Session 2
Objectives
By establishing the addressability of a coding section, you can refer to the symbolic addresses defined in it in the operands of machine instruction Assembler will convert the implicit addresses into explicit addresses (base - displacement form)
CTS-PAC Version 2.0 33
Assembler/Session 2
Objectives
Specify a base address from which the assembler can compute displacements Assign a base register to contain this base address Write the instruction that loads the base register with the base address Note: The base address should remain in the base
register throughout the execution of the program
CTS-PAC Version 2.0 34
Assembler/Session 2
Objectives
The USING and DROP assembler instructions enable one to use expressions representing implicit addresses as operands of machine instruction statements, leaving the assignment of base registers and the calculation of displacements to the assembler USING - Use Base Address Register - allows one to specify a base address and assign one or more base registers
CTS-PAC Version 2.0 35
Assembler/Session 2
Objectives
To use the USING instruction correctly, one should know : which locations in a coding section are made addressable by the USING statement where in a source module you can use these established addresses as implicit addresses in instruction operands Format: symbol USING base address,basereg1| basereg2|,.. e.g. USING BASE,9,10,11 USING *,12
CTS-PAC
Version 2.0
36
Assembler/Session 2
Objectives
Range of a USING instruction: The range of a USING instruction is the 4096 bytes beginning at the base address specified in the USING instruction Domain of a USING instruction The domain of a USING instruction begins where the USING instruction appears in a source module to the end of the source module
CTS-PAC
Version 2.0
37
Assembler/Session 2
Objectives
Assembler/Session 2
Objectives
ALPHA+2 or BETA-4
BETA
Assembler/Session 3 & 4
CTS-PAC
Version 2.0
40
Assembler/Session 3 & 4
Objectives
Move Character Instruction (MVC) Copy data from one place in memory to another Format : MVC operand1,operand2 S1(L), S2 - implicit - explicit
INPUT(5),OUTPUT
Version 2.0 41
Assembler/Session 3 & 4
Objectives
Move Immediate Instruction (MVI) Can move only one byte of constant data to a field Format : MVI operand1,operand2 S1,I2 D1(B1),I2 e.g.. MVI CTL,CB - implicit - explicit
CTS-PAC
Version 2.0
42
Assembler/Session 3 & 4
Objectives
PAD+6(4),=CL4 CL10
CTS-PAC
Version 2.0
43
Assembler/Session 3 & 4
Objectives
CTS-PAC
Version 2.0
44
Assembler/Session 3 & 4
Objectives
Comparison Instructions Compares 2 values - the values are found in fields, in registers or in immediate data CLC - Compare logical character e.g. CLC FLDA,FLDB
CTS-PAC
Version 2.0
45
Assembler/Session 3 & 4
Objectives
Exercise 2 Q1 and Q2 2. What will be the effect of the following instructions :
CTS-PAC
Version 2.0
46
Assembler/Session 3 & 4
Objectives
Three types of binary instructions Full word Half word Register The Binary Move Instructions L, LH, LR ,ST, STH Type : R,X Register and indexed storage
e.g... L STH
CTS-PAC
5,FULL 7,HALF
Version 2.0
LR
5,7
47
Assembler/Session 3 & 4
Objectives
Note : Do not mix up the instruction types and field types e.g.
LH L ST RES DS 5,FULL - right half of Reg 5 gets 1st 2 bytes at FULL 6,HALF - Reg 6 gets 4 bytes starting from HALF 3,RES H H15 F8 - 4 bytes of reg 3 are stored starting from RES
HALF DC FULL DC
CTS-PAC
Version 2.0
48
Assembler/Session 3 & 4
Objectives
Binary Addition (A, AH and AR) Fixed-point overflow occurs when the sum will not fit in the receiving register Type R-X e.g.
A AH AR
CTS-PAC
Assembler/Session 3 & 4
Objectives
CTS-PAC
Version 2.0
50
Assembler/Session 3 & 4
Objectives
CTS-PAC
Version 2.0
51
Assembler/Session 3 & 4
op1,op2
op1 : An even numbered register; refers to an even-odd pair of registers (any register in case of half word format) op2 : storage area (full word/half word/register)
CTS-PAC
Version 2.0
52
Binary Multiplication (M, MR, MH) ... Function : The value in OP2 is multiplied by the
value in the odd register of the even-odd pair and the result placed in even-odd registers
(For half word format : The half word specified in OP2 is multiplied by the value in OP1 and result stored in OP1.)
CTS-PAC
Version 2.0
53
Assembler/Session 3 & 4
Objectives
op1,op2
R-X / R-R
Op1 : An even numbered register. It refers to an even-odd pair of registers. The pair holds the double word to be divided. The even register receives the remainder; the odd register receives the quotient. e.g. D 4,FULL
CTS-PAC
Version 2.0
54
Assembler/Session 3 & 4
Format :
e.g.
BC
B1001,BRPTA
will cause a branch to the instruction named BRPTA, if at the time the instruction is executed, the condition code is 0 or 3.
CTS-PAC Version 2.0 55
Assembler/Session 3 & 4
Objectives
BRANCHING BRANCHING
A branch causes execution to continue at some other instruction in the program Branch conditions : Arithmatic B, BZ,BP,BM, BNZ,BNP,BNM,BO,BNO Comparison BH, BL, BE, BNH, BNL,BNE e.g : CLI FLDA,CK BNL GOOD
CTS-PAC Version 2.0 56
Assembler/Session 3 & 4
condition code occupies 2 bits of PSW condition code is set by each of a number of instructions condition code is an extremely important intermediary between arithmetic instructions and conditional branch instructions very important in implementing control structures CC Arithmetic Comparison 0 1 2 3 Zero < Zero >Zero Overflow
CTS-PAC
Objectives
First operand = Second operand First operand < Second operand First operand > second operand Not set
Version 2.0 57
Assembler/Session 3 & 4
LPR - Load positive register (Loads into R1 the absolute value of R2) LNR Load Negative register (Loads into R1 the negative of absolute value of R2) LCR Load complement register (Loads opposite sign of the value in R2) Note: R1 and R2 can be the same
CTS-PAC
Version 2.0
58
Assembler/Session 3 & 4
Objectives
S-S OC NC XC R-R OR NR XR O N X
Operation OR AND
S-I OI NI
R-X
Exclusive OR XI e.g... OI NR X
CTS-PAC
Version 2.0
59
Assembler/Session 3 & 4
Objectives
AND
OR Second 0 1 First 0 1 0 1 1 1
Second 0 1 First 0 1 0 0 0 1
Exclusive OR
Second First 0 1 0 0 1 1 1 0
CTS-PAC
Version 2.0
60
Assembler/Session 3 & 4
Objectives
Function : The bits of S1 ( a single byte) are tested under the control of the mask in I2 and condition code is set as all zeroes, all ones or mixed e.g. TM EMP,B00000101 BNM NEXT
CTS-PAC
Version 2.0
61
Assembler/Session 3 & 4
Objectives
Bit Shifting Instructions SLL, SLDL Left logical SRL, SRDL Right logical (No condition code set) SLA, SLDA Left arithmetic SRA, SRDA Right arithmetic
(Sign bit not affected and condition code set)
e.g.
SLL SRDA
5,1 4,5
Version 2.0 62
CTS-PAC
Assembler/Session 3 & 4
Objectives
Bit Shifting Instructions Condition code setting for arithmetic shift instructions 0- Result is zero 1- Result is negative 2- Result is positive 3- Overflow generated Overflow is generated when a bit other than the sign bit is shifted out
CTS-PAC Version 2.0 63
Assembler/Session 3 & 4
BIT MANIPULATIONS
If the source byte is x40 (Space), then the displacement into the table is 64. The value in the table at displacement 64 will be replacing the source.
CTS-PAC Version 2.0 64
Assembler/Session 3 & 4
Objectives
1 byte - 256 possible combinations x00,x01, x02, x03,..x0F x10,x11,x12,..x1F .. xF1,xF2,xF3,xFF The table should start with replacement byte for x00 and end with replacement for xFF
CTS-PAC Version 2.0 65
Assembler/Session 3 & 4
Assembler/Session 3 & 4
Objectives
CTS-PAC
Version 2.0
67
Assembler/Session 3 & 4
Objectives
1. Conversion to binary (CVB) Format: CVB operand1,operand2 operand1 : Register operand2 : a double word (containing valid packed decimal number) e.g.
binary
CTS-PAC Version 2.0 68
CVB
5,DOUBLE
Assembler/Session 3 & 4
Objectives
2. Conversion from binary (CVD) Format: CVD operand1,operand2 operand1 : Register operand2 : a double word e.g. CVD 5,DOUBLE Use : Binary-(CVD)->Packed decimal-(UNPK)->
Character data
CTS-PAC
Version 2.0
69
Assembler/Session 3 & 4
Objectives
3. Conversion from Zoned decimal to packed (PACK) (SS instruction) Format: PACK operand1,operand2
CTS-PAC
Version 2.0
70
Assembler/Session 3 & 4
Objectives
4 Packed decimal to Zoned decimal (UNPACK) Format: UNPACK operand1,operand2 operand1 : Zoned decimal operand2 : Packed decimal e.g. UNPACK ZD(5),PACKED(2)
CTS-PAC
Version 2.0
71
Assembler/Session 3 & 4
Relation between CVD,CVB,PACK and UNPACK Relation between CVD,CVB,PACK and UNPACK
Objectives
Binary in Register
CVB CVD
PACK
Input
Packed Decimal
UNPK
Zoned Decimal
Output
CTS-PAC
Version 2.0
72
Assembler/Session 3 & 4
Example code for Different conversions Example code for Different conversions
Objectives
7,PNUM 7,=F1 7,PNUM
PNUM(8),START(3)
ANS(3),PNUM(8)
DC C125 DS CL3 DS D
Version 2.0 73
Assembler/Session 3 & 4
Objectives
ZAP - Zero and add packed MP - Multiply packed DP CP - Divide packed - Compare packed
Note: All these operations ignore the decimal places. You have to track the decimal places and edit it with ED and EDMK instructions
CTS-PAC Version 2.0 74
Assembler/Session 3 & 4
Objectives
Advanced instructions:
SRP - Shift and Round packed OPCODE D1(L,B1),D2(B2),I3 First operand - Memory location including length Second operand - Direction and number of places to shift Third operand - Whether to round or not ------------------------------------------------------------------------Second operand, <= 32, left shift is done and 33 to 64 right shift is done. Number for right shift = ( 64 - number of digits to be shifted) (No rounding is involved in left shift
CTS-PAC
Version 2.0
75
Assembler/Session 3 & 4
Objectives
CTS-PAC
Version 2.0
76
Assembler/Session 3 & 4
Objectives
Advanced instructions:
MVZ - Move Zone (Moves the first half of each byte) MVN - Move numeric (Moves the second half of each byte) MVO - Move with offset EG: Multiply A by 100 where value of A is 123 MVC TEMP(3),A MVN TEMP+2(1),=X00 MVZ TEMP+3(1),=X00 MVN TEMP+3(1),A+2 A
CTS-PAC
DC
PL3123
Version 2.0 77
TEMP DS PL4
Assembler/Session 3 & 4
Editing the output for printing Editing the output for printing
Version 2.0
78
Assembler/Session 3 & 4
Editing the output for printing Editing the output for printing
Objectives
V alues being ex ined am P attern PDdig it b yte D it ig 0 selector 1 -9 S ignificanc 0 e starter 1 -9 Field seperator A other ny b yte D it ig selector S ignificanc e starter Field seperator A other ny b yte N ne o N ne o 0 -9 0 -9 N ne o N ne o
A ction tak en N pattern ew F character ill dig in it EB ID C IC F character ill dig in it EB ID C IC F character ill F character ill dig in it EB ID C IC dig in it EB ID C IC F character ill P attern b yte not chang ed N state of ew S I O ff O n O n O n O ff O ff O n O n O ff O n
CTS-PAC
Version 2.0
79
Assembler/Session 3 & 4
Editing the output for printing Editing the output for printing
Objectives
-ED and EDMK can detect the difference between significant and non signi ficant digits ie between leading and non leading zeros - Significance starter forces all subsequent digits to be considered significant -When significance indicator is off and detection of a significant digit turns it on, the address of that significant digit placed in 8-31 of register 1 by EDMK -EDMK allows a floating currency and/or algebraic sign but ED does not allow
CTS-PAC
Version 2.0
80
Assembler/Session 3 & 4
Objectives
DS L 6F
4,RATE+8
Objectives
BCT op1,op2
e.g.
REPEAT
LH EQU .. BCT
9,=H12 *
9,REPEAT
82
CTS-PAC
Version 2.0
Assembler/Session 3 & 4 Branch on index high and branch on index low or equal (BXH and BXLE)
Objectives
op1,op2,op3
Format:
BXLE BXH
op1 : A register known as the index register op2 : A even-odd pair of registers Even register - increment register Odd register - Limit register op3 : A storage operand. This is the branch address.
CTS-PAC
Version 2.0
83
Assembler/Session 3 & 4
Function : First, the value in the increment Objectives register. Second, register is added to the indexed the branch is taken only when the value in the index register is lower than or equal to / higher than the value in the limit register Useful when the same register is to be used as the count and index register
CTS-PAC
Version 2.0
84
Assembler/Session 3 & 4
BXLE BXHe.g...
DO UNTIL repetitions
DO WHILE repetitions
LH LH LH --7,=H0 2,=H2 3,=H18 index increment amount the limit
Objectives
REPEAT
CTS-PAC
Version 2.0
85
Assembler/Session 3 & 4
Assembler/Session 3 & 4
USING EQUATES USING EQUATES To associate a fixed value with a symbol Useful for length and relative address calculation e.g.
TABLE DS DC DC ... TBLEND TBLSIZE
CTS-PAC
Objectives
0H C01 C02
Assembler/Session 3 & 4
Can be
1. To assign single absolute values to symbols. 2. To assign the values of previously defined symbols or expressions to new symbols, thus allowing you to use different mnemonics for different purposes. 3. To compute expressions whose values are unknown at coding time or difficult to calculate. The value of the expressions is then assigned to a symbol.
CTS-PAC Version 2.0 88
Assembler/Session 5
CTS-PAC
Version 2.0
89
Assembler/Session 5
Beginning and End of Source Modules Beginning and End of Source Modules
Objectives
Code a CSECT segment before any statement that affects the location counter END statement is required as the last statement in the assembly
CTS-PAC
Version 2.0
90
Assembler/Session 5
A source module can be divided into one or more control sections A control section is the smallest subdivision of a program that can be relocated as a unit
Objectives
CTS-PAC
Version 2.0
91
At coding time, establish the addressability of each control section within the source module, and provide any symbolic linkages between control sections that lie in different source modules. Initiated by using the START or CSECT instruction
CTS-PAC
Version 2.0
92
Assembler/Session 5
Any instruction that affects the location counter, or uses its current value, establishes the beginning of the first control section.
Objectives
CTS-PAC
Version 2.0
93
Operation
CSECT
Operand
Not required
Assembler/Session 5
Objectives
A dummy control section is a reference control section that allows you to describe the layout of data in a storage area without actually reserving any virtual storage.
CTS-PAC
Version 2.0
95
Use the DSECT instruction to initiate a dummy control section or to indicate its continuation. Format of DSECT: Name
Any symbol or blank
CTS-PAC Version 2.0 96
Operation
DSECT
Operand
Not required
Assembler/Session 5
Objectives
Reserve a storage area for the unformatted data Ensure that this data is loaded into the area at
execution time
Analogy: Cobol copybook
CTS-PAC
Version 2.0
97
Ensure that the locations of the symbols in the dummy section actually correspond to the locations of the data being described Establish the addressability of the dummy section in combination with the storage area
You can then refer to the unformatted data symbolically by using the symbols defined in the dummy section.
CTS-PAC Version 2.0 98
Assembler/Session 5 ASMBLY2 BEGIN CSECT BALR USING ... LA USING CLI BE ... ATYPE MVC MVC ..
CTS-PAC Version 2.0 99
Objectives 2,0
*,2 Reg 3 points to data area 3,INPUT INAREA,3 INCODE,C'A' ATYPE WORKA,INPUTA WORKB,INPUTB
DS DS DS ...
...
CTS-PAC Version 2.0 100
Assembler/Session 5
Objectives
TITLE : To provide headings for each page of the assembly listing of the source modules. EJECT : To stop the printing of the assembler listing on the current page, and continue the printing on the next page. ORG : To reset the location counter
CTS-PAC
Version 2.0
101
LTORG : A literal pool is created immediately after a LTORG instruction or, if no LTORG instruction is specified, at the end of the first control section. PRINT : To control the amount of detail to be printed in the listing of programs.
PRINT
CTS-PAC
NOGEN / GEN
Version 2.0 102
Assembler/Session 6
CTS-PAC
Version 2.0
103
Assembler/Session 6
Program Entry and Exit Logic Program Entry and Exit Logic
Objectives
Program entry - Preserve register contents Program Exit - Restore register contents Register save area Always calling program provides a save area of 18 Full words long used for storage of registers Save area address passed through register 13 by IBM convention
CTS-PAC Version 2.0 104
Assembler/Session 6
Address of calling programs save area Address of called programs save area Contents of Register 14 Contents of Register 15 Contents of Register 0 Contents of Register 12
Version 2.0 105
Assembler/Session 6
Objectives
1.Save contents of registers 0-12,14 & 15 in calling programs save area 2.Establish base register 3.Store calling programs save area in the 2nd word of its own save area
CTS-PAC
Version 2.0
106
Assembler/Session 6
Program entry conventions (contd..) 4. Store the address of its register save area in the third word of the calling programs register save area (The addresses in the 3d word of save area establish a chain of register save areas. This will be useful in reading the dump when program crashes).
Objectives
CTS-PAC
Version 2.0
107
Assembler/Session 6
Objectives
R14,R12,12(R13)
Assembler/Session 6
Objectives
1. Restore registers 0-12 and 14 2. Place the address of the save area provided by the calling program in Reg 13 3. Place a return code in the low order byte of register 15 if one is required. Otherwise restore register 15.
CTS-PAC Version 2.0 109
Assembler/Session 6
Objectives
R13,4(R13)
LM R14,R12,12(R13) BR R14
CTS-PAC
Version 2.0
110
Assembler/Session 6
CTS-PAC
Version 2.0
111
Assembler/Session 6
4. Register 1 should have the address of the parameter list A BALR instruction stores the address of the next instruction in the calling program into register 14 and transfers control to the called subroutine
BALR R14,R15
CTS-PAC
Version 2.0
112
Assembler/Session 6
Objectives The standard interface requires that addresses of parameters be placed in a block of storage, and the address of the block be loaded into register 1 as the subroutine is called
Both input and output parameters are treated the same way e.g... ADDS
DC DC DC LA
CTS-PAC
Assembler/Session 6
R1
Objectives
Parmlist
Main storage
Addr of parmlist
parm3
CTS-PAC
Version 2.0
114
Assembler/Session 6
L L
R3,4(,R1) R8,0(,R3)
CTS-PAC
Version 2.0
115
Assembler/Session 6
Objectives
R0 : Contains single word output of a subroutine R1 : contains the address of an area of main storage that contains addresses of parameters
CTS-PAC
Version 2.0
116
Assembler/Session 6
Objectives
Objectives
R14,R12,12(R13)
DC
Assembler/Session 6
Subroutine RDIGIT
RDIGIT STM R14,R12,12(R13) BALR USING ST LA ... L BALR ... L LM LM BR SAV RANDAD DC DS R13,SAV+4 R14,R15,12(R13) R1,R12,24(R13) R14 18F R15,RANDAD R14,R15 R12,0 *,R12 R13,SAV+4 R13,SAV
Objectives
A(RANDOM)
CTS-PAC
Version 2.0
119
Assembler/Session 6
Program divided into 2 or more source modules Source module divided into 2 or more control sections For link-editing, a complete object module or any individual control section of the object module can be specified
Objectives
CTS-PAC
Version 2.0
120
Assembler/Session 6
Communicating between program parts To communicate between 2 or more source modules, symbolically link them together To communicate between 2 or more control sections within a source module, establish proper addressability
Objectives
CTS-PAC
Version 2.0
121
Assembler/Session 6
Assembler/Session 6
Objectives program A
EXTRN WXTRN TABLEB TABLEB V(TABLEB)
TABADR
DS
program B
ENTRY TABLEB
CTS-PAC
TABLEB ...
Version 2.0 123
DS
Assembler/Session 6
Objectives
An address constant is a main storage address contained in a constant A V-type constant is the value of an external symbol - a relocatable symbol that is external to the current control section. Used for branching to locations in other control sections
e.g ADCON
GSUBAD
L DC
DC
5,ADCON A(SOMWHERE)
V(READATA)
CTS-PAC
Version 2.0
124
Assembler/Session 7
CTS-PAC
Version 2.0
125
M/C
Macro Instr.
Assembler/Session 7
EXEC PGM=pgmname,PARM=
When program gets control : Register 1 contains the address of a full word on a full word boundary in programs address space the high order bit of this full word is set to 1 (this convention is to indicate the last word in a variable length parameter list)
CTS-PAC Version 2.0 127
Objectives
Assembler/Session 7
COBOL to Assembler
CALL
PL/I to Assembler
DCL ASMSUB ENTRY OPTIONS(ASSEMBLER) CHARSTRING CHAR(25); CALL ASMSUB(CHARSTRING);
CTS-PAC
Version 2.0
129
Assembler/Session 8
CTS-PAC
Version 2.0
130
Assembler/Session 8
Macros
Objectives
Short source routines written and stored in libraries Assembler inserts the source statements in the program where the macro appears
CTS-PAC Version 2.0 131
Macro Definition Format : A header statement A prototype Model statements A trailer statement
CTS-PAC Version 2.0 132
Assembler/Session 8
Header statement:
Objectives MACRO
&TO,&FROM,&LENGTH
MEND
Version 2.0 133
Assembler/Session 8
Macro Instruction:
A statement containing the name of a macro when expanded, the symbolic parameters in the model statements are replaced by corresponding parameters from the macro instructions symbolic parameters may be positional or keyword
CTS-PAC Version 2.0 134
Objectives
MEND
CTS-PAC
Version 2.0
135
Assembler/Session 8
SET Symbols (global or local) 3 types : binary (SETB) character (SETC) arithmetic (SETA)
Objectives
SET symbols are declared using, LCLA GCLA LCLB GCLB LCLC GCLC
CTS-PAC
Version 2.0
136
Assembler/Session 8
Format: Label symbol-name operation operands Objectives SETA SETB SETC e.g. LCLA&A1 GCLA &A1 SETA &A2 SETA
CTS-PAC
An expression
&A2 1 &A1+3
Version 2.0 137
Assembler/Session 8
Attributes
There are 6 attributes of a symbol or symbolic parameter : type, length, scaling, integer, count and number System variable symbols
&SYSINDX, &SYSDATE, &SYSTIME, &SYSECT, &SYSPARM, &SYSLOC
CTS-PAC Version 2.0 138
Objectives
Assembler/Session 8
Conditional Assembly
The assembler can be made to branch and loop among assembler language statements using sequence symbols and the assembler instructions AIF and AGO
Objectives
Sequence symbol : Period followed by 1 to 7 alphabets or digits of which the first is a letter e.g. .Z23Ab
Version 2.0 139
CTS-PAC
Assembler/Session 8
Format: Label
Operation Operand seq. symbol A logical expression enclosed in parenthesis, followed by seq symbol
Objectives
CTS-PAC
Version 2.0
140
A logical expression is composed of one or more relations or values of SETB symbols connected by logical connects AND, OR, AND NOT, OR NOT A relation consists of 2 arithmetic expressions or 2 character expressions connected by a relational operator EQ, NE, LT, LE, GT, GE
CTS-PAC
Version 2.0
141
Assembler/Session 8
e.g.
MACRO PSRCH
Objectives
&PARAMS,&STRING
GBLB &FOUND LCLA &I &FOUND .LP &I &FOUND SETB 0 AIF ((&I GE N&PARAMS) OR &FOUND) .E
.E
CTS-PAC
MEND
Version 2.0
142
Assembler/Session 8
Keywords in DCB parameter: Objectives DSORG PS Physical sequential RECFM F,FA,FB,FBA,V,VBA BLKSIZE Block length LRECL Record Length DDNAME Dataset name in JCL MACRF Macro GM - Get Move GL - Get Locate PM - Put Move PL - Put locate
Move parameter directly puts the record in the storage area specified while Locate mode Loads the address of the record in Register 1
CTS-PAC Version 2.0 143
Assembler/Session 8
Accessing VSAM files: ACB macro AM - VSAM Objectives (For documentation) BUFND - No. of I/O buffers for data control intervals BUFNI - No. of I/O buffers for index control intervals BUFSP - Size of an area for data and Index I/O buffers DDNAME - Filename used in the DD statement. If omitted refers EXLST - Address to the EXLST macro. Generates a list of MACRF - Types of processing the file will do
CTS-PAC
Version 2.0
144
Assembler/Session 8
Objectives
VSAM
EODAD = (Address, A/N, L) (Load module) EXCPAD = (Address, A/N, L) (Load module) JRNAD = (Address, A/N, L) (Load module) LERAD = (Address, A/N, L) (Load module) SYNAD = (Address, A/N, L) (Load module) Active/No, Stored in load module
CTS-PAC Version 2.0 145
Assembler/Session 8
Accessing VSAM files: RPL macro (Request parameter list) ACB - Address of the ACB macro Objectives AREA - Address of the work area to be used AREALEN - Length of the work area (Should be large enough to hold largest record in Move mode and at least 4 bytes in the Locate mode) RECLEN -Length of the records in the file (For VB you have to put the length before writing using MODCB) ARG - Label containing the key for the search (Key for KSDS, RRN for RRDS and RBA for ESDS) OPTCD - 5 sets of groups of parameters
CTS-PAC
Version 2.0
146
Assembler/Session 8
Accessing VSAM files: RPL macro (Continued) Options for OPTCD: Objectives KEY/CNV/ADR - Access by key,Control interval or Relative byte address SEQ/DIR/SKP - Sequential processing,Direct, Skip sequential FWD/BWD - Forward sequential processing,Backward ARD/LRD -Start seq.processing with ARG specified/ Backward processing from the last record NUP/NSP/UPD - No updating(Next rec not ready),No updating Next rec ready(DA only), Record updating) MVE/LOC - Move mode/ Locate mode
CTS-PAC Version 2.0 147
Assembler/Session 8
OPEN - Open theObjectives file CLOSE - Close the file GET - Read a record PUT - Store a record ERASE - Delete a record POINT - Position for access
CTS-PAC
Version 2.0
148
Assembler/Session 9
CTS-PAC
Version 2.0
149
Assembler/Session 8
CTS-PAC
Version 2.0
150
uses DSECTs does not abnormally terminate due to user error provides meaningful error messages
CTS-PAC
Version 2.0
151
Assembler/Session 8
Characteristics of good assembler program Objectives (contd..) lets the assembler determine lengths has opcodes, operand and comments aligned contains meaningful comments uses meaningful labels
CTS-PAC
Version 2.0
152
Assembler/Session 8
Structured Programming
Objectives
Assembler/Session 9
the EX instruction is a R-X type instruction that directs the execution of an instruction called the subject instruction, which is addressed by the second operand the subject instruction is in effect a one-instruction subroutine
Objectives
CTS-PAC
Version 2.0
154
The EXecute Instruction (contd...) The subject instruction is modified before execution (though not altered at its main storage location) : bits 8-15 of the instruction ORed with bits 24-31 of register R1 to form the second byte of the instruction actually executed e.g. Let reg 9 have the length of string to be moved
EX R9,VARMVC VARMVC MVC A(0),B
CTS-PAC Version 2.0 155
Assembler/Session 9
Objectives
Exceptions and Interrupts
DEBUGGING DEBUGGING
Interrupts that result directly from attempts at invalid program execution are called program-check interrupts; identified by a code Interruption code 1 : Operation Interruption code 2 : Privileged operation Interruption code 4 : Protection Interruption code 5 :Addressing Interruption code 6 :Specification CTS-PAC Version 2.0
156
Assembler/Session 9
Objectives
Exceptions and Interrupts (contd..) Interruption code 7 : Data Interruption code 8 : Fixed-Point Overflow Interruption code 9 : Fixed-Point Divide Other Interruption codes ( 3, 10, 11, 12, 13, 14, 15)
CTS-PAC Version 2.0 157
DEBUGGING
Assembler/Session 9
Objectives
Reading dumps
DEBUGGING DEBUGGING
whenever a program abends an indicative dump is generated The completion code is a code furnished by the O/S to designate the reason for the termination of the job step In case of program check interruption, the first 2 digits of the completion code is 0C
CTS-PAC Version 2.0 158
DEBUGGING DEBUGGING
CTS-PAC
Version 2.0
159
Assembler/Session 9
Objectives
Reading dumps (contd...)
DEBUGGING DEBUGGING
The register contents are the contents at the point of interruption (the instruction that caused the interrupt is usually the one just before the interrupt address given) use address at interrupt and entry address to locate the instruction that caused the programcheck interruption
CTS-PAC Version 2.0 160
Assembler/Session 9
Objectives
Full and Partial dumps
DEBUGGING DEBUGGING
CTS-PAC
Version 2.0
161
DEBUGGING DEBUGGING
Reading the dump SAVE AREA trace P/P Storage Examine register contents, PSW and listed entry point to find the portion of program being executed Look at main storage dump to determine the data being used
CTS-PAC Version 2.0 162
Assembler/Session 9
Objectives
DCB - Construct a data control block OPEN - Logically connect a dataset CLOSE - Logically disconnect a dataset GET - Obtain next logical record (queued access) PUT access) Write next logical record (queued
READ - Read a block (basic access) WRITE - Write a block (basic access) CTS-PAC Version 2.0
163
Assembler/Session 9
Objectives
Supervisor Services Macros ABEND - Abnormally terminate a task CALL - Pass control to a control section GETMAIN - Allocate virtual storage FREEMAIN - Free virtual storage LOAD - Bring a load module into virtual storage RETURN - return control to the calling program SAVE - Save register contents
CTS-PAC Version 2.0 164
Assembler/Session 9
Objectives
Supervisor Services Macros (contd) SNAP - Dump virtual storage and continue LINK - Pass control to a Program in Another load module WTO - Write to operator
CTS-PAC
Version 2.0
165
Assembler/Session 9
Objectives
CLOSE
Assembler/Session 9
Objectives
Standard form : Results in instructions that store into an inline parameter list and pass control to the required program List form : Provides as out-of-line parameter list Execute form : Provides the executable instructions required to modify the out-of-line parameter list and pass control to the required program
CTS-PAC
Version 2.0
167
you ank Th
CTS-PAC
Version 2.0
168