Download presentation

Presentation is loading. Please wait.

Published byHarry Moor Modified over 3 years ago

1
Some Logical Operations Ch.4 p. 87 - bottom

2
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

3
Compare Packed Decimal Compare two packed decimal fields: –CPM1(L1),M2(L2) Compare first field to second field Set a condition code based 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

4
Condition Code 4 bits located within the processor (PSW bits: 18-19) Cond. Code PSW bits 18 & 19 M1(L1) = M2(L2)100000 M1(L1) < M2(L2)010001 M1(L1) > M2(L2)001010 Not used---11

5
So How Do You Test CC? Branch-on-Condition Instruction

6
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) CPTC-HRS,40HRS BC2,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 … 40HRSDCPL2’40’ TC-HRSDSCL2

7
Another Example CPFIELDA,FIELDB BC8,SAME(BE) BC4,LOWER(BL) BC2,HIGHER(BH) 00 01 23 45 67 8C00 08 76 54 32 1C FIELDAFIELDB Which Branch is taken? ______________ LOWER

8
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.

9
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: PACKPACKNO,ZONENO

10
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.

11
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) PACKNODSCL6 ZONENODCCL8’24681357’ ZONENO Contents:‘F2F4F6F8F1F3F5F7’

12
When the PACK instruction has executed … PACKPACKNO,ZONENO BeforeAfter PACKNOn/a00002468135C ZONENOF2F4F6F8F1F3F5F7 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.

13
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

14
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. ADDERADDEND Before01 12 34 5C38 46 0D After73 88 5C38 46 0D APADDEND(3),ADDER(4) - or – AP0(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.

15
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.

16
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

17
Subtract Packed Instruction Example 00303C FB21 404A 4048 25 SUBTR1 SP P2,P1P2= 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.

18
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.

19
Multiply Packed Example ZAPPRODUCT,MULTPLD00 00 12 34 56 0C MPPRODUCT,MULTPLR01 17 28 32 00 0C *: MULTPLDDCPL4’1234560’ MULTPLRDCPL2’950’ PRODUCTDSPL6 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.

20
Another Multiply Packed Instruction Example 50 *MULTIPLY, GENERATE 3 DECIMALS, ROUND: 51 *------------------------------------- 52ZAPWAGE,HRS00 00 01 20 5C 53MPWAGE,RATE00 10 30 27 5CMULTIPLY 54 SRPWAGE,63.500 01 03 02 8CSHIFT/ROUND 55 *: 56 HRSDCP’120.5’01 20 5C 57 RATEDCP’8.55’85 5C 58 WAGEDSPL5 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.

21
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.

22
A Typical Decimal Divide Instruction Example ZAPRESULT,DIVDND DPRESULT,DIVSOR *: DIVDNDDSPL4Dividend DIVSORDSPL1Divisor RESULTDSPL5Quotient/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 DividendDivisor Quotient = Dividend

23
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: ZAPRESULT,DIVDND00 12 34 56 7C DPRESULT,DIVSOR04 11 52 2C 1C *: DIVDNDDCPL4’1234567’Dividend DIVSORDCPL1’3’Divisor RESULTDSPL5Quotient/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.

24
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: dividendxx.xxxx divisor x.x = xx.xxxquotient

25
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.

26
UNPK instruction example UNPKZONED,PACKED *: PACKEDDCPL3’12345’ 12 34 5C ZONEDDSZL5 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: OIZONED+4,’F0’ The rightmost byte now is changed to ‘F5’ and will print as the digit 5.

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

28
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: BUFFERDS0CL80

29
Input/Output Operations Start STM OPEN OPEN : : 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. OPENDCB1,INPUT ---- GETDCB1,DATA1

30
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 – DCBEODAD=eof-rtn entry pt.

31
AND In the Program OPEN dcbname : NXTRECGET dcbname,inarea : BNXTREC eofrtnCLOSE dcbname inareaDSCLnn dcbname DCB LRECL=nn,RECFM=F, MACRF=G,EODAD=eofrtn, DDNAME=filename

32
Output Operation Example OPEN dcbname : NXTRECPUT dcbname,outarea : BNXTREC CLOSE dcbname outareaDSCLnn 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.

33
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

34
BEGINSTART REGS : ***OPEN FILES OIINDCB+10,X’08’ OPENINDCB,INPUT OIOUTDCB+10,X’08’ OPENOUTDCB,OUTPUT : LOOPGETINDCB,INBUFF ADD and more … PUTOUTDCB,OUTBUFF BLOOP ***DEFINE FILES INDCBDCBLREC=80,RECFM=F,EODAD=EOFRTN … OUTDCBDCBLREC=80,RECFM=F,MACRF=P … ***DEFINE BUFFERS INBUFFDS0CL80 EMP#DSCL6 DSCL1 EMPNAMEDSCL20 : OUTBUFFDCCL80’ ‘* 80 blanks :

35
*** READ INPUT & WRITE OUTPUT TO FILE START 0 *REGSBEGIN ****OPEN FILES OI INDCB+10,X'08' OPEN INDCB,INPUT OI OUTDCB+10,X'08' OPEN OUTDCB,OUTPUT *: LOOPGET INDCB,INBUFF MVC OUTBUFF,INBUFF *and more … PUT OUTDCB,OUTBUFF WTO OUTBUFF B LOOP EOFRTNCLOSE 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 INBUFFDS 0CL27 EMP#DS CL6 DS CL1 EMPNAMEDS CL20 OUTBUFFDC CL27' '* 27 blanks CARRCTRL DC XL2'0D25' END BEGIN SAMPLE WORKING PROGRAM WITH I/O

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

37
Coding Assignment Realtors Assignment Posted in Assignments Due in 1 week Hand In: –Appropriate files (Source, Console sheet, output files) –.MLC file –Clean “console” sheet Place your files into a folder and ZIP the folder – turn in prior to class next week

Similar presentations

OK

Lec 3: Data Representation Computer Organization & Assembly Language Programming.

Lec 3: Data Representation Computer Organization & Assembly Language Programming.

© 2019 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google