Download - 7300697-assember-Sessio 1-ppt
-
8/13/2019 7300697-assember-Sessio 1-ppt
1/141
ASM Version 1.0ASM Version 1.0 11
Assembler/Session 1
Course Title :
ASSEMBLER
LANGUAGEDuration : 5 Half - DAYS
Course Title ::
ASSEMBLERASSEMBLER
LANGUAGELANGUAGEDurationDuration :: 5 Half5 Half -- DAYSDAYS
-
8/13/2019 7300697-assember-Sessio 1-ppt
2/141
Assembler/Session 1
Course Title :
SSEMBLER L NGU GEDuration : 5 Half - DAYS
-
8/13/2019 7300697-assember-Sessio 1-ppt
3/141
Objectives
Objectives
Familiarise with IBM 370 Assembly Language
Assembler/Session 1
-
8/13/2019 7300697-assember-Sessio 1-ppt
4/141
SESSION 1
Day 1Introduction
SESSION 2
Day 1
Addressing
SESSION 3
Day 2 Machine Instructions
Assembler/Session 1
COURSE SCHEDULE
-
8/13/2019 7300697-assember-Sessio 1-ppt
5/141
-
8/13/2019 7300697-assember-Sessio 1-ppt
6/141
Macro LanguageSESSION 8
Day 4
Other TopicsSESSION 9
Day 5
Assembler/Session 1
COURSE SCHEDULE
-
8/13/2019 7300697-assember-Sessio 1-ppt
7/141
Assembler Language
SESSION 1
Assembler/Session 1
-
8/13/2019 7300697-assember-Sessio 1-ppt
8/141
ObjectivesINTRODUCTION
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
Assembler/Session 1
-
8/13/2019 7300697-assember-Sessio 1-ppt
9/141
ObjectivesSTATEMENT FORMAT
1 10 16 30label operation operands comments
e.g..
INIT1 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
Assembler/Session 1
-
8/13/2019 7300697-assember-Sessio 1-ppt
10/141
ObjectivesSTATEMENT FORMAT
Operation
One of the 200 M/C instruction mnemonics
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
Assembler/Session 1
-
8/13/2019 7300697-assember-Sessio 1-ppt
11/141
ObjectivesSTATEMENT FORMAT
Comment Statement
* in column 1
Any text in columns 2 - 71
Note : Fields separated by one or moreblanks
Assembler/Session 1
-
8/13/2019 7300697-assember-Sessio 1-ppt
12/141
ObjectivesTYPES OF INSTRUCTIONS
1. Machine Instructions
2. Assembler Instructions (Directives)
3. Macro Instructions
Assembler/Session 1
-
8/13/2019 7300697-assember-Sessio 1-ppt
13/141
ObjectivesREGISTERS
Registers are storage areas inside the processor
Advantages:
- No need to retrieve data from main storage
(saves time)
- Shared resource that allows intercommunication between programs
Assembler/Session 1
-
8/13/2019 7300697-assember-Sessio 1-ppt
14/141
ObjectivesREGISTERS
General purpose registers:
* 16 registers available
* Numbered 0 - 15
* Holds 32 bits (4 bytes) of data
F loating 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
Assembler/Session 1
-
8/13/2019 7300697-assember-Sessio 1-ppt
15/141
ObjectivesDATA REPRESENTATION
Binary fields
-Always fixed in length, either 2 or 4 bytes
(Fullword or Halfword)
- Negative numbers stored in 2s complement form
Examples:
A DC H295 01 27
B DC H-75 FF 35
Assembler/Session 1
-
8/13/2019 7300697-assember-Sessio 1-ppt
16/141
ObjectivesDATA REPRESENTATION
Characters
- One byte (EBCDIC form)
- Character representation of decimal digits is called
Zoned Decimal (first nibble is zone and next is digit)
Zone digit Zone Code
0 - 9 + C- D
+, - , blank Blank F
Assembler/Session 1
-
8/13/2019 7300697-assember-Sessio 1-ppt
17/141
ObjectivesDATA REPRESENTATION
F loating Point Numbers
- Always fixed in length, 4, 8 or 16 bytes
(Full word, double word, double double word)
- Left most bit represents sign
(0 - positive; 1 - negative)
- Next 7 bits represent exponent
- Remaining bytes represent the fraction
Assembler/Session 1
-
8/13/2019 7300697-assember-Sessio 1-ppt
18/141
ObjectivesDATA REPRESENTATION
Decimal numbers ( Packed Decimal representation)
- Each byte but the rightmost has 2 decimal digits (0-9)
- The right most byte contains a digit in the left half anda sign indicator in the right
Sign indicator: C- Positive
D - Negative
Example: 753 - 7 5 3 C
Assembler/Session 1
A bl /S i 1
-
8/13/2019 7300697-assember-Sessio 1-ppt
19/141
ObjectivesAddressing Operands
Register addressing
Base, displacement addressing
Base, index and displacement addressing
Assembler/Session 1
A bl /S i 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
20/141
ObjectivesI NSTRUCTION FORMATS
RR opcode R1 R2
SI opcode I2 B1 D1
SS opcode L B1 D1 B2 D2
SS opcode L1 L2 B1 D1 B2 D2
RX opcode R1 X2 B2 D2
RS opcode R1 R3 B2 D2
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
21/141
Assembler Language
SESSION 2
Addressing
Assembler/Session 2
A bl /S i 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
22/141
ObjectivesSTORAGE DEFINITIONS
Two ways to define fields :
1. Define a field and initialise the data in it usingthe DCassembler directive
2. Define a field without initialising using the DSassembler directive
Assembler/Session 2
A bl /S i 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
23/141
ObjectivesSTORAGE DEFINITIONS
Format:
label {DS/DC} dtLnvalue
where :label : Label used to name the field (optional)
d : Duplication factor (optional)
t : Type of data ( required)
Ln : The letter L followed by the length of the field in
bytes (optional)
value : Represents the value enclosed in apostrophes
Assembler/Session 2
A bl /S i 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
24/141
ObjectivesSTORAGE DEFINITIONS
Examples:
ALPHA DC CABC EF
FLDS DS 3CL2
H1 DC H29
F2 DC F-10
F1 DC X03
F3 DC PL4-72
Note : for character constants truncation or padding is to
the right and for almost all others it is to the left.
Assembler/Session 2
A bl /S i 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
25/141
ObjectivesSTORAGE DEFINITIONS
DC TYPESType Implied Alignment Data Representation
Length
C - None Character
X - None Hex digitsB - None Binary digits
F 4 Full word Binary
H 2 Half word Binary
E 4 Full word Floating point
D 8 Double word Floating point
L 16 Double word Floating point
P - None Packed decimal
Assembler/Session 2
Assembler/Session 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
26/141
ObjectivesSTORAGE DEFINITIONS
Data Representation in other languages:
Assembler FORTRAN COBOL PASCAL BASIC
Language
DC Type
C Character Display String StringF, H Integer COMP Integer Integer
E Real COMP-1 Real Single
precision
D Double COMP-2 Real DoublePrecision Precision
X, B Logical N/A Boolean Hex
P N/A COMP-3 N/A N/A
Assembler/Session 2
Assembler/Session 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
27/141
ObjectivesSTORAGE DEFINITIONS
Literals
A literal is a constant preceded by an equals sign =.
Can be used as a main-storage operand but not as adestination field of an instruction
Causes assembler to define a field that is initialised with
the data specified
All constants defined by literals are put by the assembler
in a literal pool, usually at the very end of the program
L R4,=F1
Assembler/Session 2
Assembler/Session 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
28/141
ObjectivesExercise 1 Q 1 and Q2.
2.What will happen in the following cases
DC CL5123
DC CL5123456
DC XA1245
DC XL2A1245
DC XL5A1245DC F19
DC FL1513
Assembler/Session 2
Assembler/Session 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
29/141
ObjectivesEQU (Assembler directive)
The EQU statement is used to associate a
fixed value with a symbol
R4 EQU 4
DRBACK EQU OUT+25
Assembler/Session 2
Assembler/Session 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
30/141
ObjectivesESTABLISHING ADDRESSABILITY
By establishing the addressability of a
coding section, you can refer to the
symbolic addresses defined in it in theoperands of machine instruction
Assembler will convert the implicit
addresses into explicit addresses(base - displacement form)
Assembler/Session 2
Assembler/Session 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
31/141
ObjectivesESTABLISHING ADDRESSABILITY
To establish the address of a coding section :
Specify a base address from which the
assembler can compute displacements
Assign a base register to contain this baseaddress
Write the instruction that loads the base
register with the base address
Note: The base address should remain in the baseregister throughout the execution of the program
Assembler/Session 2
Assembler/Session 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
32/141
ObjectivesESTABLISHING ADDRESSABILITY
Establishing Base Register
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
Assembler/Session 2
Assembler/Session 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
33/141
ObjectivesESTABLISHING ADDRESSABILITY
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
Assembler/Session 2
Assembler/Session 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
34/141
ObjectivesESTABLISHING ADDRESSABILITY
Range of a USING instruction:
The range of a USING instruction is the 4096
bytes beginning at the base address specified in
the USING instructionDomain 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
Assembler/Session 2
Assembler/Session 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
35/141
ObjectivesESTABLISHING ADDRESSABILITY
The assembler converts implicit address references into theirexplicit form:
if the address reference appears in the domain of a
USING instruction
if the addresses referred to lie within the range of thesame USING instruction
Guideline:
Specify all USING instructions at the beginning of thesource module
Specify a base address in each USING instruction that lies
at the beginning of each control section
Assembler/Session 2
Assembler/Session 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
36/141
ObjectivesRELATIVE ADDRESSING
Relative addressing is the technique of addressinginstructions and data areas by designating their location
in relation to the location counter or to some symbolic
location
ALPHA LR 3,4
CR 4,6 ALPHA+2 or BETA-4
BCR 1,14
BETA AR 2,3
Note : Always avoid using relative addressing
Assembler/Session 2
-
8/13/2019 7300697-assember-Sessio 1-ppt
37/141
Assembler Language
SESSION 3 & 4
Machine Instructions
Assembler/Session 3 & 4
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
38/141
ObjectivesHANDLING CHARACTER DATA
Move Character Instruction (MVC)
Copy data from one place in memory to another
Format: MVC operand1,operand2
S1(L), S2 - implicit
D1(L,B1),D2(B2) - explicit
e.g...
MVC INPUT(5),OUTPUT
Assembler/Session 3 & 4
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
39/141
ObjectivesHANDLING CHARACTER DATA
Move Immediate Instruction (MVI)
Can move only one byte of constant data to a field
Format: MVI operand1,operand2
S1,I2 - implicit
D1(B1),I2 - explicit
e.g..
MVI CTL,CB
DBSS TRAINING CENTRE
Assembler/Session 3 & 4
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
40/141
ObjectivesHANDLING CHARACTER DATA
Advanced Techniques
1. Explicit lengths and relative addressing
MVC PAD+6(4),=CL4
PAD DS CL10
2. Overlapping fields and the MVC instruction
MVC FLDB,FLDA
FLDS DC CA
FLDB DS CL3
Assembler/Session 3 & 4
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
41/141
ObjectivesHANDLING CHARACTER DATA
Comparison Instructions
Compares 2 values - the values are found in fields, in
registers or in immediate data
CLC - Compare logical charactere.g. CLC FLDA,FLDB
CLI - Compare logical immediate
e.g. CLI FLDA,CK
Assembler/Session 3 & 4
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
42/141
ObjectivesExercise 2 Q1 and Q2
2. What will be the effect of the following instructions :
MVI OUTAREA,C
MVC OUTAREA+1(132),OUTAREA
OUTAREA DS 133C
sse b e /Sess o 3 &
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
43/141
ObjectivesBINARY INSTRUCTIONS
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 5,FULL LR 5,7
STH 7,HALF
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
44/141
ObjectivesBINARY INSTRUCTIONS
Note : Do not mix up the instruction types and field types
e.g.
LH 5,FULL - right half of Reg 5 gets 1st 2 bytes at FULL
L 6,HALF - Reg 6 gets 4 bytes starting from HALF
ST 3,RES - 4 bytes of reg 3 are stored starting from RES
RES DS H
HALF DC H15
FULL DC F8
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
45/141
ObjectivesBINARY INSTRUCTIONS
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 5,FULL
AH 6,HALF
AR 7,3
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
46/141
ObjectivesBINARY INSTRUCTIONS
Binary Subtraction (S, SH and SR)
Type R-X
e.g.
S 5,FULL
SH 6,HALF
SR 7,3
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
47/141
ObjectivesBINARY INSTRUCTIONS
Binary comparisons (C, CH and CR)
e.g.
C 5,FULL
CH 6,HALF
CR 7,3
Condition code set as HIGH, LOWor EQUAL
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
48/141
ObjectivesBinary Multiplication (M, MR, MH)
Format : M op1,op2
op1 : An even numbered register; refers to an even-odd
pair of registers(any register in case of halfword format)
op2 : storage area (fullword/halfword/register)
-
8/13/2019 7300697-assember-Sessio 1-ppt
49/141
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 theresult 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.)
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
50/141
ObjectivesBINARY INSTRUCTIONS
Binary Division (D, DR)
Format: D op1,op2
Type : R-X / R-R
Op1 : An even numbered register. It refers to an even-odd pairof 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
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
51/141
ObjectivesBRANCHING
A branch causes execution to continue at some
other instruction in the program
Branch conditions : B, BH, BL, BE, BNH, BNL,
BNE, BZ, BNZ, BM, BNM, BO, BNO
e.g : CLI FLDA,CK
BNL GOOD
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
52/141
ObjectivesCONDITION CODE PROCESSING
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
0 Zero
1 < Zero
2 >Zero
3 Overflow
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
53/141
ObjectivesBC and BCR Instructions
instructions that do or do not branch depending onthe value of the condition code
Format : BC M1,S2
BCR M1,R2
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.
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
54/141
ObjectivesBIT MANIPULATIONS
Operation S-I S-S R-R R-X
OR OI OC OR O
AND NI NC NR N
Exclusive OR XI XC XR X
e.g... OI FLDA,X0F
NR 5,7
X 9,FULL
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
55/141
ObjectivesBIT MANIPULATIONS
Testing individual bits - Test under mask (TM)
TM S1,I2
Function : The bits of S1 ( a single byte) are testedunder the control of the mask in I2 and condition
code is set as all zeroes, all ones or mixed
e.g. TM EMP,B00000101BNM NEXT
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
56/141
ObjectivesBIT MANIPULATIONS
Bit Shifting Instructions
SLL, SLDL Left logical
SRL, SRDL Right logical
SLA, SLDA Left arithmetic (sign bit not affected)
SRA, SRDA Right arithmetic(& condition code set)
e.g. SLL 5,1
SRDA 4,5
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
57/141
ObjectivesBIT MANIPULATIONS
Translations
To translate from one bit combination to another
Format: TR S1(L),S2 or S1,S2
S1 : The field whose data is to be translated
S2 : A 256-byte translation table
Function : The value of the original byte is used as adisplacement into the translation table. The byte found there
replaces the original byte.
e.g. TR WORK,XTABLE
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
58/141
ObjectivesBINARY CONVERSIONS
1. Conversion to binary (CVB)
Format: CVB operand1,operand2
operand1 : Register
operand2 : a double word (containing
valid packed decimal number)
e.g. CVB 5,DOUBLE
Use : character data -(PACK)->packed decimal-(CVB)->binary
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
59/141
ObjectivesBINARY CONVERSIONS
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
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
60/141
ObjectivesTABLE PROCESSING
A table is a named storage structure consisting ofsubunits or entries
e.g. RATE DS 6F
L 4,RATE+8
Accessing table elements with indexed storage
operands:
e.g. LH 9,=H2
L 5,RATE(9) (9 - index register)
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
61/141
ObjectivesMulti-purpose branching instructions
Convenient when counted repetition structure (table processing) is
needed
Branch on count (BCT and BCTR)
Format: BCT op1,op2 (R-X)
Function: First the op1 value is decremented by 1. Second thebranch is taken to the address specified in op2 only if the value in op1
is not 0.
e.g. LH 9,=H12
REPEAT EQU *
..
BCT 9,REPEAT
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
62/141
Objectives Branch on index high and branch on index low or equal (BXH
and BXLE)
Format: BXLE op1,op2,op3
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 addres.
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
63/141
ObjectivesFunction : First, the value in the increment
register is added to the indexed register. Second,
the branch is taken only when the value in the
index register is lower than or equal to / higher
thanthe value in the limit register
Useful when the same register is to be used as the
count and index register
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
64/141
ObjectivesBXLE - DO UNTIL repetitions
BXH - DO WHILE repetitionse.g... LH 7,=H0 index
LH 2,=H2 increment amount
LH 3,=H18 the limit
---
REPEAT ...
LH 6,TABLE(7)
...
BXLE 7,2,REPEAT
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
65/141
ObjectivesLoad instructions with additional features
Load and Test (LTR)
e.g... LTR 15,15
BNZ ERROR
Load Address (LA)
LA R1,D2(X2,B2)
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
66/141
ObjectivesUSING EQUATES
To associate a fixed value with a symbol
Useful for length and relative address calculation
e.g. TABLE DS 0H
DC C01
DC C02
...
TBLEND EQU *
TBLSIZE EQU TBLEND-TABLE
Assembler/Session 3 & 4
-
8/13/2019 7300697-assember-Sessio 1-ppt
67/141
ObjectivesUSING EQUATES
Can be used for the following purposes:
1. To assign single absolute values to symbols.
2. To assign the values of previously defined
symbols or expressions to new symbols, thusallowing you to use different mnemonics for
different purposes.
3. To compute expressions whose values areunknown at coding time or difficult to calculate.
The value of the expressions is then assigned to a
symbol.
Assembler/Session 5
-
8/13/2019 7300697-assember-Sessio 1-ppt
68/141
Assembler Language
SESSION 5
Program Sectioning
Assembler/Session 5
Assembler/Session 5
-
8/13/2019 7300697-assember-Sessio 1-ppt
69/141
ObjectivesBeginning and End of Source Modules
Code a CSECT segment before any
statement that affects the location
counter
END statement is required as the last
statement in the assembly
Assembler/Session 5
-
8/13/2019 7300697-assember-Sessio 1-ppt
70/141
ObjectivesCONTROL SECTIONS
A source module can be divided intoone or more control sections
A control section is the smallestsubdivision of a program that can be
relocated as a unit
-
8/13/2019 7300697-assember-Sessio 1-ppt
71/141
At coding time, establish the addressabilityof each control section within the source
module, and provide any symbolic linkages
between control sections that lie in differentsource modules.
Initiated by using the START or CSECT
instruction
CONTROL SECTIONS
Assembler/Session 5
-
8/13/2019 7300697-assember-Sessio 1-ppt
72/141
ObjectivesCONTROL SECTIONS
Any instruction that affects the locationcounter, or uses its current value,
establishes the beginning of the first
control section.
-
8/13/2019 7300697-assember-Sessio 1-ppt
73/141
Format of CSECT:
Name Operation Operand
Any symbol CSECT Not required
or blank
Note: The end of a control section or portion of acontrol section is marked by (a) any instruction that
defines a new or continued control section, or (b) the
END instruction.
CONTROL SECTIONS
Assembler/Session 5
-
8/13/2019 7300697-assember-Sessio 1-ppt
74/141
ObjectivesDUMMY SECTIONS
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.
-
8/13/2019 7300697-assember-Sessio 1-ppt
75/141
Use the DSECT instruction to initiate a
dummy control section or to indicate its
continuation.
Format of DSECT:
Name Operation Operand
Any symbol DSECT Not required
or blank
DUMMY SECTIONS
Assembler/Session 5
-
8/13/2019 7300697-assember-Sessio 1-ppt
76/141
ObjectivesDUMMY SECTIONS
To use a dummy section :
Reserve a storage area for the
unformatted data Ensure that this data is loaded into the area
at execution time
-
8/13/2019 7300697-assember-Sessio 1-ppt
77/141
Ensure that the locations of the symbols inthe 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 datasymbolically by using the symbols defined in the
dummy section.
DUMMY SECTIONS
Assembler/Session 5
-
8/13/2019 7300697-assember-Sessio 1-ppt
78/141
ObjectivesASMBLY2 CSECT
BEGIN BALR 2,0
USING *,2
... Reg 3 points to dataarea
USING INAREA,3
CLI INCODE,C'A'
BE ATYPE
...ATYPE MVC WORKA,INPUTA
MVC WORKB,INPUTB
. .
-
8/13/2019 7300697-assember-Sessio 1-ppt
79/141
WORKA DS CL20WORKB DS CL18
...
INAREA DSECT
INCODE DS CL1
INPUTA DS CL20
INPUTB DS CL18
...
END
A i i
Assembler/Session 5
-
8/13/2019 7300697-assember-Sessio 1-ppt
80/141
ObjectivesAssembler Directives
TITLE : To provide headings for each page ofthe assembly listing of the source modules.
EJECT : To stop the printing of the assemblerlisting on the current page, and continue the
printing on the next page.
ORG : To reset the location counter
A bl Di i
-
8/13/2019 7300697-assember-Sessio 1-ppt
81/141
LTORG: A literal pool is createdimmediately after a LTORG instruction or,
if no LTORG instruction is specified, at the
end of the first control section.
PRINT : Tocontrol the amount of detail to
be printed in the listing of programs.PRINT NOGEN / GEN
Assembler Directives
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
82/141
Assembler Language
SESSION 6
Writing a complete program
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
83/141
ObjectivesProgram Entry and Exit Logic
Program entry - Preserve register contents
Program Exit - Restore register contents
Register save areaAlways calling program provides a savearea of
18 words long used for storage of registers
Savearea address passed through register 13
A i
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
84/141
ObjectivesA register save area
Word Address Contents
1 SAV
2 SAV+4 Address of calling programs save area
3 SAV+8 Address of called programs save area
4 SAV+12 Contents of Register 14
5 SAV+16 Contents of Register 15
6 SAV+20 Contents of Register 0
...
18 SAV+68 Contents of Register 12
R ibili i f ll d
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
85/141
ObjectivesResponsibilities of called program
Program entry conventions1.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
P t ti ( td )
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
86/141
ObjectivesProgram entry conventions (contd..)
4. Store the address of its register savearea in thethird 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 inreading the dump when program crashes).
R ibiliti f ll d ( td )
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
87/141
ObjectivesResponsibilities of called program (contd..)
Program Entry
STM R14,R12,12(R13)
BALR R12,0
USING *,R12
ST R13,SAVOWN+4 store calling programs save area
LR R14,R13
LA R13,SAVOWN Reg 13 contains current progs SA...
ST R13,8(R14)
R ibiliti f ll d ( td )
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
88/141
ObjectivesResponsibilities of called program (contd..)
Program Exit conventions1. Restore registers 0-12 and 14
2. Place the address of the save area provided by thecalling program in Reg 13
3. Place a return code in the low order byte of
register 15 if one is required. Otherwise restoreregister 15.
R ibiliti f ll d ( td )
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
89/141
ObjectivesResponsibilities of called program (contd..)
Program Exit
L R13,4(R13)
LM R14,R12,12(R13)
BR R4
Responsibilities of calling program
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
90/141
ObjectivesResponsibilities of calling program
1. Register 13 must contain the address of a register
save area.
2. Register 15 should be set to the beginning address
of the subroutine
L R15,=V(SUBENTRY)
where SUBENTRY is the entry address (usually the CSECT
name) of the subroutine
Responsibilities of calling program (contd )
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
91/141
ObjectivesResponsibilities of calling program (contd...)
3. Register 14 should have the return address
4. Register 1 sould 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
Passing parameters to a subroutine
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
92/141
ObjectivesPassing parameters to a subroutine
The standard interface requires that addresses of
parameters be placed in a block of storage, and theaddress of the block be loaded into register 1 as the
subroutine is called
Both input and output parameters are treated the sameway
e.g... ADDS DC A(T)
DC A(U)
DC A(V)
LA R1,ADDS
R1 M i t
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
93/141
ObjectivesR1 Main storage
Addr of parmlist Parmlist parm3
Addr of parm1
Addr of parm2 parm1
Addr of parm3 parm2
C ll d b i B h d
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
94/141
ObjectivesCalled subroutine B may get the second parameter
by
L R3,4(,R1)
L R8,0(,R3)
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
95/141
Objectives
Registers with special useR0 : Contains single word output of a
subroutine
R1 : contains the address of an area of
main storage that contains addresses of
parameters
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
96/141
Objectives
Registers with special use (contd...)R14 : Contains the return address, the address
in the calling routine to which a subroutine
should return control when finished
R15 : contains the address of the entry point in
the subroutine
R13 : contains the address of an area in which
register contents can be stored by a subroutine
The subroutine RANDOM
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
97/141
ObjectivesThe subroutine RANDOM
RANDOM STM RR14,R12,12(R13)
BALR R12,0
USING *,R12
L R7,RN
M R6,=F65541
ST R7,RN
LR R0,R7
LM R1,R12,24(R13)
BR R14
RN DC F8193
Subroutine RDIGIT
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
98/141
ObjectivesRDIGIT STM R14,R12,12(R13)BALR R12,0
USING *,R12
ST R13,SAV+4
LA R13,SAV
...
L R15,RANDADBALR R14,R15
...
L R13,SAV+4
LM R14,R15,12(R13)
LM R1,R12,24(R13)
BR R14
SAV DS 18F
RANDAD DC A(RANDOM)
Linkage Conventions
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
99/141
ObjectivesLinkage Conventions
Program divided into 2 or more sourcemodules
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
C i ti b t t
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
100/141
ObjectivesCommunicating between program parts
To communicate between 2 or more sourcemodules, symbolically link them together
To communicate between 2 or more control
sections within a source module, establish proper
addressability
Establishing symbolic linkage
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
101/141
ObjectivesEstablishing symbolic linkage
Identify external symbols in the EXTRN or WXTRN
instruction or the V-type address constant
provide A-type or V-type address constants to reserve
storage for addresses represented by external symbols
In the external source modules, identify these symbols
with the ENTRY instruction
(name entry of a START or CSECT instruction is
automatically identified as an entry symbol)
External symbol dictionary
Establishing symbolic linkage (contd...)Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
102/141
Objectivesg y g ( )
e.g. program A
EXTRN TABLEB
WXTRN TABLEB
TABADR DS V(TABLEB)
program B
ENTRY TABLEB
TABLEB DS ...
Add C t t (A d V)
Assembler/Session 6
-
8/13/2019 7300697-assember-Sessio 1-ppt
103/141
ObjectivesAddress Constants (A and V)
An address constant is a main storage address containedin 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 L 5,ADCON
ADCON DC A(SOMWHERE)
GSUBAD DC V(READATA)
Assembler/Session 7
-
8/13/2019 7300697-assember-Sessio 1-ppt
104/141
Assembler Language
SESSION 7
Assemble and Link Program
Processing of Instructions
Assembler/Session 7
-
8/13/2019 7300697-assember-Sessio 1-ppt
105/141
ObjectivesProcessing of Instructions
Time/ M/C Assembler ENTRY Macro
Activity instruc. EXTRN Instr.
Code source m/c DC,DS
instruc.
Preassembly Refer to macro
instruc.
Assembly object code
LKED
Prog fetch
Execution data area form data
area in load mod
JCL parm processing
Assembler/Session 7
-
8/13/2019 7300697-assember-Sessio 1-ppt
106/141
ObjectivesJCL parm processing
EXEC PGM=pgmname,PARM=
When program gets control :
Register 1 contains the address of a fullwordon a fullword boundary in programs address
space
the high order bit of this fullword is set to 1
(this convention is to indicate the last word in a
variable length parameter list)
-
8/13/2019 7300697-assember-Sessio 1-ppt
107/141
JCL parm processing ...
Bits 1-31 of the fullword contain theaddress of a 2-byte length field on a
halfword boundary
The length field contains a binary countof the no. of bytes in the PARM field
which immediately follows the length
field
COBOL to Assembler
Assembler/Session 7
-
8/13/2019 7300697-assember-Sessio 1-ppt
108/141
ObjectivesCALL asmpgm USING COMM-AREA
PL/I to Assembler
DCL ASMSUB ENTRY OPTIONS(ASSEMBLER)
CHARSTRING CHAR(25);
CALL ASMSUB(CHARSTRING);
Ref : PL/I Programming Guide, COBOL programming
Guide
Assembler/Session 8
-
8/13/2019 7300697-assember-Sessio 1-ppt
109/141
Assembler Language
SESSION 8
Macro Language
Assembler/Session 8
-
8/13/2019 7300697-assember-Sessio 1-ppt
110/141
ObjectivesMacros
Short source routines written and
stored in libraries
Assembler inserts the source
statements in the program where
the macro appears
-
8/13/2019 7300697-assember-Sessio 1-ppt
111/141
Macro Definition
Format :
A header statement
A prototype
Model statements
A trailer statement
Header statement:
Assembler/Session 8
-
8/13/2019 7300697-assember-Sessio 1-ppt
112/141
ObjectivesHeader statement:
MACRO
Prototype:
&name MOVE &TO,&FROM,&LENGTH
Model statements:
A set of machine and assembler instructions
Trailer statement:
&name MEND
Macro Instruction:Assembler/Session 8
-
8/13/2019 7300697-assember-Sessio 1-ppt
113/141
Objectives
A statement containing the name of amacro
when expanded, the symbolic parameters in
the model statements are replaced bycorresponding parameters from the macro
instructions
symbolic prarameters may be positional or
keyword
Macro Instruction ...
-
8/13/2019 7300697-assember-Sessio 1-ppt
114/141
MACRO
&LABEL HALFSWAP ®,&SV
&LABEL ST ®,&SV
SLL ®,8
IC ®,&SV
SLL ®,8
IC ®,&SV+1
MEND
SET Symbols (global or local)
Assembler/Session 8
-
8/13/2019 7300697-assember-Sessio 1-ppt
115/141
ObjectivesSET Symbols (global or local)
3 types :
arithmetic (SETS)
binary (SETB)
character (SETC)
SET symbols are declared using,
LCLA LCLB LCLC
GCLA GCLB GCLC
Format:Assembler/Session 8
-
8/13/2019 7300697-assember-Sessio 1-ppt
116/141
ObjectivesLabel operation operands
symbol-name SETA An expression
SETB
SETC
e.g.
LCLA &A1
GCLA &A2
&A1 SETA 1
&A2 SETA &A1+3
Attributes
Assembler/Session 8
-
8/13/2019 7300697-assember-Sessio 1-ppt
117/141
ObjectivesAttributes
There are 6 attributes of a symbol orsymbolic parameter :
type, length, scaling, integer, count and
number
System variable symbols
&SYSINDX, &SYSDATE, &SYSTIME, &SYSECT,
&SYSPARM, &SYSLOC
Conditional Assembly
Assembler/Session 8
-
8/13/2019 7300697-assember-Sessio 1-ppt
118/141
ObjectivesConditional Assembly
The assembler can be made to branch and loopamong assembler language statements using
sequence symbols and the assembler
instructions AIFand AGO
Sequence symbol : Period followed by 1 to 7
alphabets or digits of which the first is a letter
e.g. .Z23Ab
Format:
Assembler/Session 8
-
8/13/2019 7300697-assember-Sessio 1-ppt
119/141
ObjectivesFormat:
Label Operation Operandseq symbo AGO seq. symbol
or blank
-do- AIF A logical expression
enclosed in parenthesis,
followed by seq symbol
-
8/13/2019 7300697-assember-Sessio 1-ppt
120/141
A logical expression is composed of one ormore 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
Obj ie.g.
Assembler/Session 8
-
8/13/2019 7300697-assember-Sessio 1-ppt
121/141
ObjectivesMACROPSRCH &PARAMS,&STRING
GBLB &FOUND
LCLA &I
&FOUND SETB 0
.LP AIF ((&I GE N&PARAMS) OR &FOUND) .E
&I SETA &I+1
&FOUND SETB (&PARAMS(&I) EQ &STRING)
AGO .LP
.E MEND
Assembler/Session 9
-
8/13/2019 7300697-assember-Sessio 1-ppt
122/141
Assembler Language
SESSION 9
Other Topics
Obj i
Assembler/Session 8
-
8/13/2019 7300697-assember-Sessio 1-ppt
123/141
ObjectivesCharacteristics of good assembler program
has simple, easy to understand logic
uses mostly simple instructions
has no relative addressing
uses subroutines
Ch t i ti f d bl
-
8/13/2019 7300697-assember-Sessio 1-ppt
124/141
Characteristics of good assembler program ...
uses DSECTs
has efficient code (LA R10, 4(0,R10 - A R10,=F4)
does not abnormally terminate due to user error
requests and check feedback from macro instruction
provides meaningful error messages
Obj iCharacteristics of good assembler program
Assembler/Session 8
-
8/13/2019 7300697-assember-Sessio 1-ppt
125/141
ObjectivesCharacteristics of good assembler program
(contd..)
lets the assembler determine lengths
has opcodes, operand and comments aligned
contains meaningful comments
uses meaningful labels
Obj tiStructured Programming
Assembler/Session 8
-
8/13/2019 7300697-assember-Sessio 1-ppt
126/141
Objectivesg g
To improve design and understandability of aprogram
made up of building blocks of subroutines
Conventions for general purpose registers
Base registers
Link registers
Obj tiThe EXecute Instruction
Assembler/Session 9
-
8/13/2019 7300697-assember-Sessio 1-ppt
127/141
Objectives
the EX instruction is a R-X type instruction thatdirects 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
The EXecute Instruction (contd...)
-
8/13/2019 7300697-assember-Sessio 1-ppt
128/141
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 instructionactually executed
e.g. Let reg 9 have the length of string to be moved
EX R9,VARMVC
VARMVC MVC A(0),B
The EXecute Instruction (contd...)
Obj ti
DEBUGGING
Assembler/Session 9
-
8/13/2019 7300697-assember-Sessio 1-ppt
129/141
Objectives
Exceptions and InterruptsInterrupts 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
Obj ti
DEBUGGING
Assembler/Session 9
-
8/13/2019 7300697-assember-Sessio 1-ppt
130/141
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)
Obj ti
DEBUGGING
Assembler/Session 9
-
8/13/2019 7300697-assember-Sessio 1-ppt
131/141
Objectives
Reading dumps
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
DEBUGGING
-
8/13/2019 7300697-assember-Sessio 1-ppt
132/141
Locate the entry point of your program
Reading dumps ...
Obj ti
DEBUGGING
Assembler/Session 9
-
8/13/2019 7300697-assember-Sessio 1-ppt
133/141
Objectives
Reading dumps (contd...)
The register contents are the contents at the
point of interruption (the instruction that
caused the interrupt is usually the one justbefore the interrupt address given)
use address at interrupt and entry address to
locate the instruction that caused the program-check interruption
Obj ti
DEBUGGING
Assembler/Session 9
-
8/13/2019 7300697-assember-Sessio 1-ppt
134/141
Objectives
Full and Partial dumps
//SYSUDUMP DD SYSOUT=A
SNAP macro
DEBUGGING
-
8/13/2019 7300697-assember-Sessio 1-ppt
135/141
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 databeing used
Objectives
SYSTEM MACROS
Assembler/Session 9
-
8/13/2019 7300697-assember-Sessio 1-ppt
136/141
ObjectivesData Management Macros
DCB - Construct a data control block
OPEN - Logically connect a dataset
CLOSE - Logically disconnect a dataset
GET - Obtain next logical record (queued access)
PUT - Write next logical record (queued
access)
READ - Read a block (basic access)
WRITE - Write a block (basic access)
Objectives
SYSTEM MACROS
Assembler/Session 9
-
8/13/2019 7300697-assember-Sessio 1-ppt
137/141
Objectives
Supervisor Services MacrosABEND - 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 storageRETURN - return control to the calling program
SAVE - Save register contents
Objectives
SYSTEM MACROS
Assembler/Session 9
-
8/13/2019 7300697-assember-Sessio 1-ppt
138/141
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
Objectives
SYSTEM MACROS
Assembler/Session 9
-
8/13/2019 7300697-assember-Sessio 1-ppt
139/141
Objectivese.g. File I/O
OPEN (INFILE,INPUT)
GET INFILE,RECAREA
PUT OUTFILE,RECAREA
CLOSE (INFILE)
INFILE DCB
DSORG=PS,MACRF=GM,DDNAME=IFILE
OUTFILE DCB
DSORG=PS,MACRF=PM,DDNAME=OFILE
(RECFM=,LRECL=,BLKSIZE=,)
Objectives
SYSTEM MACROSAssembler/Session 9
-
8/13/2019 7300697-assember-Sessio 1-ppt
140/141
ObjectivesThree forms :
Standard form : Results in instructions that store
into an inline parameter list and pass control to the
required program
List form : Provides asn 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
-
8/13/2019 7300697-assember-Sessio 1-ppt
141/141