Académique Documents
Professionnel Documents
Culture Documents
Part -1
Assembler Training
• Disadvantages
– Application Development time is more.
– Applications are machine dependent.
– Difficult to learn and understand
– Does not provide data structure facilities like in
high-level language
Assembler Training
Main Storage
• Addressed by 24 bits or 31 bits
• Contains program and data
• Byte is the least addressable area
• Bytes can be addressed in groups (2,4 or 8)
• Instruction execution is faster if data is aligned in
fullword binary
Assembler Training
CPU
CPU executes five categories of instructions
– General instructions
– Decimal instructions
– Floating-point Instructions
– Control Instructions
– I/O Instructions
Assembler Training
CPU (Contd.)
CPU Contains
• Program Status Word (PSW)
• General Purpose registers (GPRs)
• Floating Point Registers( FPRs)
• Control Registers ( CRs)
• Arithmetic and Logical Unit (ALU)
• Interrupt handling logic
Assembler Training
CPU (Contd.)
CPU (Contd.)
• General Purpose Registers( GPR)
– 16 registers are available
– Each is 32 bits in length
– addressed by 0-15 of R field of the instructions
– Used as accumulators in binary arithmetic
instructions
– Two consecutive registers can be used to hold
64 bit operands and is addressed by even
register
Assembler Training
CPU (Contd.)
• Floating Point Registers
– Available for floating point operations
– 4 registers
– Each is 64 bits in length
– Addressed by 0,2,4,6
– Can contain short or long operand
– Two adjacent registers can be used as 128 bit
register
– Identified by R field of the instructions
Assembler Training
CPU (Contd.)
• Control Registers
– 16 control registers are available
– Each one is 32 bits in length
– Indicates facilities available in the system
– Addresses by 4 bit R filed of control
instructions
Assembler Training
Input/Output System
• Directs the flow of information between I/O derives and
main storage
• CPU is relieved of communicating directly to I/O
devices
• Data processing and I/O processing are concurrent
• Consists of channel subsystem ,control unit and
I/O
Assembler Training
Name field Operation field Operand field Remarks field Sequence field
Example
ADD1 AR 1,2
Assembler Training
Assembly Language Basics(contd.)
• Operands(contd.)
Immediate Operand
– Contained with in the instruction itself
– Eight bit value
– Self-defining term or an absolute symbol can be used
Example
Clear NI PARM,B’10000000’
PARM DC X’12’
Assembler Training
Assembly Language Basics(contd.)
• Operands(contd.)
Storage Operand
– Resides in memory
– Address is not specified explicitly
– Base and/or Index method is used
– Register 0 cannot be used as base or index register
– 12 bit displacement could be specified.
– BALR instruction is used to load base register
– If symbols are used assembler resolves it to base displacement
form.
Assembler Training
Assembly Language Basics(contd.)
• Operands(contd.)
Address calculation
Address is calculated by specifying a base address and the
displacement from the base. An Index can also be specified in some
instructions.
Effective address =(b) +(x)+disp
Effective address =(b) +disp
Size of storage operand
– Single or group of bytes
– length is implied by the instruction or specified in the instruction
Example LPSW D2(B2)
Assembler Training
Implied Operand
• Instruction itself assumes the operand
Assembler Training
Assembly Language Basics(contd.)
• Instructions Classification
Instructions are classified according to the types of
operands
RR Instructions :Both operands are in registers.
RS Instructions :First Operand is in the register and the
other in the storage.The address of the storage location is
specified in base displacement form.
RX Instructions: Similar to RS instructions ,but the storage
address is given by base,index and displacement form .
Assembler Training
Assembly Language Basics(contd.)
S Instructions :First Operand is in the storage and the other
operand is the implied operand.
SI Instructions: First Operand is in the storage and the
second is the immediate operand.
SS Instructions: Both Operands are in storage.
Examples
1. RR type instruction
AR 1,2 reg1==reg1+reg2
Assembler Training
Assembly Language Basics(contd.)
Examples (contd.)
2. RS type instruction
BXH 1,3,D2(B2) reg1==reg1+reg3
if reg1>reg3 then branch
3. RX type instruction
L 1,D2(X2+B2) reg1 <==(D2+X2+B)
4. S type instruction
LPSW D2(B2)
Assembler Training
Assembly Language Basics(contd.)
Examples (contd.)
Example:
LOAD L 2,=F’4’
MOVE MVC MSG,=C’**ERR**’
Assembler Training
Assembly Language Basics(contd.)
• Assembler Directives
Commonly used directives
CSECT
– Indicates the beginning of a program.
– Smallest portion of the code which can be relocated.
– A program can have more than one CSECT.
– CSECT ‘S can be continued across CSECT ‘S.
– Separate location counter for each CSECT .
– Symbols are not addressable across CSECT ‘S.
Assembler Training
Assembly Language Basics(contd.)
• Assembler Directives(contd.)
Commonly used directives(contd.)
DSECT
– Dummy control sections.
– To describe the structure of a block of memory with out
actually allocating memory.
– Acts as a template.
– No code is generated.
– DC statement is not allowed in a DSECT.
Assembler Training
Assembly Language Basics(contd.)
• Assembler Directives(contd.)
Commonly used directives(contd.)
DSECT(contd.)
Example:
CUSTOMER DSECT
NUMBER DS CL3
LNAME DS CL10
MNAME DS CL10
STREET DS CL5
CITY DS CL5
ZIP DS CL6
Assembler Training
Assembly Language Basics(contd.)
• Assembler Directives(contd.)
Commonly used directives(contd.)
USING
USING < symbol >,Rn.
– Symbol can be any relocatable symbol defined in the
program.
– ‘*’ can be used in the place of the symbol.
– Fields in the DSECT’S can be accessed after establishing
base with this directive.
Assembler Training
Assembly Language Basics(contd.)
• Assembler Directives(contd.)
Commonly used directives(contd.)
USING(contd.)
– Rn, base register to be used by the assembler for resolving the
symbols in the base displacement form.
– The location counter of the symbol is used as the base from
which displacements are calculated.
– Users responsibility to load the base register with base
register.
– BALR instruction can be used to load the base address.
– Range of a base register is 4096 including the base.
– If the code size is more than 4096 bytes,multiple base
registers have to be used.
Assembler Training
Assembly Language Basics(contd.)
• Assembler Directives(contd.)
Commonly used directives(contd.)
USING(contd.)
Example:
BALR R12,0 load the base address
USING *,12 reg 12 is the base register.
USING PROG,10 base for DSECT PROG
Assembler Training
Assembly Language Basics(contd.)
• Assembler Directives(contd.)
Commonly used directives(contd.)
ORG
ORG <expr>
• If expr is specified ,location counter is set with expr
value.
• If expr is not specified ,location counter takes
previous maximum value.
Assembler Training
Assembly Language Basics(contd.)
• Assembler Directives(contd.)
Commonly used directives(contd.)
ORG(contd.)
– Used to redefine the storage.
Example:
BUFFER DS 100F
ORG BUFFER
BUFF1 DS CL80
BUFF2 DS CL80
Assembler Training
Assembly Language Basics(contd.)
• Assembler Directives(contd.)
Commonly used directives(contd.)
DROP
DROP (R0,R1,….,Rn)
Specified registers are dropped as base registers.
END
Signals the end of a control section or program.
EJECT
Force a form feed.
Starts of with a fresh page.
Assembler Training
Load register
LR R1,R2
– Loads the content of R2 to R1.
– The condition code remains unchanged.
Assembler Training
Assembly Language Basics(contd.)
Load and test register
LTR R1,R2
• Loads the contents of register R2 to R1.
• Condition codes are set depending on the value loaded.
• A register can be checked for zero/non zero value by “ LTR
R1,R1”.
CC INTERPRETATION
00 zero
01 negative
02 positive
03 overflow
Assembler Training
Assembly Language Basics(contd.)
Load complement register
LCTR R1,R2
• Two’s complement R2 is loaded to R1.
• Condition codes are set.
Load negative
LNR R1,R2
• Two’s complement of absolute value of R2 is loaded to R1.
• Condition codes are set.
Assembler Training
Assembly Language Basics(contd.)
Load Positive
LPR R1,R2
• Absolute value of R2 is loaded to R1.
• Condition codes are set.
Load
L R1,D2(X2,B2)(Rx)
• D2(X2,B2) specifies the address of the second operand .
• The second operand is loaded to the first operand ,specified by
R1.
Assembler Training
Assembly Language Basics(contd.)
Load(contd.)
• Condition code is unchanged.
• Second operand can also be specified as
• S2, a symbol.
• S2(X2),a symbol with index.
• D2,absolute value (maximum value 4095).
• D2(,B2),base displacement form.
• D2(X2),index and displacement.
Assembler Training
Assembly Language Basics(contd.)
Load Halfword
LH R1,D2(X2,B2)
Example:
LA 2,25 reg2 <-- 25
LA 3,1(3) reg3 <-- reg3+1..
Assembler Training
Arithmetic Instructions
Assembler Training
• The second operand is added to the first operand and the sum
is placed at the first operand location.
• Condition code is set.
Assembler Training
Branch Instructions
Assembler Training
Assembly Language Basics(contd.)
Branch on condition
BCR M1,R2 (RR)
BC M1,D2(X2,B2) (RX)
The instruction address in the current PSW is replaced by the branch
address if the condition code has one of the values specified by
M1;otherwise,normal instruction sequencing proceeds with the updated
instruction address.
• M1 is a four-bit mask
• Each condition codes correspond to each bit of the mask
• If R2 field is zero,no branch is taken
Assembler Training
Decimal instructions
Assembler Training
Data conversion
Assembler Training
Assembly Language Basics(contd.)
Data Conversion Instructions
Pack
PACK D1(L1,B1),D2(L2,B2)
• Second operand is in zoned decimal format.
• The operand is converted from zoned format to packed format.
• Operands can overlap.
Unpack
UNPK D1(L1,B1),D2(L2,B2)
• Second operand is in packed decimal format.
• The operand is converted from packed format to zoned format.
• Digits are not checked for validity.
• Operands can overlap.
Assembler Training
Special instructions
Assembler Training
Assembly Language Basics(contd.)
Special Instructions
Translate
TR D1(L,B1),D2(B2)
TR SOURCE(L),TABLE
• Each byte source specifies the table entry which replaces itself in
source.
• Translates the source characters into the values found at the address
offsets in the second operand table one byte at a time.
• The table can have maximum of 256 entries.
• Can be used to translate data from one format to another.
• Can be used to rearrange a record layout.
Assembler Training
Assembly Language Basics(contd.)
Translate and Test
TRT D1(L,B1),D2(B2)
TRT SOURCE(L),TABLE
• Only searches for any specified character(s) in the source.
• Does not change the source.
• Zeroes in the table for no scan.
• Register 1 contains address of the last byte translated.
• Register 2 contains table entry contents (24-31 bits, function byte)
• can be used to find occurrence and position of an invalid character.
• Condition code setting is
• 0 - all function bytes zero
• 1 - non-zero function byte; source not exhausted
• 2 - non-zero function byte; source exhausted
• 3 - ---
Assembler Training
Assembly Language Basics(contd.)
Execute
EX R1,D2(X2,B2)
• Bits 8-15 of the instruction designated by the second-operand
address are ORed with bits 24-31 of R! and the resultant
instruction is executed.
• The ORing does not change either the contents of R1 or the
instruction in storage.
• The target instruction may be 2,4 or 6 bytes in length.
• The execution and exception handling of the target instruction are
exactly as if the target instruction were obtained in normal
operation.
• The instruction address of the current PSW is increased by length
of the EXECUTE instruction.
• The target instruction can not be ‘EXECUTE’ instruction.
• Condition codes are set by the target instruction execution.
Assembler Training
Thank You