Professional Documents
Culture Documents
Assemblerppt
Assemblerppt
Course
Course Title
Title ::
ASSEMBLER
ASSEMBLER
LANGUAGE
LANGUAGE
Duration
Duration :: 55 Half
Half -- DAYS
DAYS
SESSION 1 Introduction
Day 1
SESSION 2 Addressing
Day 1
SESSION 3
Day 2 Machine Instructions
COURSE SCHEDULE
Assembler Language
SESSION 1
STATEMENT
STATEMENT FORMAT
FORMAT
Objectives
1 10 16 30
label operation operands comments
e.g..
INIT1 LA R5,4 ;INITIALISE REGISTER 5
L 2,A
A 2,B
ST 2,ANS
…..
…..
A DC F’15’
B DC F’20’
ANS DS F
STATEMENT
STATEMENT FORMAT
FORMAT
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
STATEMENT
STATEMENT FORMAT
FORMAT
Objectives
Comment Statement
• * in column 1
• Any text in columns 2 - 71
TYPES
TYPES OF
OF INSTRUCTIONS
INSTRUCTIONS
Objectives
1. Machine Instructions
3. Macro Instructions
REGISTERS
REGISTERS
Objectives
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
REGISTERS
REGISTERS
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
Assembler/Session 1
DATA
DATA REPRESENTATION
REPRESENTATION
Objectives
Binary fields
- Always fixed in length, either 2 or 4 bytes
(Full word or Half word)
- Negative numbers stored in 2’s complement form
Examples:
A DC H’295’ 01 27
B DC H’-75’ FF 35
2’s
2’s complement
complement form
form
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
Boundary
Boundary requirements
requirements
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
DATA
DATA REPRESENTATION
REPRESENTATION
Objectives
Floating 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
DATA
DATA REPRESENTATION
REPRESENTATION
Objectives
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 and
a sign indicator in the right
Objectives
Addressing Operands
• Register addressing
• Base, displacement addressing
• Base, index and displacement addressing
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
Addressing RX Operands:
Objectives
Implicit format:
L 3,VAR
Explicit format:
L 3,100(0,12)
Assembler
Assembler Language
Language
SESSION 2
Addressing
STORAGE
STORAGE DEFINITIONS
DEFINITIONS
Objectives
Two ways to define fields :
STORAGE
STORAGE DEFINITIONS
DEFINITIONS
Objectives
Format:
label {DS/DC} dtLn’value’
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
STORAGE
STORAGE DEFINITIONS
DEFINITIONS
Objectives
Examples:
ALPHA DC C’ABC EF’
FLDS DS 3CL2
H1 DC H’29’
F2 DC F’-10’
F1 DC X’03’
F3 DC PL4’-72’
STORAGE
STORAGE DEFINITIONS
DEFINITIONS
Objectives
DC TYPES
Type Implied Alignment Data Representation
Length
C - None Character
X - None Hex digits
B - 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
STORAGE
STORAGE DEFINITIONS
DEFINITIONS
Objectives
Data Representation in other languages:
Assembler FORTRAN COBOL PASCAL BASIC
Language
DC Type
C Character Display String String
F, H Integer COMP Integer Integer
E Real COMP-1 Real Single
precision
D Double COMP-2 Real Double
Precision Precision
X, B Logical N/A Boolean Hex
P N/A COMP-3 N/A N/A
STORAGE DEFINITIONS
Objectives
Literals
• A literal is a constant preceded by an equals sign ‘=‘.
• Can be used as a main-storage operand but not as a
destination field of an instruction
• Causes assembler to define a field that is initialized 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
(Unless changed by LTORG instruction)
L R4,=F’1’
Objectives
Exercise 1 Q 1 and Q2.
Objectives
EQU (Assembler directive)
R4 EQU 4
DRBACK EQU OUT+25
ESTABLISHING
ESTABLISHING ADDRESSABILITY
ADDRESSABILITY
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)
ESTABLISHING
ESTABLISHING ADDRESSABILITY
ADDRESSABILITY
Objectives
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 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
ESTABLISHING
ESTABLISHING ADDRESSABILITY
ADDRESSABILITY
Objectives
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
ESTABLISHING
ESTABLISHING ADDRESSABILITY
ADDRESSABILITY
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
ESTABLISHING
ESTABLISHING ADDRESSABILITY
ADDRESSABILITY
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
Guideline:
• Specify all USING instructions at the beginning of the
source module
• Specify a base address in each USING instruction that lies
at the beginning of each control section
CTS-PAC Version 2.0 38
Assembler/Session 2
RELATIVE
RELATIVE ADDRESSING
ADDRESSING
Objectives
• Relative addressing is the technique of addressing
instructions 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
Assembler
Assembler Language
Language
SESSION 3 & 4
Machine Instructions
HANDLING
HANDLING CHARACTER
CHARACTER DATA
DATA
Objectives
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
CTS-PAC Version 2.0 41
Assembler/Session 3 & 4
HANDLING
HANDLING CHARACTER
CHARACTER DATA
DATA
Objectives
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,C’B’
HANDLING
HANDLING CHARACTER
CHARACTER DATA
DATA
Objectives
Advanced Techniques
1. Explicit lengths and relative addressing
MVC PAD+6(4),=CL4’ ‘
PAD DS CL10
HANDLING
HANDLING CHARACTER
CHARACTER DATA
DATA
Objectives
Moving more than 256 characters: MVCL instruction
Uses 2 pairs of even-odd pair of registers
Format : MVCL R1,R2 (Both are even registers)
Reg R1 – Address of destination R1+1 – Length
Reg R2 - Source R2+1 – Padding character (1 st 8 bits) and Length
Eg: LA 2,Q
LA 3,2000
LA 4,P
LA 5,1500
MVCL 2,4
HANDLING
HANDLING CHARACTER
CHARACTER DATA
DATA
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
CLI - Compare logical immediate
e.g. CLI FLDA,C’K’
Objectives
Exercise 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
BINARY
BINARY INSTRUCTIONS
INSTRUCTIONS
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 5,FULL LR 5,7
STH 7,HALF
BINARY
BINARY INSTRUCTIONS
INSTRUCTIONS
Objectives
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 H’15’
FULL DC F’8’
BINARY
BINARY INSTRUCTIONS
INSTRUCTIONS
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 5,FULL
AH 6,HALF
AR 7,3
BINARY
BINARY INSTRUCTIONS
INSTRUCTIONS
Objectives
Binary Subtraction (S, SH and SR)
• Type R-X
e.g.
S 5,FULL
SH 6,HALF
SR 7,3
BINARY
BINARY INSTRUCTIONS
INSTRUCTIONS
Objectives
Binary comparisons (C, CH and CR)
e.g.
C 5,FULL
CH 6,HALF
CR 7,3
Objectives
Binary 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 half word
format)
op2 : storage area (full word/half word/register)
BINARY
BINARY INSTRUCTIONS
INSTRUCTIONS
Objectives
Binary Division (D, DR)
Format: D op1,op2
Type : 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
e.g. BC B’1001’,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
BRANCHING
BRANCHING
Objectives
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
BIT
BIT MANIPULATIONS
MANIPULATIONS
Objectives
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,X’0F’
NR 5,7
X 9,FULL
BIT
BIT MANIPULATIONS
MANIPULATIONS
Objectives
OR Second 0 1 AND Second 0 1
First 0 0 1 First 0 0 0
1 1 1 1 0 1
Exclusive OR
Second 0 1
First 0 0 1
1 1 0
BIT
BIT MANIPULATIONS
MANIPULATIONS
Objectives
Testing individual bits - Test under mask (TM)
TM S1,I2
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,B’00000101’
BNM NEXT
BIT
BIT MANIPULATIONS
MANIPULATIONS
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 5,1
SRDA 4,5
CTS-PAC Version 2.0 62
Assembler/Session 3 & 4
BIT
BIT MANIPULATIONS
MANIPULATIONS
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
Translations
Objectives
1 byte - 256 possible combinations
x’00’,x’01’, x’02’, x’03’,…………..x’0F’
x’10’,x’11’,x’12’,…………………..x’1F’
…………………………………………..
x’F1’,x’F2’,x’F3’,…………………x’FF’
The table should start with replacement byte for
x’00’ and end with replacement for x’FF’
TABLE DC 75X’00’
DC X’4B’
DC 180X’00’
Numeric
Numeric Conversions
Conversions
Objectives
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
CTS-PAC Version 2.0 68
Assembler/Session 3 & 4
Numeric
Numeric Conversions
Conversions
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
Numeric
Numeric Conversions
Conversions
Objectives
3. Conversion from Zoned decimal to packed
(PACK) (SS instruction)
Format: PACK operand1,operand2
operand1 : Packed decimal
operand2 : Zoned Decimal
e.g. PACK PACKED(3),ZONED(5)
Numeric
Numeric Conversions
Conversions
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)
Relation
Relation between
between CVD,CVB,PACK
CVD,CVB,PACK and
and UNPACK
UNPACK
Objectives
PACK Input
CVB
Binary in Packed Zoned
Register UNPK Output
CVD Decimal Decimal
Example
Example code
code for
for Different
Different conversions
conversions
Objectives
PACK PNUM(8),START(3)
CVB 7,PNUM
A 7,=F’1’
CVD 7,PNUM
UNPK ANS(3),PNUM(8)
…
…
START DC C’125’
ANS DS CL3
PNUM DS D
Packed
Packed decimal
decimal operations
operations
Objectives
SS format - OPCODE D1(L1,B1),D2(L2,B2)
AP - Add packed
SP - Subtract packed
ZAP - Zero and add packed
MP - Multiply packed
DP - Divide packed
CP - 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
Packed
Packed decimal
decimal operations
operations
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
Packed
Packed decimal
decimal operations
operations
Objectives
Advanced instructions: (SRP continued)
NUM is a 5 byte packed decimal number and contains 001234567C.
What is the value in number after each of these instructions?
1. SRP NUM(5),2,0
2. SRP NUM(5),62,0
3. SRP NUM(5),62,5
4. SRP NUM(5),60,5
Packed
Packed decimal
decimal operations
operations
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),=X’00’
MVZ TEMP+3(1),=X’00’
MVN TEMP+3(1),A+2
A DC PL3’123’
TEMP DS PL4
CTS-PAC Version 2.0 77
Assembler/Session 3 & 4
Editing
Editing the
the output
output for
for printing
printing
Objectives
ED and EDMK instructions ( D1(L,B1), D2(B2)) (Pattern and PD
number) …
Patterns: …
x’20’ - Digit selector
x’21’ - Significance selector
x’22’ - Field separator x’60’ - Sign indicator
Pattern and the packed decimal number processed from left 1 byte at a time
X 0 1 2 3 4 5 6 C (Instruction: ED P(12),X)
Fill Character
P 40 20 20 6B 20 21 20 4B 20 20 60 40 (Before execution)
P 40 40 F1 6B F2 F3 F4 4B F5 F6 40 40 (After execution)
Editing
Editing the
the output
output for
for printing
printing
Objectives
Values being Action taken
examined
Pattern PD digit New pattern New state of
byte SI
When the Digit 0 Fill character Off
significant selector digit in
indicator is off 1-9 EBCIDIC On
Significanc 0 Fill character On
e starter 1-9
digit in
EBCIDIC On
Field None Fill character Off
seperator
Any other None Fill character Off
byte
When the Digit 0-9 digit in On
significant selector EBCIDIC
indicator is on Significanc 0-9 digit in On
e starter EBCIDIC
Field None Fill character Off
seperator
Any other None Pattern byte On
byte not changed
Editing
Editing the
the output
output for
for printing
printing
Objectives
-ED and EDMK can detect the difference between significant and non signi
ficant digits ie between leading and non leading zeros
-EDMK allows a floating currency and/or algebraic sign but ED does not allow
TABLE
TABLE PROCESSING
PROCESSING
Objectives
A table is a named storage structure consisting of
subunits or entries
e.g. RATE DS 6F
L 4,RATE+8
Accessing table elements with indexed storage
operands:
e.g. LH 9,=F8’
L 5,RATE(9) (9 - index register)
e.g. LH 9,=H’12’
REPEAT EQU *
..
BCT 9,REPEAT
Objectives
Load instructions with additional features
USING
USING EQUATES
EQUATES
Objectives
• To associate a fixed value with a symbol
• Useful for length and relative address calculation
e.g. TABLE DS 0H
DC C’01
DC C’02’
...
TBLEND EQU *
TBLSIZE EQU TBLEND-TABLE
Can be
Objectives
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, 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
Assembler
Assembler Language
Language
SESSION 5
Program Sectioning
Beginning
Beginning and
and End
End of
of Source
Source Modules
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
CONTROL
CONTROL SECTIONS
SECTIONS
Objectives
• 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
Format of CSECT:
Name Operation Operand
Any symbol CSECT Not required
or blank
DUMMY
DUMMY SECTIONS
SECTIONS
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.
ASMBLY2 CSECT
BEGIN BALR Objectives
2,0
USING *,2
... Reg 3 points to data
area
LA 3,INPUT
USING INAREA,3
CLI INCODE,C'A'
BE ATYPE
...
ATYPE MVC WORKA,INPUTA
MVC WORKB,INPUTB
..
CTS-PAC Version 2.0 99
WORKA DS CL20
WORKB DS CL18
INPUT DS CL39
...
INAREA DSECT
INCODE DS CL1
INPUTA DS CL20
INPUTB DS CL18
...
CTS-PAC Version 2.0
Assembler/Session 5
Assembler
Assembler Directives
Directives
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
Assembler
Assembler Language
Language
SESSION 6
Writing a complete program
Program
Program Entry
Entry and
and Exit
Exit Logic
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
Assembler/Session 6
R1 Main storage
Objectives
Addr of parmlist Parmlist parm3
Addr of parm1
Addr of parm2 parm1
Addr of parm3 parm2
L R3,4(,R1)
L R8,0(,R3)
Objectives
Registers with special use
R0 : Contains single word output of a
subroutine
R1 : contains the address of an area of
main storage that contains addresses of
parameters
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
RANDAD DC A(RANDOM)
CTS-PAC Version 2.0
Assembler/Session 6
Linkage
Linkage Conventions
Conventions
Objectives
•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
program B
ENTRY TABLEB
TABLEB DS ...
e.g L 5,ADCON
ADCON DC A(SOMWHERE)
GSUBADDC V(READATA)
Assembler
Assembler Language
Language
SESSION 7
Assemble and Link Program
PL/I to Assembler
DCL ASMSUB ENTRY OPTIONS(ASSEMBLER)
CHARSTRING CHAR(25);
CALL ASMSUB(CHARSTRING);
Ref : PL/I Programming Guide, COBOL
programming Guide
Assembler
Assembler Language
Language
SESSION 8
Macro Language
Macros Objectives
• Short source routines written and
stored in libraries
•Assembler inserts the source
statements in the program where
the macro appears
Header statement:
Objectives
MACRO
Prototype:
&name MOVE &TO,&FROM,&LENGTH
Model statements:
A set of machine and assembler instructions
Trailer statement:
&name MEND
CTS-PAC Version 2.0
Assembler/Session 8
Macro Instruction:
Objectives
• 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
Macro Instruction ...
MACRO
&LABEL HALFSWAP ®,&SV
&LABEL ST ®,&SV
SLL ®,8
IC ®,&SV
SLL ®,8
IC ®,&SV+1
MEND
Attributes
Objectives
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
Conditional Assembly
Objectives
The assembler can be made to branch and loop
among assembler language statements using
sequence symbols and the assembler
instructions AIF and AGO
Format:
Objectives
Label Operation Operand
seq symbol AGO seq. symbol
or blank
-do- AIF A logical expression
enclosed in parenthesis,
followed by seq symbol
.E MEND
CTS-PAC Version 2.0
Assembler/Session 8
Accessing QSAM files:
Objectives
Keywords in DCB parameter:
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
ARG - Label containing the key for the search (Key for
KSDS, RRN for RRDS and RBA for ESDS)
Assembler
Assembler Language
Language
SESSION 9
Other Topics
Objectives
Characteristics of good assembler program
• has simple, easy to understand logic
• uses mostly simple instructions
• has no relative addressing
• uses subroutines
• uses DSECTs
• has efficient code (LA R10, 4(0,R10 - A R10,=F’4)
• does not abnormally terminate due to user error
• requests and check feedback from macro instructions
• provides meaningful error messages
Structured Programming
Objectives
• To improve design and understandability of a
program
• made up of building blocks of subroutines
DEBUGGING
DEBUGGING
Objectives
Exceptions and Interrupts
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
CTS-PAC
code 6 :Specification
Version 2.0
Assembler/Session 9
DEBUGGING
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)
DEBUGGING
DEBUGGING
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
CTS-PAC Version 2.0
DEBUGGING
DEBUGGING
Reading dumps ...
• Locate the entry point of your program
DEBUGGING
DEBUGGING
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 just
before the interrupt address given)
• use address at interrupt and entry address to
locate the instruction that caused the program-
check interruption
DEBUGGING
DEBUGGING
Objectives
Full and Partial dumps
• //SYSUDUMP DD SYSOUT=A
• SNAP macro
SYSTEM
SYSTEM MACROS
MACROS
Objectives
Data 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)
CTS-PAC Version 2.0
Assembler/Session 9
SYSTEM
SYSTEM MACROS
MACROS
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
Assembler/Session 9
SYSTEM
SYSTEM MACROS
MACROS
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
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=,)
CTS-PAC Version 2.0
Assembler/Session 9
SYSTEM
SYSTEM MACROS
MACROS
Three forms : 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