Assembler Language III
Assembler Language III
"Boot Camp"
Part 3 - Assembly and
Execution; Branching
SHARE in Minneapolis
July 22 - 27, 2001
Session 8183
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
Assembly of a Complete Program
9
Assembly of a
Complete Program
10
A Complete Program
Yesterday, we introduced a few instructions and
used them to create a complete, if short, program
11
First Demo Program, Source List
* This program adds two numbers that are taken
* from the 5th and 6th words of the program.
* The sum is stored in the 7th word.
ADD2 CSECT
L 1,16(,15) Load 1st no. into R1
L 2,20(,15) Load 2nd no. into R2
AR 1,2 Get sum in R1
ST 1,24(,15) Store sum
BCR B'1111',14 Return to caller
DC F'4' Fullword initially 4
DC F'6' Fullword initially 6
DS F Rsrvd only, no init
END ADD2
12
First Demo Program, Assembled
LOC OBJECT CODE SOURCE STATEMENT
13
First Demo Program, Assembled
LOC OBJECT CODE SOURCE STATEMENT
14
First Demo Program, Assembled
LOC OBJECT CODE SOURCE STATEMENT
15
First Demo Program, Assembled
LOC OBJECT CODE SOURCE STATEMENT
16
First Demo Program, Assembled
LOC OBJECT CODE SOURCE STATEMENT
17
First Demo Program, Assembled
LOC OBJECT CODE SOURCE STATEMENT
18
First Demo Program, Assembled
LOC OBJECT CODE SOURCE STATEMENT
19
First Demo Program, Assembled
LOC OBJECT CODE SOURCE STATEMENT
20
First Demo Program, Assembled
LOC OBJECT CODE SOURCE STATEMENT
21
First Demo Program, Assembled
LOC OBJECT CODE SOURCE STATEMENT
22
First Demo Program, Assembled
LOC OBJECT CODE SOURCE STATEMENT
23
First Demo Program, Assembled
LOC OBJECT CODE SOURCE STATEMENT
24
First Demo Program, Assembled
LOC OBJECT CODE SOURCE STATEMENT
25
Execution of a
Complete Program
26
ADD2 Program Before Execution
PSW AT BREAK FFC50000 0F000000
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
27
ADD2 Program Before Execution
PSW AT BREAK
Here is our
FFC50000 0F000000
R0-7 :
program loaded
F4F4F4F4 F4F4F4F4 F4F4F4F4 F4F4F4F4 F4F4F4F4 F4F4F4F4 F4F4F4F4 F4F4F4F4
R8-15: F4F4F4F4into memory
F4F4F4F4 F4F4F4F4 F4F4F4F4 F4F4F4F4 00000020 00000068 00000000
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
28
ADD2 Program Before Execution
PSW AT BREAK FFC50000 0F000000 Address of the
first instruction
R0-7 : F4F4F4F4 F4F4F4F4 F4F4F4F4 F4F4F4F4 F4F4F4F4 F4F4F4F4 F4F4F4F4 F4F4F4F4
R8-15: F4F4F4F4 F4F4F4F4 F4F4F4F4 F4F4F4F4 F4F4F4F4 00000020 00000068 00000000
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
29
ADD2 Program Before Execution
Address of the
next instruction
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
30
ADD2 Program After 1st Instruction
PSW AT BREAK FFC50000 8F000004
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
31
ADD2
ContentsProgram
of After 1st Instruction
word 5 "loaded"
to
PSW AT BREAK R1FFC50000 8F000004
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
32
ADD2next
Program
Address of the
instruction
After 1st Instruction
PSW AT BREAK FFC50000 8F000004
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
33
ADD2 Program After 2nd Instruction
PSW AT BREAK FFC50000 8F000008
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
34
ADD2 Program
Contents of
After 2nd Instruction
word 6 "loaded"
PSW AT BREAK to R2 8F000008
FFC50000
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
35
ADD2 Program After 2nd Instruction
Address of the
next instruction
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
36
ADD2 Program After 3rd Instruction
PSW AT BREAK FFC50000 8F00000A
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
37
ADD2
Contents ofProgram
R2 After 3rd Instruction
added to
PSW ATcontents
BREAK ofFFC50000
R1 8F00000A
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
38
ADD2next
Program
Address of the
instruction After 3rd Instruction
PSW AT BREAK FFC50000 8F00000A
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
39
ADD2 Program After 4th Instruction
PSW AT BREAK FFC50000 8F00000E
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
40
ADD2
Contents ofProgram
R1 After 4th Instruction
(sum) "stored"
PSW to word FFC50000
AT BREAK 7 8F00000E
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
41
ADD2next
Program
Address of the
instruction
After 4th Instruction
PSW AT BREAK FFC50000 8F00000E
===> B(rkpt.), D(ump), G(o), M(emory), P(SW), Q(uit), R(eg.), S(tep), T(race)
:
42
Implicit Addresses
and USING
Making Assembler
Programming "Easy"
43
A Slight Change
What if we want to make a change to our original
program? Maybe use register 12 as the base instead
of R15
47
Updated Demo Program Assembled
LOC OBJECT CODE SOURCE STATEMENT
50
Use Labels!
Remember: "Object Code - Nothing Else Matters"
54
Demo Program with Labels
* This program adds two numbers that are taken
* from WORD1 and WORD2 in the program.
* The sum is stored in WORD3.
ADD2 CSECT
LR 12,15 Copy addr of 1st inst
USING ADD2,12 Tell assembler
L 1,WORD1 Load 1st no. into R1
L 2,WORD2 Load 2nd no. into R2
AR 1,2 Get sum in R1
ST 1,WORD3 Store sum
BCR B'1111',14 Return to caller
WORD1 DC F'4' Fullword initially 4
WORD2 DC F'6' Fullword initially 6
WORD3 DS F Rsrvd only, no init
55
END ADD2
Demo Program with Labels
LOC OBJECT CODE SOURCE STATEMENT
57
The Condition Code
The ADD (A, AR) and SUBTRACT (S, SR)
instructions have an additional characteristic not yet
mentioned - they set the condition code in the
following way
CC Meaning
0 Result is 0
1 Result is < 0
2 Result is > 0
3 Overflow occurred
58
The Condition Code
Another pair of instructions, COMPARE (C, CR)
also set the condition code, but the values are
interpreted in a slightly different way
CC Meaning
0 Contents equal
1 1st operand value < 2nd operand value
2 1st operand value > 2nd operand value
3 ---- (not set)
59
The Condition Code
The condition code is actually two bits of the PSW
(bits 34 & 35 in ASSIST/I, bits 18 & 19 in S/390)
65
Character Data
At this point, we've seen only numeric data,
represented as binary fullwords (data type F)
72
The XDECI Instruction Logic
1. Start at D2(X2,B2), scan for the first non-blank
2. If the first non-blank is anything but + or - or a
decimal digit, set the condition code to 3 and quit
3. Otherwise, 1 to 9 digits are scanned and the
resulting number converted to binary, placed in
register R1
4. Register 1 is set to the address of the first
non-digit (so R1 should not be 1!)
5. If ten or more digits are found, register 1 is set to
the address of the first non-digit, the condition
code is set to 3, and R1 is unchanged 73
The XDECI Instruction Logic
XDECI sets the condition code
0 - The number converted was 0
1 - The number converted was < 0
2 - The number converted was > 0
3 - Non-numeric attempted
74
The XDECO Instruction
The XDECO instruction converts a binary numeric
value in a register to an EBCDIC numeric value in
memory (action opposite that of XDECI)
77
Example With X-Instructions (1 of 2)
* THIS PROGRAM READS DATA CARDS EACH HAVING TWO
* NUMBERS. THE SUM OF THE NUMBERS IS PRINTED.
*
SUMUP CSECT
USING SUMUP,15
*
XPRNT HEADING,28 PRINT PAGE HDR
XREAD CARD,80 READ 1ST CARD
*
CHECKEOF DC B'0100',EXIT BR ON EOF
*
XDECI 2,CARD ASSUME BOTH NUMS
XDECI 3,0(1) ARE VALID
*
78
AR 2,3 CALCULATE THE SUM
Example With X-Instructions (2 of 2)
XDECO 2,OUTPUT PRINTABLE FORM
* INTO PRINT LINE
XPRNT CRG,13 PRINT THE SUM
* AFTER SINGLE SPACE
XREAD CARD,80 TRY ANOTHER READ
BC B'1111',CHECKEOF GO CHECK FOR EOF
*
EXIT BCR B'1111',14 TERMINATE PROGRAM
*
CARD DS CL80 INPUT BUFFER
*
CRG DC C' ' SINGLE SPACE CC
OUTPUT DS CL12 SUM GOES HERE
HEADING DC C'1THIS IS THE OUTPUT OF SUMUP'
79
END SUMUP
What's Next?
Tomorrow, we will see the conventions which allow
routines to communicate, even though written at
different times by different people
80