IBM 370 Assembly Language - Day2
IBM 370 Assembly Language - Day2
FOR
IBM 370
Day 2
1
Agenda
Agenda
Day1 – Fundamental Concepts – Assembly Language
Basics
2
Day2
Topics
3
Summary of Session 1
1. Instruction – converted to m/c lang & executed at run time
2. Directives – will not be converted to m/c lang & used by assembler
3. Opcode-Operand format – opcode is instr or directives
4. & operand is data or addr of data
5. B-D format of addressing - 12 bits D and 4 bits reg name
6. How assembler gets base address, base register & displacement from
USING statement
7. How Assembler converts name fields to memory address in D(,B) format.
8. How program gets base address & calculates effective address from BALR
instruction
9. Relocation factor – program to use address assigned after loaded instead
of using address assigned by assembler
10. 24 bit memory addressing (for 16 MB memory) with 16 bit address
representation using B-D format
11. 16 registers and register usage conventions
12. How Assembler converts name fields to memory addresses
4
Standard Programming conventions
There are conventional programming requirements for writing the
program in IBM 370.
No. Requirement Program statements Comments
PGMNAME1 CSECT Tells the Program name.
STM Store regs. 14 thru 12 in save area.
The first statements 14,12,12(13) Establish base address in reg. 12.
(other than comments) for BALR 12,0
1. Tells base address / reg. to assmblr.
the program should be USING *,12 Store previous pgm / OS save area.
these:
ST 13,SAVE+4 Load current program’s save area
LA 13,SAVE address.
LABEL001 L 13,SAVE+4
The last executable Restore prev. pgm / OS save area.
LM Restore prev. pgm / OS registers.
2. statements of the program 14,12,12(13)
should be these: BR 14
Return to prev. pgm or OS.
5
Complete convention
This is complete convention which includes storing current
program’s SAVE area address in previous program’s SAVE
area in SAVE+8.
6
SAVE AREA
1. Save the previous program registers 14 thru 12 in previous program SAVE area in SAVE +
12.
2. Save the Previous program SAVE area address in current program SAVE area in SAVE + 4.
3. Save the Current program SAVE area address in previous program SAVE area in SAVE + 8.
OS Save area Current program’s Save area (P) Next program’s Save area (Q)
1st word SAVE Used by PL1 programs Used by PL1 programs saved by Used by PL1 programs
8
Sample Program to use memory
addressing & indexing
PROGRAM1 CSECT CONVENTIONAL REQUIREMENT 1
STM 14,12,12(13)
BALR 12,0
USING *,12
ST 13,SAVE+4
LA 13,SAVE
GETVAL LA 5,ARRAY01 LOAD ADDRESS OF ARRAY
L 7,COUNT1 LOAD ARRAY COUNT
L 2,=F’0’ INITIALIZE INDEXING REG TO 0
L 8,=F’0’ INITIALIZE REG 8 FOR STORING
ADDLOOP A 8,0(2,5) ADD DATA FROM NEXT MEM LOCATION
LA 2,4(2) INC INDEX REG BY 4 (INC QTY)
BCT 7,ADDLOOP DCRMNT COUNT AND BRANCH IF NOT 0
STORERES ST 8,SUM1 STORE THE RESULT IN SUM1 FIELD
WTO ‘THE SUM OF ARRAY OF NOS. IS ‘ SUM1 DISPLAY THE SUM
EXIT L 13,SAVE+4 CONVENTIONAL REQUIREMENT 2
LM 14,12,12(13)
BR 14
ARRAY01 DC F‘10’ FIRST ARRAY ELEMENT
DC F’20’ SECOND
DC F’30’ THIRD
DC F’40’ FOURTH
DC F’50’ FIFTH
COUNT1 DC F‘5’ COUNT OF ARRAY
SUM1 DS F RESULT FIELD
SAVE DS 18F CONVENTIONAL REQUIREMENT 3
END PROGRAM END
9
©
Explicit format Vs Implicit format
No. Explicit Format Implicit Format
The operands need to be converted to base-
1. The operands can be kept as it is.
displacement form for implicit formats.
Base-displacement form and register addresses are
2. Name-field symbol is used to represent address.
used to represent address.
Simpler to use, less error prone, greatly facilitate
3. Not ease of use.
writing and modifying the program.
In the RX explicit base-displacement form there are
3 possibilities X2 and B2 specified, X2 omitted and
B2 omitted. X2 omitted or B2 omitted has the
same effect at run time. Index register can be used
for incrementing the subsequent addresses in
looping to operate multiple data. Explicit format RX In the RX implicit name-field symbol form there are
R1,D2(X2,B2). 2 possibilities length specified and length not
4. specified and assumed from first name-field.
Effective address = content of base register +
displacement + Implicit format RX R1,S2(X2)
content of index register
= base address +
displacement +
index
10
Explicit format Vs Implicit format
(continued...)
No. Explicit Format Implicit Format
The assembler is required to generate the base-
The effective address is calculated during the
run time from base-displacement form of displacement form of address for name-field symbol, say
address to operate the data present in that Z in add example shown below. The assembler gets base
address. Explicit format RX R1,D2(,B2). address and base register from ‘USING’ directive. Thus
displacement can be calculated and the format D2(,B2)
5. Effective address = content of base can be achieved. Implicit format RX R1,S2.
register + displacement = address of name-field symbol Z –
displacement content of base register +
= base address + = address of name-field symbol Z –
displacement base address
In the explicit formats length has to be
In the implicit format length will be assumed by
mentioned explicitly for L and L1, L2 in SS1
6. assembler to number of bytes of first name-field symbol if
D1(L,B1),D2(B2) and SS2
it is not mentioned. Implicit format SS1 S1,S2.
D1(L1,B1),D2(L2,B2) respectively.
A 3,4(10,11) – RX X2 & B2 Specified A 3,Z - RX name-field symbol
A 3,4(,11) – RX X2 omitted A 3,Z(6) - RX name-field symbol with index reg. 6
7. A 3,4(11) – RX B2 omitted CLC X(5),Z - SS1 length 5 specified
A 3,4 – RX X2 & B2 omitted CLC X,Z - SS1 length of first symbol taken,
CLC 85(5,12),200(12) – SS1 length is 5 hence length of X
11
Instruction Formats
Instruction Instruction
No. Instruction Formats
Type Length
Assembly Language
Instruction Format
op R1,R2
Assembly Language
Instruction example
AR 3,4
1. RR – EXPLICIT
Machine Language
converted
1A 3 4 8 + 4 +4
= 16 bits
Machine Language
op R1 R2 = 2 bytes
Instruction Format
Assembly Language
RX – EXPLICIT Instruction Format
op R1,D2(X2,B2)
(with both X2
& B2) Assembly Language
Instruction example
A 3,4(10,11)
2a. Operand 2
Effective Machine Language 8 + 4 + 4 +4
5A 3 A B 004
address = R10 converted + 12
content + R11 = 32 bits
Machine Language op R1 X2 B2 D2
content + 4
Instruction Format = 4 bytes
12
Instruction Formats (continued...)
Instruction Instruction
No. Instruction Formats
Type Length
Assembly Language
RX – EXPLICIT op R1,D2(,B2)
Instruction Format
(X2 omitted) –
no indexing - Assembly Language
Instruction example
A 3,4(,11)
2b. Operand 2
Effective Machine Language 8 + 4 + 4 +4
address = R11 converted
5A 3 0 B 004
+ 12
content + 4 = 32 bits
Machine Language
Instruction Format
op R1 X2 B2 D2 = 4 bytes
Assembly Language
Instruction Format
op R1,D2(X2)
RX – EXPLICIT
(B2 omitted) Assembly Language
Instruction example
A 3,4(11)
2c. Operand 2
Effective Machine Language 8 + 4 + 4 +4
5A 3 B 0 004
address = R11 converted + 12
content + 4 = 32 bits
Machine Language op R1 X2 B2 D2
Instruction Format = 4 bytes
13
Instruction Formats (continued...)
Instruction Sample Instruction
No. Instruction Formats
Type Values Length
Assembly Language
Instruction Format
op R1,D2
RX – EXPLICIT
(both X2 & B2 Assembly Language
Instruction example
A 3,4
omitted)
2d.
Operand 2 Machine Language 8 + 4 + 4 +4
converted
5A 3 0 0 004
Effective + 12
address = 4 = 32 bits
Machine Language
op R1 X2 B2 D2 = 4 bytes
Instruction Format
Assembly Language
Instruction Format
op R1,S2(X2)
RX – IMPLICIT
Assembly Language A 3,Z(5) replaced by Z=80A, base
Operand 2 register is 12 thus
Instruction example A 3,2052(5,12)
2e. Effective B2=C, base
address = Machine Language address=6, index 8 + 4 + 4 +4
Address of Z + 5A 3 5 C 804 register X2=5
converted + 12
R5 content (given), index=20,
Machine Language displacement=80A- = 32 bits
op R1 X2 B2 D2
Instruction Format 6=X’804’=2052 = 4 bytes
14
Instruction Formats (continued...)
Instruction Sample Instruction
No. Instruction Formats
Type Values Length
Assembly Language
Instruction Format
op R1,S2
15
Instruction Formats (continued...)
Instruction Sample Instruction
No. Type Instruction Formats
Values Length
Assembly Language
Instruction Format
op R1,R2,S3
16
© 2003-2010 GalaxE.Solutions ®Strictly
Private and Confidential
Instruction Formats (continued...)
Instruction Sample Instruction
No. Type Instruction Formats
Values Length
Assembly Language
Instruction Format
op S1,I2
SI – IMPLICIT
- 1 byte Assembly Language CLI Z,X’40’ replaced by Z=80A, base
Immediate Instruction example register is 12
CLI 2052(12) ,X’40’ thus B3=C,
4b. data - Operand
Machine Language base
1 Effective 95 40 C 804 8 + 8 + 4 +12
converted address=6,
address =
displacement= = 32 bits
Address of Z Machine Language 80A-
op R1 R2 B3 D3 = 4 bytes
Instruction Format 6=X’804’=2052
Assembly Language
Instruction Format
op D1(B1)
S – EXPLICIT Assembly Language
Operand 1 Instruction example
TS 12(13)
5a. Effective
Machine Language 93 unused D 00C
address = R13 8 + 8 + 4 +12
converted
content + 12 = 32 bits
Machine Language op unused B1 D1 = 4 bytes
Instruction Format
17
Instruction Formats (continued...)
[Note: Length field L is one less in machine language than in assembly language in
SS1 type]
18
©
Instruction Formats (continued...)
[Note: Length field L is one less in machine language than in assembly language in
SS1 type]
19
Instruction Formats (continued...)
[Note: Length field L is one less in machine language than in assembly language in
SS1 type]
20
Instruction Formats (continued...)
[Note: Length fields L1 & L2 are one less in machine language than in assembly
language in SS2 type]
21
Instruction Formats (continued...)
[Note: Length fields L1 & L2 are one less in machine language than in assembly
language in SS2 type]
22
Instruction Formats (continued...)
[Note: Length fields L1 & L2 are one less in machine language than in assembly
language in SS2 type]
23
Instruction Formats (continued...)
[Note: Length fields L1 & L2 are one less in machine language than in assembly
language in SS2 type]
24
Instruction Formats (continued...)
[Note: Length fields L1 & L2 are one less in machine language than in assembly
language in SS2 type]
25
THANK YOU!
Questions?
26