Assembler Language IV
Assembler Language IV
"Boot Camp"
Part 4 - Arithmetic;
Program Structures
SHARE in Minneapolis
July 22 - 27, 2001
Session 8184
1
Introduction
Who are we?
2
Introduction
Who are you?
An applications programmer who needs to write
something in S/390 assembler?
An applications programmer who wants to
understand S/390 architecture so as to better
understand how HLL programs work?
A manager who needs to have a general
understanding of assembler?
4
Introduction
The original ASSIST (Assembler System for
Student Instruction and Systems Teaching) was
written by John R Mashey at Penn State University
8
Today's Agenda
The MULTIPLY and DIVIDE Instructions
9
The MULTIPLY and
DIVIDE Instructions
In Which We Encounter
"Higher" Math
10
Multiplication
MULTIPLY, like ADD and SUBTRACT, comes in
two flavors: RR and RX
12
Multiplication
For example: if c(R9) = 00000003,
c(R7)=FFFFFFFD (-3), and c(R6) is anything
Then MR R6,R9 leaves R9 unchanged and the
result is R6/R7 = FFFFFFFF FFFFFFF7 (-9)
M 0,WORD1
R0/R1 = FFFFFFFF FFFFFFF6 (-10)
M 0,WORD2
R0/R1 = 00000000 00000002 (2)
M 2,WORD1
R2/R3 = 00000000 00000028 (40)
15
Division
Division also comes in two flavors: RR and RX
16
Division
The dividend is two words long and in the
even/odd pair R1/R1+1
19
Division Examples
DR 2,4
R2/R3 = 00000000 FFFFFFEC (0,-20)
DR 2,5
R2/R3 = 00000014 00000000 (20,0)
D 2,WORD1
R2/R3 = 00000000 FFFFFFFB (0,-5) 20
Division Examples
D 2,WORD2
R2/R3 = 00000006 00000001 (6,1)
D 4,WORD1
R4/R5 = 00000000 0000003C (0,60)
D 4,WORD2
R4/R5 = FFFFFFFE FFFFFFEF (-2,-17)
21
Register EQUates &
Extended BRANCH
Mnemonics
In Which We Find More Than One
Way to Say the Same Thing
22
Register EQUates
It is possible to define symbols using the EQU
instruction
label EQU expression
26
Literals
Recall that the DC instruction defines an area of
storage within a program, with an initial value
Since that value is only initial, it can easily be
changed (and very often is)
27
Literals
We can instead define the constant as part of the
instruction, directly as the second operand
M R4,=F'1'
28
Literals
But where will the storage for this literal be?
With a DC (or DS) the location is exactly where
the instruction occurs
30
The LOAD ADDRESS Instruction
Sometimes only D2 is specified - that is, X2 and B2
are zero
LA R5,4 (0<=D2<=4095)
This is a long-standing method to place a small
number in a register with no other memory access
Note: this is the same as LA R5,4(0,0)
34
Demo Program to Build a Table - 4
LTORG
CARD DS CL80 Card input area
TABLE DS 50F Room for 50 entries
TRAILER DC F'999999'
R2 EQU 2
R3 EQU 3
R4 EQU 4
R14 EQU 14
R15 EQU 15
END TABUILD
$ENTRY
123
456
789
234
567
890
345
999999
35
Looping Using BCT and BCTR
The loop we saw in the demo is controlled by the
number of records in the input file
The logic is
Decrement R1 by one
If c(R1) .NE. 0, branch; otherwise, continue
39
The Program Status Word (PSW)
The PSW is a two-word aggregation of a number
of important pieces of information, including
The address of the next instruction
The Interruption Code
The Condition Code (CC)
The Program Mask
The Instruction Length Code (ILC) (in ASSIST only)
43
BAL/BALR and Subroutines
There is a very important instruction which is
used to control access to subroutines, BRANCH
AND LINK
50
Type A Data: Address Constants
label DC A(exp) [or DS A]
If exp is a non-negative integer, the generated
fullword will have the binary representation of the
integer (same as F'exp')
If exp is the label of an instruction or a data area,
or is of the form label+n or label-n, the generated
fullword will contain the appropriate address
If exp is the label of an EQU of a non-negative
integer, then the symbol is interpreted as a
non-negative integer, and the generated fullword will
have the binary representation of the integer
51
Type A Data: Address Constants
The following are examples
DC A(123) generates 0000007B
DC A(R12) generates 0000000C
DC A(SAVE) generates the address of SAVE
56
External Subroutines - Parameters
The following demonstrates a typical parameter
list and how it is passed to SORTTABL:
LA R1,PARMLIST
L R15,=V(SORTTABL)
BALR R14,R15
...
NUM DC F'20' Value to pass
PARMLIST DC A(TABLE) First parameter
DC A(NUM) Second parameter
DC A(RET) Third parameter
RET DS F Return code
TABLE DS 20F Table of values
57
External Subroutines - Parameters
We are clearly "passing by reference" rather than
"passing by value"
59
External Subroutines - Save Areas
None of the above conventions is particularly
difficult to understand or implement
61
External Subroutines - Save Areas
*** Unused *** R4
Address of previous R5
save area
Address of next save R6
area
R14 R7
R15 R8
R0 R9
R1 R10
R2 R11
R3 R12 62
External Subroutines -
Standard Entry and Exit Linkage
Registers are restored in a similar manner before
returning to the calling program
LM R14,R12,12(R13)
BR R14
69
Next Time
Tomorrow, we will look at how decimal arithmetic
is performed, and how numbers are converted
from binary to decimal to character (and the
reverse)