1 / 50

Course Details

Course Details. Audience This course discusses how to build over the basic Assembler Language skills and thus aims at application programmers. It is also applicable for Assembler programmers who wish to extend their knowledge of

mohawk
Télécharger la présentation

Course Details

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Course Details • Audience • This course discusses how to build over the basic Assembler Language skills and thus aims at application • programmers. It is also applicable for Assembler programmers who wish to extend their knowledge of • programming techniques. Those who have programmed in Assembler in a non-MVS environment, and wish • to learn the input/output and debugging facilities of MVS, will also find this course useful. • Prerequisites • The learner should have completed Assembler Language Intermediate, or other equivalent training, and • should be able to program in a High Level Language. Introduction

  2. Course Introduction • The first unit, Looping, explains the basic instructions to implement the iterative loop structure, basic • functions of address arithmetic operations, and how to process arrays. • The second unit, Logical and Shift Instructions, explains the functions of Boolean algebra, functions • of Boolean and shifting instructions, and the function of the Test Under Mask instruction. • The third unit, Modular Programming, explains the process in writing Assembler Language modules or exit • routines for insertion into complete programs. • The fourth unit, Creating a Complete Program, explains how to create a complete program and • understand the relationship of the modules to the complete program. • The fifth unit, Testing and Debugging, explains how to recognize and remove syntax errors, perform • debugging operations and read a symptom dump. introduction

  3. Course Objectives • At the end of this course, you will be able to: • Create loops with the Load Address (LA) and Branch on Count (BCT) instructions • Process arrays and other structured data • Perform Boolean and shift operations • Relate the condition code setting to bit testing • Use the Test Under Mask (TM) instruction to perform bit testing Continued… introduction

  4. Course Objectives (cont’d) • At the end of this course, you will be able to: • Write Assembler Language modules or exit routines for insertion to complete programs • Generate code to pass control and receive control, and to pass data and receive data • Use both fixed length and variable length parameter lists • Construct a complete Assembler Language program • Debug a program making use of the debugging macros of MVS Introduction

  5. UNIT Looping Topics: • The Iterative Loop • Address Arithmetic • Processing Arrays

  6. Unit: Looping Unit Introduction • In designing and writing Assembler language programs, one is often faced with a need to repeatedly execute • the same sequence of machine instructions. Looping is a technique that is used to do this. • This unit examines common looping techniques along with examples of application situations where looping • is useful. Introduction

  7. Unit: Looping Unit Objectives • At the end of this unit, you will be able to: • Use basic instructions to implement the iterative loop structure • Perform basic address arithmetic operations • Understand how to process Arrays Introduction

  8. UNIT Looping Topics: • The Iterative Loop • Address Arithmetic • Processing Arrays

  9. Topic: The Iterative Loop Unit: Looping Topic Objectives • At the end of this topic, you will be able to: • Define iterative loop • Demonstrate iterative looping • Demonstrate Branch on Count (BCT) instructions Introduction

  10. Topic: The Iterative Loop Unit: Looping Uses of Iterative Structure • What is looping? • Looping is a coding technique that enables to • repeatedly execute the same sequence of machine • instructions. • What is an iterative loop? • Unlike situations where the end condition is unknown until execution time, an iterative loop is coded when its known how many times the loop is needed. • The example shows processing of an array with one entry for each month. Array Next Entry Process Month1 Month2 . . . . Month12 Result < Compare Counter Loop = Store Results Continued… Concepts

  11. Topic: The Iterative Loop Unit: Looping Uses of Iterative Structure (cont’d) • How is an iterative loop built? • Iterative loop structure can be built by using a counter and a comparison followed by a Branch on Condition. • The example shows the code used to process the array of 12 months. LH R3,=H’1’ Initialize counter to 1 MTHLOOP EQU * * Process data for * month number * which is in R3 AH R3,=H’1’ Increment month number CH R3,=H’12’ Have you processed all the months BNH MTHLOOP No Concepts

  12. Topic: The Iterative Loop Unit: Looping Are We On Track? • For an iterative loop, which of the following describes the point when the number of iterations are first known? • A. When the program is designed and written • B. When the program is assembled • C. When the program is linked • D. When the program is executed Review

  13. Topic: The Iterative Loop Unit: Looping Are We On Track? • Add the extended mnemonic to complete the following code, to sum daily data for the period of one week. • LH R5,=H’1’ • PROCDAY EQU * • . Code to process • . a day’s • . data • AH R5,=H’1’ • CH R5,=H’7’ • ______ PROCDAY Review

  14. Topic: The Iterative Loop Unit: Looping Branch on Count • What is Branch on Count? • The Branch on Count (BCT) instruction is designed to handle iterative looping. • One is subtracted from the first operand register and the result is saved in the register. If the result is zero, then normal instruction sequencing occurs at the instruction, following BCT. If the result is non-zero, the main storage address specified by the second operand replaces the next instruction address in the PSW. • If second operand is 0 (zero), no branching occurs and execution continues with the next instruction. Branch on Count (BCT): RX Format - Register and Indexed Storage BCT R6,LOOP Loop Counter Register Branch Address (Main Storage) R6 • Reduces the counter by 1 each time program loops • Falls through to next instruction when counter reaches 0 10 Counter CC Setting - Condition Code is Unchanged Continued… Concepts

  15. Topic: The Iterative Loop Unit: Looping Branch on Count (cont’d) • How is a BCT used? • Using BCT involves the following steps: • Immediately before the body of the loop, load a General Purpose Register (GPR) with the number of times the loop needs to be executed • Code the body of the loop, with the last instruction being a BCT, using the initialized register and the address at the start of the loop • The code on the right shows how monthly • processing is repeated 12 times using BCT. LH R3,=H’12’ Loop count for 12 months MTHLOOP EQU * * * Process data for Month 13- (value in R3) BCT R3,MTHLOOP Continued… Concepts

  16. Topic: The Iterative Loop Unit: Looping Branch on Count (cont’d) • What happens when BCT does not branch? • The fact that BCT does not branch when its second operand is 0, allows it to be used as a way to subtract one from a register with no literal value needed. • That means, instead of using the following code: • SH R7,=H’1’ • Use: • BCTR R7,0 • The only difference between these two codes is that the BCTR cannot cause overflow and it will not set the condition code. SH R7,=H'1' Code subtracts the Literal Value 1 from the contents of R7, (requires 2+4=6 bytes) BCTR R7, 0 Code does not branch when the 2nd Operand is 0, allowing it to subtract 1 from R7, (requires 2 bytes) Concepts

  17. Topic: The Iterative Loop Unit: Looping Are We On Track ? • Code the LH instruction to initialize the register used with BCT, for the following code to sum daily data for seven days of a week. • ___________________________ • PROCDAY EQU * • * process one day’s data • . • . • . • BCT R4,PROCDAY Review

  18. Topic: The Iterative Loop Unit: Looping Are We On Track ? • What is the final decimal value in R7, after the following segment is executed? • LH R7 ,=H’10’ • BCTR R7 ,0 • AR R7 ,R7 • BCTR R7 ,0 • ______________ Review

  19. Topic: The Iterative Loop Unit: Looping Glossary • Looping – A program function, where a set of statements in a program execute repeatedly, either a fixed number of times, or until some condition is true or false. • Iterative Loop – A process that occurs when a statement in a program causes the program to • repeat one or more statements. Examples of iterative statements in High Level Languages are: FOR,DO,REPEAT…UNTIL and DO…WHILE. • Array – A list of data values, all of the same type, any element of which can be referenced by indexing or address modification. Arrays are part of the fundamentals of data structures, which in turn are major fundamentals of computer programming. • Counter – In programming, a variable used to keep count. • Comparison – The process in which two fields are checked so as to determine which is larger or if they are equal. In a program, the outcome of a compare operation often determines which of two actions is taken next. • Branch on Condition – An Assembly instruction that transfers control to another instruction, based on some condition (that is, it transfers if a specific condition is true or false). Continued… Glossary

  20. Topic: The Iterative Loop Unit: Looping Glossary (cont’d) • Operand – The object of a mathematical operation or a computer instruction. • GPR – A General Purpose Register (GPR) is used for addressing, binary arithmetical operations and other purposes. There are 16 GPRs inside the process. • Overflow – Generally, the condition that occurs when data resulting from processing requires more bits than have been provided in hardware or software to store the data. • Condition Code – A two bit field in the Program Status Word (PSW) which is set by some machine instructions to indicate their results. For example, Arithmetic instructions set the condition code to indicate if their result is positive, negative, zero or overflow. Glossary

  21. Topic: The Iterative Loop Unit: Looping Topic Summary • Now that you have completed the topic, you should be able to: • Define iterative loop • Demonstrate iterative looping • Demonstrate Branch on Count (BCT) instructions Summary

  22. UNIT Looping Topics: • The Iterative Loop • Address Arithmetic • Processing Arrays

  23. Topic: Address Arithmetic Unit: Looping Topic Objectives • At the end of this topic, you will be able to: • Define and describe address arithmetic • Demonstrate load address instruction • Identify the limitations of address arithmetic Introduction

  24. Topic: Address Arithmetic Unit: Looping Address Arithmetic • While processing arrays in a loop, each iteration of the loop processes a different element of the array. The Assembler programmer must adjust the address of the current element each time through the loop. • The process of manipulating the addresses of data is called address arithmetic. • The most important instruction used in writing address arithmetic is the Load Address (LA) instruction. • The address of the second operand is placed in the first operand location. The condition code is unaltered. Load Address (LA): RX Format - Register and Indexed Storage LA R4,ARRAY 2nd Operand (Base Displacement) 1st Operand R4 ARRAY Contents Address LA Replaces Contents of R4 with Address at location ARRAY CC Setting - Condition Code is Unchanged Concepts

  25. Topic: Address Arithmetic Unit: Looping Load Address Instruction • What is the difference between Load and Load Address? • In both cases, the effective address of the second operand is calculated by adding the displacement to the sum of the contents of the base, and index registers. But in the case of Load Address, the effective address is placed in the GPR specified by the first register. For Load, the contents of the effective address are placed into the GPR, specified by the first operand. • Load makes a storage reference, while Load Address does not. • Example: LA R4,ARRAY • The address of the storage location ARRAY is placed into R4. LA R4,ARRAY L R4,ARRAY Calculate Effective Address – Sum Of Displacement, Base, and Index Storage Contents Of Effective Address In Storage Continued… Concepts

  26. Topic: Address Arithmetic Unit: Looping Load Address Instruction (cont’d) • How effective addresses are formed? • For an RX format instruction, like Load Address, adding the displacement, contents of the base register, and the contents of the index register, forms the effective address. • If either or both of the base and index registers specify R0, then that component is not used in address formation. LA R3, 10 LA R3, 10(,R4) LA R3, 10(R4) LA R3,10(R4,R5) No Base or Index No Index No Base Both Base and Index Concepts

  27. Topic: Address Arithmetic Unit: Looping Are We On Track? • Match the instruction on the left with its use on the right. • 1. L A. Places the address specified by the second operand in the first operand register • 2. LH B. Places the fullword at the location specified by the second operand in the first operand register • 3. LA C. Places the halfword at the location specified by the second operand in the first operand register Review

  28. Topic: Address Arithmetic Unit: Looping Are We On Track? • What is the effective address of the second operand of the following instruction? • LA R4,8 • _______________ Review

  29. Topic: Address Arithmetic Unit: Looping Address Arithmetic • What does address arithmetic deal with? • Address arithmetic deals with storage addresses, which are non-negative integers less than the maximum • storage size. • In BC mode, the address arithmetic deals with numbers in the range of 0- 16,777,215. • In EC mode, the maximum number in address arithmetic is 2 ³¹ – 1 Continued… Concepts

  30. Topic: Address Arithmetic Unit: Looping Address Arithmetic (cont’d) • What are the uses of load address? • Load address can be used for the following purposes: • It can be used for placing the address of a named storage area into a register • It can be used to initialize a register • Example: • To place the value 10 into R5, instead of using: LH R5,=H’10’ • Use, LA R5,10 • To add 5 to the contents of R7, instead of using: AH R7,=H’5’ • Use, LA R7,5(,R7) Concepts

  31. Topic: Address Arithmetic Unit: Looping Address Arithmetic: Example • In the example, the effective address is formed by adding the basic contents of the base register R7 and the displacement 5. • The result is placed in the first operand R7. • The effect is to add 5 to R7. • What are the limitations of address arithmetic? • Following are the limitations of address arithmetic: • Displacementsmust be in the range 0-4095 • The arithmetic must deal with non-negative integers less than the storage size, for address arithmetic to work Comma Indicates Index Register is not specified Displacement Base Register LA R7,5(,R7) R1 D2 X2 B2 1st Operand 2nd Operand Basic Instruction Format: OP R1,D2,(X2,B2) Concepts

  32. Topic: Address Arithmetic Unit: Looping Are We On Track? • Which of the following are valid Assembler instructions? • A. LA R3,-5 • B. LA R3,1000 • C. LA R3,100(R3) • D. LA R3,100(,R3) Review

  33. Topic: Address Arithmetic Unit: Looping Are We On Track? • Code a LA instruction to add 25 to the value in R7. • ____________________________________________ Review

  34. Topic: Address Arithmetic Unit: Looping Glossary • Address Arithmetic – Performing arithmetic operations on storage addresses. An example is adding the length of an array element to an element address to get the address of the next element. • Address – To reference a particular storage location. • Contents – The value contained at a specified storage location. • Storage Reference – A reference to a storage location within an Assembler or Machine Language instruction. • Format – In general, the structure or appearance of a unit of data. • Integer – A positive or negative whole number, such as 37, 50 and 364. • Displacement – The number of bytes beyond the location specified in the base register, where the storage address is located. Glossary

  35. Topic: Address Arithmetic Unit: Looping Topic Summary • Now that you have completed the topic, you should be able to: • Define and describe address arithmetic • Demonstrate load address instruction • Identify the limitations of address arithmetic Summary

  36. UNIT Looping Topics: • The Iterative Loop • Address Arithmetic • Processing Arrays

  37. Topic: Processing Arrays Unit: Looping Topic Objectives • At the end of this topic, you will be able to: • Define and describe an array • Demonstrate RX format to process arrays • Demonstrate other formats to process arrays Introduction

  38. Topic: Processing Arrays Unit: Looping Defining Arrays • An array is a repetitive data structure, consisting of multiple elements of some base type. • In the example shown to record a a company’s gross sales for each day in January, an array of 31 fullwords, or 31 packed decimal numbers have been used. Fixed-Point Array: FDSALES DS 31F Array of 31 Fullwords Packed Decimal: PDSALES DS 31PL4 31 Packed Decimal Fields of Length 4 Continued… Concepts

  39. Topic: Processing Arrays Unit: Looping Defining Arrays (cont’d) • The example shows how to create an array of constants. It shows an array to hold the number of days in each • month of a common (not a leap) year. • Here a duplication factor has not been specified. Rather, by defining twelve constants, the Assembler has • been told that the array has 12 elements. DAYSINMTH DC H‘31,28,31,30,31,30,31,31,30,31,30,31” 12 Constants – Each Being a Halfword 31 28 31 30 31 30 31 31 30 31 30 31 Main Storage – 12 Elements Concepts

  40. Topic: Processing Arrays Unit: Looping Are We On Track? • Code the definition for an array called PAY, to hold 12 monthly pay amounts, each represented as a 5 byte packed number. Review

  41. Topic: Processing Arrays Unit: Looping Logic Structure for Array Processing • There are two techniques in array processing. They are: • Technique 1: RX Format • Technique 2: other formats • What is the first technique? • In the first technique, only RX instructions are used. • A symbol is used to point to the first element of the array and an index register is varied to select each specific element. Technique 1: RX Format Symbol (Base – Displacement) Points to the Beginning +4 0 +8 +12 +16 +20 Index Varied to Select Elements Continued… Concepts

  42. Base(Initially Point) Change Base To Select Elements 0 +8 +12 +16 +20 +4 Topic: Processing Arrays Unit: Looping Logic Structure for Array Processing (cont’d) • What is the second technique? • The second technique uses instruction types other than RX to process array elements. • Here an LA is used to load a base register to initially point to the first array element. As moving from element to element, the base register is modified. Technique 2: Other Formats Continued… Concepts

  43. Topic: Processing Arrays Unit: Looping Logic Structure for Array Processing (cont’d) • Example of Technique 1 • Suppose you need to calculate the total sales for January, assuming daily sales were in the elements of the array. • The example shows the code to sum the elements of this array. • When this loop completes execution, the total of the 31 elements will be in R3. Total Sales Array: FDSALES DS 31F Code To Sum The Elements: Zero sum Zero index Set loop counter for 31 iterations Add next array element Increment Index for next element SR R3,R3 SR R4,R4 LA R5,31 FLOOP EQU * A R3,FDSALES(R4) LA R4,4(,R4) BCT R5,FLOOP Zero sum Zero index Set loop counter for 31 iterations Add next array element Increment Each array element is accessed by specifying the name of the array, followed by the index register in parentheses. Continued… Concepts

  44. Topic: Processing Arrays Unit: Looping Logic Structure for Array Processing (cont’d) • Example of Technique 2 • In the given example the daily sales are stored as an array of packed decimal numbers. • The example shows the code to sum this array into a packed field. Daily Sales Array: PD SALES DS 31PL4 Code To Sum The Elements: CODE TO SUM THE ELEMENTS: ZAP JANSALES,=P’0’ LA R4,PDSALES LA R3,31 PLOOP EQU * LA R4,4(,R4) BCT R5,PLOOP Zero sum Point to first element Set loop counter for 31 iterations Add next array element Increment base for next element AP JANSALES,0(4,R4) Continued… Concepts

  45. Topic: Processing Arrays Unit: Looping Logic Structure for Array Processing (cont’d) • Example of Technique 2 • Here, character strings are represented as strings of characters terminated by a null character. • The example shows how this technique 2 of array processing is used in calculating the length of C-type string at location STRING. Array Processing: Point to start of string End of string? Yes No- point to next character and continue search Points to end of string here Address of string start R3 has string length LA R3,STRING SLOOP EQU * CLI 0(R3),X’00’ BE NULLFND LA R3,1(,R3) B SLOOP NULLFND EQU * LA R4,STRING SR R3,R4 Concepts

  46. Topic: Processing Arrays Unit: Looping Are We On Track? • Complete the missing instruction in this code to add 12 monthly pay amounts, stored in PAYS. • ZAP TOTPAY,=P’0’ • LA R4,PAYS • LA R3,12 • LOOP EQU * • ______________________________________ • LA R4,5(,R4) • BCT R3,LOOP • . • . • PAYS DS 12PL5 • TOTPAY DS PL7 Review

  47. Topic: Processing Arrays Unit: Looping Are We On Track? • Order the last five instructions to sum the elements of a 100-element halfword array. • A. SR R3,R3 • B. SR R4,R4 • C. AH R3,HWDARRAY(R4) • D. LOOP EQU • E. LA R4,2(,R4) • F. LA R5,100 • G. BCT R5,LOOP Review

  48. Topic: Processing Arrays Unit: Looping Topic Summary • Now that you have completed the topic, you should be able to: • Define and describe an array • Demonstrate RX format to process arrays • Demonstrate other formats to process arrays Summary

  49. Unit: Looping Unit Summary • Now that you have completed the unit, you should be able to: • Use basic instructions to implement the iterative loop structure • Perform basic address arithmetic operations • Understand how to process Arrays Summary

More Related