1 / 35

At its very core, a computer is capable of only performing 2 things: ADD COMPARE

At its very core, a computer is capable of only performing 2 things: ADD COMPARE We have already discussed some of the arithmetic, let’s look at the logical operations. Compare Packed Decimal. Compare two packed decimal fields: CP M1(L1),M2(L2) Compare first field to second field

obelia
Download Presentation

At its very core, a computer is capable of only performing 2 things: ADD COMPARE

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. At its very core, a computer is capable of only performing 2 things: • ADD • COMPARE • We have already discussed some of the arithmetic, let’s look at the logical operations

  2. Compare Packed Decimal • Compare two packed decimal fields: • CP M1(L1),M2(L2) • Compare first field to second field • Set a condition codebased on results • M1(L1) = M2(L2) • M1(L1) > M2(L2) • M1(L1) < M2(L2) • Then test the condition code • Maybe you remember that the condition code is located within the PSW

  3. 4 bits located within the processor (PSW bits: 18-19) Condition Code

  4. So How Do You Test CC? • Branch-on-Condition Instruction

  5. So How Does It Work? • Compare Mask and CC • If corresponding bits are both 1, then Branch to address in Operand 2 • If corresponding bits are not 1, then fall through to the next instruction (don’t Branch) CP TC-HRS,40HRS BC 2,CALC-OT * or BH CALC-OT In the example, Time-Card Hours Worked is compared to 40 Hours. If Time-Card Hours is greater than 40 Hours, then Branch to Calculate Overtime Pay. If Time-Card Hours is not greater than 40, fall through to the instruction following the BC. Of course, the field names have also been defined … 40HRS DC PL2’40’ TC-HRS DS CL2

  6. Another Example FIELDA FIELDB 00 01 23 45 67 8C 00 08 76 54 32 1C CP FIELDA,FIELDB BC 8,SAME (BE) BC 4,LOWER (BL) BC 2,HIGHER (BH) LOWER Which Branch is taken? ______________

  7. Now, that more or less takes care of COMPARE … Let’s Take a Look at the ADD side of a processor • Of course, it seems that a computer can do more than just ADD and COMPARE. There are instructions that let you Subtract, Multiply, and Divide as well. • However, the processor converts Subtract, Divide, and Multiply into an ADD, then performs the arithmetic. Multiply is simple: just perform addition of the values by the number of times of the multiplier. • Subtraction and Division are a little more complicated. First, the value being added needs to be converted into its twos-complement form, then the numbers are added (or for Division, added the number of times of the value of the divisor. • All of this has very little importance to us.

  8. Packed Decimal Numbers • Manipulating numbers in their decimal format is generally used for those numbers that are read into memory from an external source. These values are always read-in in their zoned-decimal format. They are characters: a single byte per character. The numbers appear as a string of characters, such as ‘F1F2F3F4F5F6F7F8F9F0’. • These numbers are characters and, therefore, cannot be manipulated. • They must be converted from zoned-decimal to packed-decimal. They would appear without their zone character ‘1234567890F’ or ‘1234567890C’ in memory. To accomplish this necessary change in the look of the numbers, use the PACK instruction, such as: PACK PACKNO,ZONENO

  9. PACK Instruction In machine format, PACK is an SS-type instruction (memory-to-memory) ‘F2’ is the op-code and is 1 byte in length. L1 and L2 represent the length (in bytes) of each of the operands in memory. They do not need to be the same length. Each pair of B1D1 and B2D2 are the two memory locations. In the PACK instruction example on the prior slide, B1D1 is the PACKNO field and B2D2 is the ZONENO field. When executed, the format of the B2D2 (ZONENO) operand is changed from zoned to packed, and the result is placed in the B1D1 (PACKNO) operand.

  10. PACK Instruction As the zoned value of the B2D2 operand is converted to packed, the numeric bits of each byte are treated as a digit and the zoned bits are ignored, except the zoned bits in the rightmost byte, which are treated as a sign. The sign and digits are moved unchanged to the first operand and are not checked for validity. If the B1D1 field is larger than needed, zeros will pad to the left. If B1D1 is too small, truncation takes place on the left. Assume, in the prior slide’s example, that ZONENO is 8 bytes and PACKNO is 6 bytes. (PACK PACKNO,ZONENO) PACKNO DS CL6 ZONENO DC CL8’24681357’ ZONENO Contents: ‘F2F4F6F8F1F3F5F7’

  11. When the PACK instruction has executed … PACK PACKNO,ZONENO The result of the instruction’s execution is the 6-bytes (padded with zeros) that you can now use for decimal arithmetic. The right-most character (‘C’) is the positive sign character (it may also be ‘F’). The character ‘D’ identifies a negative value. You need to be careful in determining the proper length for the B1D1 operand. Note: PACK does not set the cond. Code.

  12. ADD packed decimal numbers The second operand (B2D2) is added to the first operand (B1D1), and the resulting sum is place at the first operand location. Operands are in packed-decimal format before and after execution. The addition is algebraic and takes into account the value of the sign bits. If the first operand is too short to contain the sum, a decimal overflow occurs (cond.code = 3). If B1D1 is longer than the length needed, padding is done with leading zeros. Example on the next slide 

  13. Add Packed Instruction Example Assume that the sign, packed-decimal number at location ADDER (4 bytes) is to be added to the signed, packed-decimal number at location ADDEND (3 bytes). For this example, also assume that R12 points to ADDEND and R13 points to ADDED. AP ADDEND(3),ADDER(4) - or – AP 0(3,12),0(4,13) Note that the signs are different. In effect, the values are subtracted. There is no overflow since the sum fits in the first operand location. Condition code is set to 2: result is greater than 0.

  14. Zero and Add Pack Instruction (ZAP) The second operand is placed at the first operand location. This is the equivalent of an add to zero. All operands are in packed decimal format. The condition code is set: 0 = result is zero, 1 = result is negative, 2 = result is positive, 3 = overflow. Examples follow a little later is this slide presentation.

  15. Subtract Packed Instruction Subtract is very similar to Add, except that the result is different. The second operand (B2D2) is subtracted from the first operand (B1D1) and the resulting difference is placed at the first-operand location (B1D1). The operands and results are in packed-decimal format. Example on the next slide 

  16. Subtract Packed Instruction Example 00303C FB21 404A 4048 25 SUBTR1 SP P2,P1 P2= 04 44 4C 003042 FB11 4048 4048 26 SUBTR2 SP P1,P1 P1= 00 0C * : 003048 123C 28 P1 DC P’123’ P1= 12 3C 00304A 04567C 29 P2 DC P’4567’ P2= 04 56 7C SUBTR2 clears a field to zeros. Subtracting a field from itself, as in SUBTR2, is more efficient but requires valid packed data in operand 1. SP sets the condition code: 0 = result is 0, 1 = result is negative, 2 = result is positive, 3 = result overflow.

  17. Multiply Packed Instruction The product of the first operand (multiplicand) and the second operand (multiplier) is placed at the first operand location. All operands are in packed decimal format. The multiplier length cannot exceed 15 digits (L2 cannot be greater than 7) and must be less length than the multiplicand. The multiplicand must have at least as many bytes of leftmost zeros as the total number of bytes in the multiplier, otherwise the product will not fit when the instruction has executed. All values are packed decimal and the condition code is not set.

  18. Multiply Packed Example ZAP PRODUCT,MULTPLD 00 00 12 34 56 0C MP PRODUCT,MULTPLR 01 17 28 32 00 0C * : MULTPLD DC PL4’1234560’ MULTPLR DC PL2’950’ PRODUCT DS PL6 Recall that the ZAP instruction is like a Move, moving the second operand to the first operand assuming both fields are formatted as packed decimal. To the right of the two instructions (as comments) you can see the value of PRODUCT after each instruction executes. PRODUCT is defined as 6 bytes (the sum byte count of MULTPLR and MULTPLD lengths.

  19. Another Multiply Packed Instruction Example 50 * MULTIPLY, GENERATE 3 DECIMALS, ROUND: 51 * ------------------------------------- 52 ZAP WAGE,HRS 00 00 01 20 5C 53 MP WAGE,RATE 00 10 30 27 5C MULTIPLY 54 SRP WAGE,63.5 00 01 03 02 8C SHIFT/ROUND 55 * : 56 HRS DC P’120.5’ 01 20 5C 57 RATE DC P’8.55’ 85 5C 58 WAGE DS PL5 This example multiplies a 3-byte field, HRS, by a 2-byte field, RATE. The product, WAGE, is therefore defined as 5 bytes in length. Since HRS has one decimal and RATE has 2, the generated product has three implied decimal places. Because only two decimal places are required for dollars and cents, the unwanted rightmost digit is rounded. A Shift and Round Packed instruction (SRP) shifts the product one digit to the right, leaving two decimal places. To the right of the instructions, appearing as comments is the value of WAGE after each instruction executes.

  20. Divide Packed Decimal Instruction Aren’t all these packed-decimal instructions beginning to look alike? Unfortunately the Divide instruction is a little more complicated than the others. The first operand (B1D1), which is the dividend, is divided by the second operand (B2D2) and divisor. The resulting quotient and remainder are placed at the first operand location. All values must be packed decimal format. The quotient is placed in the leftmost portion of the first operand. The number of bytes in the quotient is equal to the difference between the dividend and divisor lengths (L1-L2). The remainder is placed in the rightmost portion of the same operand and is the same length as the divisor. The condition code is not changed.

  21. A Typical Decimal Divide Instruction Example ZAP RESULT,DIVDND DP RESULT,DIVSOR * : DIVDND DS PL4 Dividend DIVSOR DS PL1 Divisor RESULT DS PL5 Quotient/Remainder In the typical situation, you do not know the values that are to be divided, so you plan for all possible situations. Divide by zero is not allowed, so your program will be abnormally terminated. The next worst case is when the divisor is one. This means that the quotient will equal (and cannot exceed) the value of the dividend. 1234567 / 1 = 1234567 Quotient = Dividend Dividend Divisor

  22. A Typical Decimal Divide Instruction Example A convention is to provide the length of the quotient equal at least to that of the dividend. In addition, the length of the remainder always equals that of the divisor. Therefore, you should define the operand 1 field to be a length of at least the dividend plus the divisor. The result will be padded to the left with leading zeros. Here is a more realistic example: ZAP RESULT,DIVDND 00 12 34 56 7C DP RESULT,DIVSOR 04 11 52 2C 1C * : DIVDND DC PL4’1234567’ Dividend DIVSOR DC PL1’3’ Divisor RESULT DS PL5 Quotient/Remainder Since DIVDND contains 4 bytes and DIVSOR contains 1 byte, RESULT should contain at least 5 bytes, although it may be longer. The ZPA instruction initializes the dividend in RESULT. After the DP, the first 4 bytes of RESULT contain the quotient, with its sign, and the fifth byte contains the remainder, with its sign. The reaminder is 1 byte, the same length as the divisor.

  23. Now that the decimal arithmetic is done, what’s next? Many times you have to provide for an implied decimal point, so you can use the following rule: The number of decimal places in a quotient equals the number in the dividend minus the number in the divisor. For example, if the dividend contains four decimal places, and the divisor contains one, then the quotient has three: dividend xx.xxxx divisor x.x = xx.xxx quotient

  24. And finally ? … UNPK Now that all the decimal arithmetic is done in our program, we have a result that is a packed decimal number. This number is not printable since it is not character numbers. So we need to convert the packed-decimal numbers to zoned-decimal numbers. For this, use the UNPK (unpack) instruction. UNPK is pretty much the opposite of the PACK instruction. The format of the second operand (B2D2) is changed from packed to zoned, and the result is placed at the first-operand location. Signs are placed in the first-operand location unchanged. Zone bits with ‘1111’ are supplied for all bytes except the rightmost byte which is the sign. Padding takes place to the left, truncation also takes place on the left. The condition code remains unchanged.

  25. UNPK instruction example UNPK ZONED,PACKED * : PACKED DC PL3’12345’ 12 34 5C ZONED DS ZL5 F1 F2 F3 F4 C5 On the right, UNPK reverses the PACKed sign ‘C’ and the digit ‘5’ in the receiving ZONEd field. All other digits are placed in the receiving filed with a zone of ‘F’. Now the receiving field is printable (except for the rightmost byte). To take care of the rightmost byte, you can use something like the OI (Or Immediate) instruction to change the sign field in the receiving field to an ‘F’. For the ZONED field above, this would appear as: OI ZONED+4,’F0’ The rightmost byte now is changed to ‘F5’ and will print as the digit 5.

  26. Input/Output Operations Connecting to external data(see page 90)

  27. Several Requirements • A file or data set (on a device) • An area of memory describing the data file being used (DCB) • The file must be “connected” to the program using it (OPEN/CLOSE) • An area in memory to stage the records being read or written (buffer) – usually defined by Define Storage (DS) and probably subdivided: BUFFER DS 0CL80

  28. Input/Output Operations OPEN identifies the DCB that describes the file being OPEN’d. To retrieve a record from the OPEN file, issue GET. Get identifies the DCB (GET from which file…) and identifies the buffer into which to GET the record. OPEN DCB1,INPUT ---- GET DCB1,DATA1 StartSTMOPENOPEN : :

  29. Order of an I/O Operation • Input file is available • Program OPEN’s the file – completes filling in DCB • Read (GET) the first record • O/S performs the request while program waits • Program is notified that operation has completed – I/O Interrupt • Program processes the record • Program loops through reading the records from the file • CLOSE the file when done – DCB EODAD=eof-rtn entry pt.

  30. AND In the Program OPEN dcbname:NXTREC GET dcbname,inarea: B NXTRECeofrtn CLOSE dcbname inarea DS CLnn dcbname DCB LRECL=nn,RECFM=F, MACRF=G,EODAD=eofrtn, DDNAME=filename

  31. Output Operation Example OPEN dcbname:NXTREC PUT dcbname,outarea: B NXTREC CLOSE dcbname outarea DS CLnn dcbname DCB LRECL=nn,RECFM=F, MACRF=G,DDNAME=filename There is no EODAD= parameter for an output DCB since an end-of-file condition doesn’t occur on output files.

  32. NOTE: When using PC/370 Emulator • PC sees data as ASCII • Mainframe sees data as EBCDIC • Data needs to appear on your PC as though it is mainframe data • So … • Before every OPEN, modify the DCB by coding: OI dcbname+10,X’08’ so PC sees data as EBCDIC

  33. BEGIN START REGS : *** OPEN FILES OI INDCB+10,X’08’ OPEN INDCB,INPUT OI OUTDCB+10,X’08’ OPEN OUTDCB,OUTPUT : LOOP GET INDCB,INBUFF ADD and more … PUT OUTDCB,OUTBUFF B LOOP *** DEFINE FILES INDCB DCB LREC=80,RECFM=F,EODAD=EOFRTN … OUTDCB DCB LREC=80,RECFM=F,MACRF=P … *** DEFINE BUFFERS INBUFF DS 0CL80 EMP# DS CL6 DS CL1 EMPNAME DS CL20 : OUTBUFF DC CL80’ ‘ * 80 blanks :

  34. SAMPLE WORKING PROGRAM WITH I/O *** READ INPUT & WRITE OUTPUT TO FILE START 0 * REGS BEGIN BEGIN **** OPEN FILES OI INDCB+10,X'08' OPEN INDCB,INPUT OI OUTDCB+10,X'08' OPEN OUTDCB,OUTPUT * : LOOP GET INDCB,INBUFF MVC OUTBUFF,INBUFF * and more … PUT OUTDCB,OUTBUFF WTO OUTBUFF B LOOP EOFRTN CLOSE INDCB CLOSE OUTDCB RETURN *** DEFINE FILES *********-*********-*********-*********-*********-*********-*********-** INDCB DCB RECFM=F,EODAD=EOFRTN,DDNAME=F:\TEST\NAMES.TXT, X DSORG=S,MACRF=G,LRECL=29 OUTDCB DCB RECFM=FB,MACRF=P,DSORG=S,LRECL=29, X DDNAME=F:\TEST\NAMES1.TXT *** DEFINE BUFFERS INBUFF DS 0CL27 EMP# DS CL6 DS CL1 EMPNAME DS CL20 OUTBUFF DC CL27' ' * 27 blanks CARRCTRL DC XL2'0D25' END BEGIN

  35. Console Output of Sample Working Program Assemble the program Linkage Editor step execution Execute the program step followed by the console output from the WTO in the program.

More Related