An introduction to System 360 assembly language

Download Report

Transcript An introduction to System 360 assembly language

System 360 Assembly
Language
Brief Introduction
Copyright 2004-2005 Curt Hill
Assembler language format
• An assembly language statement
occupies one line
• It consists of four fields
– Each are delimited by blanks
– Only the first is column sensitive
– [LABEL] operation operands
comments
Copyright 2004-2005 Curt Hill
Label field
• This allows us to name a location
• Only used for instructions when the
instruction is the target for a branch
– However, a label may be applied to any
statement
• Data fields need labels so that they can be
referenced
• Must start in column 1
• Eight or fewer characters
• Starts with a letter
• May include letters and digits, but no
blanks
Copyright 2004-2005 Curt Hill
Operation
• The operation is a mnemonic for an
opcode
• The assembler knows what kind of
instructions have what kind of operands,
so a little checking goes on
• One or more blanks separate the label
from the operation
• There is no column requirement, but we
like to put it in column 10, because then
we can have all our operations line up
even if there is an eight character label
Copyright 2004-2005 Curt Hill
Operands
• Most instructions take two operands
• These operands are of the following
types:
• Register
– An unsigned number in range of 0-15
• Memory operand
–
–
–
–
Usually just a name
Can be base+offset pair
Can be name + index register
xyz(4) means the base + offset of xyz with the
addition of index register 4
– A name + additional displacement
– BALSX is very limited it only allows name and
name + index
Copyright 2004-2005 Curt Hill
Other Operands
• Immediate operands
– BALSX does not support
• Masks
• Lengths
• This field is separated by one or more
blanks from the operation
• If several operands are needed they are
separated by commas
• No blanks are allowed in the operand
fields
• The fields have to be in correct order and
type for the particular
operation
Copyright 2004-2005 Curt Hill
Comments
• Comments follow the operand field
without any further marking
• Any line starting with an * in column
1 is a comment and wholly ignored
Copyright 2004-2005 Curt Hill
Type of instructions
• System 360 defines the following types of
instructions:
• RR – two registers
– Length of 2
• RS – Two registers and storage
– Length of 4
• RX – Register and indexed storage
– Length of 4
• SI – Storage immediate
– Length of 4
• SS – Two storage locations
– Length of 6
• Many instructions come in a variety of flavors
– Eg. AND has an RR, RX, SI, and SS version
Copyright 2004-2005 Curt Hill
Arithmetic
• A fully loaded 360 could do arithmetic in
three flavors:
• Integer
– One of the operands is in a GP register
– RR, RX for fullwords
– RX for halfwords
• Floating point
– One of the operands is in a Floating Register
• Packed Decimal
– Both operands are in memory
– Each has a separate length
Copyright 2004-2005 Curt Hill
Registers
• The 360 has 16 General Purpose
Registers
• These are very important
• They are used for:
– Arithmetic
– Addressing
– Indexing
• One or two was usually used for a base
register - programmers choice
• Mastering register usage is one of the
first goals of a beginning assembler
Copyright 2004-2005 Curt Hill
Register Zero
• Register 0 could not be used for
addressing or indexing
• If used as a base register or index
register it always supplied a zero
• So always used for RX instructions
where there is no indexing
• Very frequently
Copyright 2004-2005 Curt Hill
Data flow
• System 360 instructions are two
address
• Data flow in an instruction is almost
always right to left
• The first operand will usually be the
one that is changed
• For example in an Add we will
specify two operands
– Both will participate
– The first one will receive the result
Copyright 2004-2005 Curt Hill
Instructions
• There is no assembly language
programming without familiarity with
individual instructions
• Next we look at some of the common
ones
• All of these will be used in virtually
every program
Copyright 2004-2005 Curt Hill
Load
• The Load instruction causes a value
to be loaded into a register
• Comes in two flavors:
• The LR is an RR
• The L is RX
Copyright 2004-2005 Curt Hill
LR
• Specifies two registers
• The contents of the second is loaded
into the first
• The second operand is unchanged
• LR 4,10
• Load the contents of 10 into 4
Copyright 2004-2005 Curt Hill
L
• RX operand so first operand is a
register, the second a memory
location with an optional index
register
• L 5,DATA
• Contents of memory location data is
placed in register 5
• Memory data is unchanged
• The old contents of 5 is lost
Copyright 2004-2005 Curt Hill
ST is the opposite
• ST 5,STUFF
• Take the contents of 5 and overwrite
the 4 bytes starting at STUFF
• Opposite of L 5,STUFF
• Violates the normal data flow
• No RR form, only RX
Copyright 2004-2005 Curt Hill
Add
• Again comes in two flavors RR, RX
• AR 4,7
• A 4,data
– Takes the contents of DATA and adds
to the contents of 4
– Data is unchanged, but 4 now contains
the sum
• Subtract is similar to Add
– Mnemonic is S
Copyright 2004-2005 Curt Hill
Halfwords
• Numerous RX instructions come in a
half word version as well
• A half word is a 16 bit quantity
• The lower half of a register is used
• Thus
– AH is the halfword version of A
– LH, STH, SH etc
• No RR operands are halfword
Copyright 2004-2005 Curt Hill
Load Address
• Consider L 7,STUFF
• When a Load is executed we take
the base and offset pair and add it to
gain the effective memory address
• LA 7,STUFF
• A Load Address puts that address
into the register
• No memory reference is generated
Copyright 2004-2005 Curt Hill
Comparisons
• Compare comes in RR and RX
versions
– C and CR
• Only sets conditions codes
• Every arithmetic operation sets
condition codes
• Compare is a subtract that does not
change a register
Copyright 2004-2005 Curt Hill
Branches
• The 360 has only one general
branch instruction which is the BC
or Branch on Condition
• It is RR or RS type instruction
– There is no register to be referenced
like a Load or Store
• Instead what we have is a mask
• The mask is used to determine
under what conditions to branch
Copyright 2004-2005 Curt Hill
Condition codes
• Recall that the PSW has two bits that
are known as the condition codes
• Two bits can represent four states,
which in this case are:
–
–
–
–
Zero (or equal) CC = 0
Negative (or lesser) CC = 1
Positive (or greater) CC = 2
Overflow CC = 3
• These bits are set by the last
arithmetic or compare instruction
Copyright 2004-2005 Curt Hill
Mask of BC
• The mask has four bits, one for each of the CCs
possible values
• If the CC has a value that corresponds to the
mask bit then the branch is executed otherwise
no branch occurs
• Examples:
• BC 8,LOC
– Will happen only if the CC means equal or zero
• BC 12,LOC
– Branch on less than or equal
• BC 15,LOC
– Is unconditional because all possible bits are on
• BC 0,LOC
– Never branch because all possible bits are off
Copyright 2004-2005 Curt Hill
Extended mnemonics
• The mask was fine for the hard cores
– The rest of us it was too hard to remember
• So the assembler used an extended
opcode
• An extended opcode incorporates both
the opcode and mask into the operation
field
• Merely come up with new mnemonics that
represent both:
–
–
–
–
–
B LOC means BC 15,LOC
NOP means BC 0,ANYWHERE
BE LOC means BC 8,LOC
BZ LOC means BC 8,LOC
BNH LOC means BC 12,LOC
Copyright 2004-2005 Curt Hill
Flow of Control
• In assembly / machine language we
do not have the familiar flow of
control:
– If
– While
– For
• Instead we construct it out of the C
and BC
Copyright 2004-2005 Curt Hill
The Block If
• Suppose in C
if(a>b){
…
}
• We construct that with:
L 4,A
C 4,B
BLE ENDLOOP
…
ENDLOOP
EQU *
Copyright 2004-2005 Curt Hill
A While is Harder
• Suppose in C:
while (a>b) {
…
}
• In assembly:
WBEGIN
L
C
BLE
…
B
WEND
EQU
4,A
4,B
WEND
WBEGIN
*
Copyright 2004-2005 Curt Hill
Variables and constants
• The assembler has two pseudo
operations: DC and DS for defining
variables
• DC means Define Constant
– Initialized to a constant value
– In no way unchangable
– Must define the length and value
• DS means Defined Storage
– Reserves storage but does not initialize
it
– Must define the type
Copyright 2004-2005 Curt Hill
Example:
• XYZ DC
F'5'
– XYZ is a variable
– A full word (4 bytes)
– Initialized to an integer +5
• ABC DS F
– ABC is an unitialized variable of size 4
bytes
Copyright 2004-2005 Curt Hill
Variables again
• The F designated both a size and a
boundary alignment
• In a DC the quoted string contained
a value
• There were other storage
designations:
– H, D, C, V, A
– BALSX does not implement
Copyright 2004-2005 Curt Hill
Arrays
• A repetition factor could precede
the type designation
• This created arrays, among other
things
• So the save area was:
SAVE DS 18F
Copyright 2004-2005 Curt Hill
BALSX pseudo instructions
• Because BALSX is a student assembler it tries to
make life easy on us
• It augments the normal instructions with several
that are really not assembler instructions or
macros
• GETD DATA
– Get an integer from the file and store in memory
location DATA
• PUTD DATA
– Put an integer to the output listing from memory
location DATA
• EOJ
– This terminates the execution of the program, when it is
encountered
Copyright 2004-2005 Curt Hill
More pseudo instructions
• END
– Signifies the end of the Assembly statements
– This is accepted by real assemblers and is required
• TON
– Takes a parameter that is the number of instructions to
trace
– Turn on tracing
– On by default
• TOFF
– Turn off tracing
• $XQT
– Must be in column 1
– Signifies the beginning of data from the input
• EOF
– Terminates the pseudo file after $XQT
Copyright 2004-2005 Curt Hill
Example
• See first BALSX listing
• Examine and trace this execution
Copyright 2004-2005 Curt Hill