System 360 assembly language continued

Download Report

Transcript System 360 assembly language continued

System 360 Assembly
Language
More Instructions
Copyright 2004-2007 Curt Hill
More arithmetic
• The multiply was particularly
interesting
• One of the values to multiply was
loaded into an odd register
• The multiply specified the even
register
• For example:
• L 5,X
• M 4,y
• The result was in both register 4 and
5 and overflow was not possible
Copyright 2004-2007 Curt Hill
Divide
• The divide was also memorable
• The numerator was put in an even
odd register pair
• Then division occurred
• The quotient remained in the odd
and the remainder in the even
• Thus the quotient and remainder
were obtained all at once
Copyright 2004-2007 Curt Hill
BALSX Multiply and Divide
• BALSX simplifies the multiply and
divide with the instruction MI DI (and
MIR, DIR)
• The MI/DI acts like Add and Subtract
with the first register only a single
register
Copyright 2004-2007 Curt Hill
Subroutine linkage
• There are many conventions
regarding subroutines that need to
be considered
• A subroutine call is different than a
branch
– Why? Because we need to be able to
return
– Where is the return address kept?
– In a register.
Copyright 2004-2007 Curt Hill
BAL
• BAL (Branch And Link) or a BALR
(Branch And Link to Register)
• The BALR is commonly used for
things outside of this control section
and BAL for things in this control
section
• Suppose a subroutine has name XYZ
Copyright 2004-2007 Curt Hill
Call of internal subroutine
• BAL 14,XYZ
• The return address is placed in 14 and
XYZ is the next instruction to be executed
• Since XYZ starts with the return address
in register 14 it will return to caller by:
• BCR 15,14 or
• BR 14
– These are the RR versions of BCR
• In theory any register may hold the return
address
– In practice register 14 was the standard
favorite
Copyright 2004-2007 Curt Hill
External subroutines
• We could not use the BAL for an external
name because that name was not known
at assembly time
• Therefore what was done is use a V type
constant:
– Extaddr
DC V‘extsubr’
• The V constant was the address of an
external subroutine
• As such it must be an absolute symbol
• Thus the linker and loader had to fill it in
when the program was executed
Copyright 2004-2007 Curt Hill
External subroutine call
• L 15,extaddr
• BALR 14,15
– 15 held the target address and 14 the return
address
• It is the subroutines responsibility to
guarantee that all registers are preserved
• At entry:
–
–
–
–
It saved registers in the users save area
It gained addressability if it was external
It created its own save area
It linked the save areas
• At exit
– It restored registers
– Branched to return address
Copyright 2004-2007 Curt Hill
Memory Spaces
• Before virtual memory things were
somewhat different
• A large multitasking machine could
have several programs running at
the same time
• For the 360 this was usually about 24 user programs besides the OS
– For 370 4-12 programs
• The architecture was designed to
make relocation easy
Copyright 2004-2007 Curt Hill
Relocation
• Each unit had code and data
– This was before data was most
commonly put on the stack
• These subroutines could be loaded
in any order and in any location of
memory
• The subroutine needed to be able to
gain addressability regardless of
location
Copyright 2004-2007 Curt Hill
Addressability
• An operand was addressable if a
base register and offset could be
formed that addressed the location
– Either data or code
• This was done in a unique way
• The BALR instruction was given but
no branch occurred
• This address was then used to
calculate offsets
Copyright 2004-2007 Curt Hill
Addressability Sequence
• Two lines:
BALR 12,0
Using 12,*
• The BALR put the current address in
register 12
– This would normally be used for a
subroutine call
– Specifying zero meant do not call
Copyright 2004-2007 Curt Hill
Addressability (cont)
• The Using told the assembler to
calculate base and offsets
• The 12 indicated to use 12 as the
base register
• The * told it to use the current
location as the place from which all
offsets were calculated
– A pseudo zero
Copyright 2004-2007 Curt Hill
S360 Entry Conventions
STM 14,12,12(13) Save
BALR 12,0
get adr in 12
USING *,12
make 12 base
* Not until last instruction may named
* items be used
LA 15,Save
Save area addr
ST 15,8(13)
Forward link
ST 13,Save+4
Back link
LR 13,15
R13 is ready
* Program goes here
L
13,Save+4
Restore user’s 13
LM 14,12,12(13) Restore users regs
BR 14
Return
Copyright 2004-2007 Curt Hill
Addressability Notes
• The STM used 4 bytes and BALR
each used 2 bytes
• Thus register 12 would be loaded
with the entry point plus 6 bytes
• All named locations would be then
an offset past register 12
• Each offset would be 6 bytes less
than the location given in the left
• Thus if A was at location 0010C the
base offset pair
would be: C106
Copyright 2004-2007 Curt Hill
Save area Notes
• The 360/370 did not have a stack
– A very convenient place to save things
• Thus each routine created a save
area of 18 full words
• The called routine would store the
caller’s registers in that area so they
would be the same when the routine
returned
• There was an elaborate convention
for the save area
Copyright 2004-2007 Curt Hill
Save Area Conventions
• Register 13 always pointed at the
save area
• Register 14 usually was the return
address
• Register 1 usually pointed at a
parameter list
• The save areas were made into a
doubly linked list
• So it was possible to move forward
or backwardCopyright
through
the links
2004-2007 Curt Hill
Locations
•
•
•
•
•
The first three words were linkage
First word was reserved for PL/I
Second word pointed forward
The third word pointed backward
The last 15 locations were the
registers 14 through 12
Copyright 2004-2007 Curt Hill
S360 Entry Conventions
STM 14,12,12(13) Save
BALR 12,0
get adr in 12
USING *,12
make 12 base
* Not until last instruction may named
* items be used
LA 15,Save
Save area addr
ST 15,8(13)
Forward link
ST 13,Save+4
Back link
LR 13,15
R13 is ready
* Program goes here
L
13,Save+4
Restore user’s 13
LM 14,12,12(13) Restore users regs
BR 14
Return
Copyright 2004-2007 Curt Hill