Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS 020 Assembly Programming

Similar presentations


Presentation on theme: "CIS 020 Assembly Programming"— Presentation transcript:

1 CIS 020 Assembly Programming
Chapter 18 - Sub-routines and Sub-program Linkage 5/27/2012 © John Urrutia 2012, All Rights Reserved.

2 Objectives Understand the Types of Subroutines
Describe how to create and invoke Subroutines Describe how communications with Subroutines work Describe the differences and similarities between Subroutines and Subprograms Demonstrate understanding of Subprogram Linkage and Communications 5/27/2012 © John Urrutia 2012, All Rights Reserved.

3 Subroutines Generally a block of instructions that perform a specific function needed from several points within a program. Provides storage efficiency by creating the specific function once and “Calling” that function from wherever it is needed. Subroutines are identified by a label at their entry point and generally terminate with a BR instruction 5/27/2012 © John Urrutia 2012, All Rights Reserved.

4 All needed instructions
Subroutines Entry Point Designated Flowchart symbol Subroutine CALL Subroutine All needed instructions Return to CALL 5/27/2012 © John Urrutia 2012, All Rights Reserved.

5 Two Types of Subroutines
Internal – Written specifically for this program for use anywhere in this program. Relies on the supporting environment provided by the main program. Generally, must be within the address range of the current base register. 5/27/2012 © John Urrutia 2012, All Rights Reserved.

6 Two Types of Subroutines
External – Written as an independent stand-alone set of reusable code that can be added anywhere into a program. Generally stored in a system library and copied into your program via a copybook or MACRO. 5/27/2012 © John Urrutia 2012, All Rights Reserved.

7 Subroutine LINKAGE To utilize subroutines
You must address the subroutine entry point You must address the next instruction to execute after the subroutine completes. Linkage between the main routine and subroutines Use special branch instructions – BAL & BALR Use the branch register to return to caller– BR 5/27/2012 © John Urrutia 2012, All Rights Reserved.

8 Subroutine LINKAGE BAL – Branch and Link
Stores the Address of the instruction following the BAL in the Register of Operand 1 Then Branches to the Address of Operand 2 5/27/2012 © John Urrutia 2012, All Rights Reserved.

9 Subroutine LINKAGE BAL – Branch and Link
Use caution – inadvertently changing the contents of the register in Operand 1 will have unpredictable results!!! What do I do if I need to use this register?? Upon entry to the subroutine – Store the Register using the ST instruction Create a 4 Byte storage area for this purpose. 5/27/2012 © John Urrutia 2012, All Rights Reserved.

10 Subroutine LINKAGE BALR – Branch and Link Register
This instruction is primarily used for calling external subroutines / subprograms. Stores the Address of the instruction following the BALR in the Register of Operand 1 Then Branches to the Address of Operand 2 5/27/2012 © John Urrutia 2012, All Rights Reserved.

11 Subroutine LINKAGE Program Housekeeping
Keeping track of where we are and where we’re going Standard Register Linkage Conventions R1 – Address of the list of data addresses R13 – Address of Calling Program’s Register Save Area R14 – Address of Calling Program’s Next Instructions R15 – On Entry – Called Program’s Entry Point Address On Exit – Called Program’s Return Code 5/27/2012 © John Urrutia 2012, All Rights Reserved.

12 5/27/2012 © John Urrutia 2012, All Rights Reserved.

13 RR – Register to Register
RR – are the fastest instructions. 2 Byte instruction Length with the coding format Translates to B' ' X' 1 C ' 5/27/2012 © John Urrutia 2012, All Rights Reserved.

14 RS – Register to Storage
RS – Transfer data between a register and storage. 4 Byte instruction Length with the coding format Translates to B' ' X' E C D C' 5/27/2012 © John Urrutia 2012, All Rights Reserved.

15 RX – Register to Indexed Storage
RX – Transfer control by mask to storage address . 4 Byte instruction Length with the coding format Translates to B' ' X' F E 8' 5/27/2012 © John Urrutia 2012, All Rights Reserved.

16 RX – Register to Indexed Storage
RX – Transfer data between a register and storage. 4 Byte instruction Length with the coding format Translates to B' ' X' E 8' 5/27/2012 © John Urrutia 2012, All Rights Reserved.

17 SI – Storage Immediate SI –Data imbedded in instruction to storage.
4 Byte instruction Length with the coding format Translates to B‘ ' X' F E 8' 5/27/2012 © John Urrutia 2012, All Rights Reserved.

18 Storage to Storage Instructions
Least efficient instructions SS Formats 5/27/2012 © John Urrutia 2012, All Rights Reserved.

19 SS – Storage to Storage SS – Storage to Storage, Character Format
6 Byte instruction Length with the coding format Translates to B‘ ' X' D F F C ' 5/27/2012 © John Urrutia 2012, All Rights Reserved.

20 SS – Storage to Storage SS – Storage to Storage, Packed Decimal Format
6 Byte instruction Length with the coding format Translates to B‘ ' X' F C ' 5/27/2012 © John Urrutia 2012, All Rights Reserved.

21 SS – Storage to Storage SS – Storage to Storage, Shift Packed Decimal Format 6 Byte instruction Length with the coding format Translates to B‘ ' X' F C ' 5/27/2012 © John Urrutia 2012, All Rights Reserved.

22 Program Interrupts & the PSW
Program interrupts occur when you tell the system to do something it can’t. Old School – System simply stops working Today – System is built with redundancy and continues to work while suspending your program execution When an interrupt occurs, generally your program is terminated with an appropriate system code. There are 5 types of interrupts 5/27/2012 © John Urrutia 2012, All Rights Reserved.

23 Program Interrupts & the PSW
There are 5 types of interrupts External – caused by an action outside of the system. I/O problem – external or internal associated with I/O subsystem Program – caused by a faulty instruction or address Machine – hardware, faulty circuit or equipment Supervisor – caused by an error detected by the Supervisor Program. 5/27/2012 © John Urrutia 2012, All Rights Reserved.

24 Program Interrupts & the PSW
The PSW – Program Status Word Identifies the state of the system at the time the interrupt occurred. z390 PSW Consists of the following information PSW= FFFDA D D088 MVC ABEND S0C5 5/27/2012 © John Urrutia 2012, All Rights Reserved.


Download ppt "CIS 020 Assembly Programming"

Similar presentations


Ads by Google