1 / 44

Bit Manipulation & Editing

Bit Manipulation & Editing. Ch. 10 Page 240. Boolean Instructions. Bits in the sending field are used to modify bits in the receiving field - – one byte at a time. OR Logic. If one bit or both bits are “on”, then the resulting bit is “on”. AND Logic.

vila
Télécharger la présentation

Bit Manipulation & Editing

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. Bit Manipulation & Editing Ch. 10 Page 240

  2. Boolean Instructions Bits in the sending field are used to modify bits in the receiving field - – one byte at a time

  3. OR Logic If one bit or both bits are “on”, then the resulting bit is “on”

  4. AND Logic Both bits must be “on” in order for the resulting bit to be “on”

  5. X-OR Logic If one bit or the other bit is 'on', but not both, then the result is 'on' If one bit or the other bit is “on”, but not both, then the resulting bit is “on”.

  6. OR Family Notice the result in the example to the left: Begin with the left-hand bit in the result field – the result bit if “0” because neither of the target fields (AREA+10 and MASK) is a “1”. In the case of the second bit from the left, the result is “1” because the bit in the same position in MASK is “1” even though it is a “0” in AREA+10. The third bit from the left is the same situation. Notice the fourth bit from the left. The result is “1” because both target bits are “1”. Simply apply the same rules to the second half of the byte – the result is “0” only if both of the target bits are “0”. This is the instruction you have been using to change the flag bit in the DCB to accept the data as EBCDIC rather than ASCII. You have also, probably, used this same instruction to make your sign-byte printable following a CVD and UNPK instruction for an output field.

  7. AND Family This time the target fields are being AND’ed – both operand fields must contain “1” bits in order for the result to be a “1” in the same bit position. Notice the only bits that are “1” in the result field are because that is the only part of the target fields that both bits are “1” – all others are “0”. This instruction is typically used to turn selected bits to “0”. In your mask field, set a bit to “1” for those bits you do not want to change, but set the bits to “0” if you wish to turn the target bit to “0”.

  8. X-OR Family This is probably the trickiest of the Boolean sets of instructions. Set the result to a “1” if either the target or the mask is a “1” bit – but not both are “1” bits (that would then be the same as AND). Map the result field back to the two input fields to see that in each case, only one of the two bits being compared cause the result to be “1”. Use this instruction when OR nor AND will do the right thing for you.

  9. Test Under Mask - TM • Check the status of bits in a byte • Storage-Immediate format only • Sets Condition Code based on results of the test • Indicate in the mask the bits in the byte to be tested by setting those bits to 1’s Practically every program uses a switch or some indicator to indicate some event has occurred. TM instruction provides a very efficient means to test that switch to see if your event has occurred yet. Do you remember the Parcheesi exercise back near the beginning of class? In it, you set a switch (using OI perhaps) to indicate that you landed on a Blue Square and are due to lose your next roll of the die. On entry to your Parcheesi Player, you could test that switch using TM. The smallest amount of memory that you can allocate is a byte, so let’s assume that you used the high-order byte for your switch. The example using Parcheesi for testing the LOSE TURN follows. Of course, the purpose of TM is to set the condition code so you can actually check on the status of the comparison.

  10. TM FLAGBYTE,X’C3’ CC=3All tested bits are 1’s

  11. Remember Parcheesi ? The flowchart that you created lies to the far left – at least the part of the flowchart that relates to our current discussion. The Assembler code that is relevant is under the flowchart symbol labeled RESET SWITCH. Early in the turn of PLAYER1, the test needs to be made to see if a Blue Square was landed on the last turn and if so, this turn needs to be bypassed. The TM instruction satisfies the test of the Blue Square (the switch is the high-order bit of the BLUESW byte. The define is done in the last displayed instruction at the bottom. The switch is set once it has been determined that the square landed on is blue. This can be easily accomplished with the OI instruction, as shown near the bottom. Note also that the switch is tested prior to rolling the die. Finally, where the switch is tested, then the branch to SWITCHON is taken, you want to remember to shut the switch off. This could be a good use of the Exclusive Or instruction: XI BLUESW,X’80’

  12. Translation Instructions • Translate – TR • Translate and Test – TRT • Execute - EX Translate one bit pattern into a different bit pattern – up to 256 unique characters per byte TR and TRT essentially work the same way, but they end up a little differently. Read on! The EX instruction is not really a Translation instruction, but it does most often get used with the TR/TRT instructions. p.328

  13. Translate - TR 2 Operands: 1. pattern to be translated 2. table of replacement characters TR EBCDIC,ASCIITAB We will create an example to change EBCDIC digits (F0-F9) into ASCII digits (30-39). EBCDIC operand is the digits to be translated & ASCIITAB is the replacement digits.

  14. Take notice of the table shown on the previous slide. Nearly all the blocks in the table contain the EBCDIC character for a blank – X’40’. These are the EBCDIC character patters to be ignored for translation. While the characters around the table – across the top and down the left side are not part of the table in memory – these characters are just showing us the 256 positions in memory which is occupied by the table. The only characters other than X’40’ are used in the bytes representing F0-F9 – the EBCDIC characters for the digits 0-9. That’s where the characters to be translated are placed in the table. The values that are replacing the X’40’ are those of the ASCII characters that represent the digits 0-9. The idea should now be quite obvious to you – when a byte that contains the EBCDIC character X’F0’ it will be translated into ASCII character X’30’, X’F1’ will be translated to ASCII X’31’ and so on. Any other characters will remain untouched (un-translated) which is what the X’40’ means to accomplish. The hardest part (not really hard, just tedious or cumbersome) is building and defining the table in memory. Recall that each character, as it appears in memory, is made up of two hex digits, up to 256 unique characters. In the table on the previous slide, the first hex character is represented down the left column and the second hex character is represented across the table (in a row).

  15. which in hex is: F1 F9 F8 F4 Translate - TR TREBCDIC,ASCIITAB 1984 where EBCDIC contains: From left-to-right, each EBCDIC character is used as an index into ASCIITAB. The resulting character is the character at the indexed-to location in memory.

  16. Translate - TR TR EBCDIC,ASCIITAB Any other bit configuration would give back a blank character – X’40’

  17. Defining ASCIITAB ? ASCIITAB DS 0CL256 DC 16X’40’ *00-0F DC 16X’40’ *10-1F DC 16X’40’ *20-2F DC 16X’40’ *E0-EF DC X’303132333435’ *F0-F5 DC X’36373839’ *F6-F9 DC 12X’40’ *FA-FF

  18. Translate-and-Test - TRT • Similar to TR in the way it works • 1st operand acts as an index into 2nd operand • 2nd operand is a table • No replacement of characters – just checks that table byte is X’00’ • If X’00’, process the next byte • If not X’00’, stop processing TRT and place address of the byte in GPR 1, place the byte from the table into low-order byte of GPR 2 • You had better not be using GPRs 1 & 2 for anything

  19. So What Are Uses of TRT? • When looking at a variable-length field such as a NAME, Find the blank following a name shorter than the fixed-character length in an input area • Find the first significant digit in a numeric field • Locate a comma separator • Find any character that has special meaning

  20. TRT Table • X’00’ – character with no special meaning • Non-X’00’ – special meaning • X’40’ represents characters without interest • X’00’ represents alpha or numeric characters • Other fields identify some special characters such as a blank (40) is identified with X’04’ and from there, the special characters are identified in increments of 4 bytes (04, 08, 0C, etc.) As you may have guessed by now, this is another of those instructions that takes significantly more time to think through, design, and build all the support areas, and the instruction itself is very easy to code.

  21. Review closely the table on the previous slide: X’00’ in the table represent the alphanumeric characters in EBCDIC – letters and numbers X’40’ is used to indicate invalid characters – those that have no interest Some special characters are of interest and are identified with other than X’00’ or X’40’ – for example a blank (40) is identified with a X’04’ and the period (4B) is identified with X’08’. Notice that the special characters are identified with symbols that are in increments of 4 bytes – 04, 08, 0C, 10, etc. The table to the right outlines the characters that are “special” for the TRT instruction.

  22. Assume the table is located beginning at location X‘2000’ – so the letter upper-case A is the translate byte at X’20C1’ • A branch table is located at X’3004’ with 16 branch instructions – one for each of the special characters- the first of which is for a blank • The characters to be translated are at location X’CA80’ which contains: (CA80-CA94) UNPK PROUT(9),WORD(5) E4D5D7D2 40D7D9D6 E4E34DF9 5D6BE6D6 D9C44DF5 5D

  23. LA R2,BRTABLETRT UNPKINST(21),TRTTABLE • Translate-and-Test instruction is: • 1st character to translate is U – X’E4’ • Translation characters are X’00’ at Table+E4 – take no special action • Translate the rest of the op-code until translation reaches the blank (b)

  24. 00 00 00 00 00 00 CA 84 • A blank character is X’40’ which takes us to table+40 which is non-X’00’ • Addr of the source byte is placed in GPR 1 • Table entry (X’04’) is placed in low order byte of GPR 2 (which contained X’3000’) • CC is set to 1 (non-zero byte found) GPR 1 00 00 00 00 00 00 30 04 GPR 2 BC 4,0(2) *blank found This is complicated! At table+40 (address in GPR1) is found X’04” so the X”04” is placed in the low-order byte of GPR2. Prior to this, GPR2 contained X”3000” – the address of the Branch Table which you constructed and can be seen on the next slide. With the value found by TRT (X”04”), the condition code is set to 1, so the BR instruction above branches on condition (cond. Code 4 = Cond. Code set to 1) to location 0000 in memory, indexed by GPR2 which contains the address of the Branch Table entry for “Found a Blank” which was X”04” in the Translate Table. Phew!

  25. TRT instruction set the Condition Code to 1 to indicate non-zero found when the “blank” was translated. With Cond.Code 1, the code to test in the Branch-on-Condition is X”4”. Branch Table beginning at Loc. X’3000’

  26. Execute - EX • Causes just one target instruction to be executed out of sequence without actually branching to that instruction. • After OR’ing bits 8-15 (2nd byte) of the 2nd operand, which could be the length field of SS-type instructions without changing the byte in the instruction (OR’s from low-order byte of 1st operand) • Most often used with TRT • RX format: EX R1,D2(X2,B2)

  27. As we all learned possibly on the very first day of class, we don’t mix instructions and definitions in the same part of the program. Normally instructions come first, then the definitions. But there are circumstances where that rule may be disregarded and the use of the EX instruction is one of those times. As we also know, with the EX instruction, we can target some other instruction that is out of sequence, execute that target instruction, then return to the instruction following the EX instruction. In this case, it makes sense to place that target instruction out of the way of normal sequential instruction execution. Place the target instruction along with the definitions of memory. The ability of the EX instruction to modify the second byte of a target instruction gives you the power, depending on the instruction format, to change a register reference, or an immediate operand, or an operand length. Review each instruction format for what is located at the second byte location, therefore subject to change: In the chart to the left, the underlined operand in each instruction format shows the possibilities for the values that can be altered by using the EX instruction. Operand 1 designates a register containing a value used to modify the second byte of the target instruction. However, if register 0 is specified, no modification is done. Operand 2 refers to the target instruction, defined elsewhere in memory, to be executed by EX. Any instruction except another EX may be target to EX. EX then Ors bits 8-15 (byte 2) of the target instruction with bits 24-31 (the rightmost byte) of the operand 1 register. The target instructions, however, is not actually changed in memory. After executing the target instruction, the program resumes either with the instruction following EX or, if the target instruction is a branch, where the branch is directed.

  28. Examples of Using EX The following RR-format example inserts X”14” into GPR5 and Ors byte 2 of ADDREG with the X”14”. This process causes the second byte of ADDREG to reference GPR 1 and 4 temporarily. ADDREG executes out of line as “add” the contents of GPR4 to the contents of GPR1. EXRR IC 5,=X’14’ insert X’14’ into R5 EX 5,ADDREG Add R4 to R1 --- DS 0H ADDREG AR 0,0 target instruction The RS-format example Ors the second byte of STOREGS with X’DF’. This process causes byte 2 of STOREGS to reference R13 and R15. STOREGS executes out of line as “Store the contents of registers 13,14, and 15 in SAVEREGS. IC 6,X’DF’ insert X’DF’ into R6 EX 6,STOREGS store regs 13-15 --- SAVEREGS DS 3F 3 fullwords DS 0H boundary alignment to even STOREGS STM 0,0,SAVEREGS RS target instruction

  29. Examples of Using EX This RX-format example Ors the second byte of STORCH with X’20’. This process causes byte 2 of STORCH to reference base reg 2 and index reg 0. STORCH executes as “store the rightmost 8 bits of R2 in SAVEBYTE. IC 7,=X’20’ put X’20’ into R7 EX 7,STORCH store right byte of R7 --- SAVEBYTE DS C one byte – character DS 0H force even address STORCH STC 0,SAVEBYTE RX Target instruction This SI-format example Ors the second byte of MOVIMM with X’5B’ (a dollar sign), then moves the dollar sign to PRINT+20, and the instruction can thus move any immediate value. IC 8,=X’5B’ place X’5B’ into R8 EX 8,MOVIMM move $ to print area --- PRINT DC CL133’ ‘ print area blanked out DS 0H force boundary alignment MOVIMM MVI PRINT+20,X’00’ target instrution

  30. Examples of Using EX Using EX on SS-format instructions causes it to modify operand lengths. Remember that when executing an SS-format instruction, the computer adds 1 to the length. The first example uses MOVECHAR to move a specified number of asterisks (up to 3) to the print area and could be used to print one, two, or three asterisks to denote the total level: IC 9,=X’02’ insert X’02’ into R9 EX 9, MOVECHAR move *** to print area --- PRINT DC CL133’ ‘ print area definition DS 0H MOVECHAR MVC PRINT+30(0),=C’CCC’ target instruction for EX This example executes an AP operation is which byte 2 contains a length code for both operands: IC 10,=X’32’ insert X’32’ into R10 EX 10,ADDPK Add FLD2 to FLD1 --- FLD1 DS PL4 FLD2 DS PL3 DS 0H ADDPK AP FLD1(0),FLD2(0) target of EX instruction

  31. Last EX Example 003802 1711 6 XR 1,1 Clear Reg 1 003804 4190 4026 7 LA 9,NAMADDR Addr 1st length indicator 003808 4310 9000 8 IC 1,0(0,9) length of NAME in Reg 1 00380C 1881 9 LR 8,1 save length in Reg 8 00380E 0610 11 BCTR 1,0 decrement Reg 1 by 1 003810 4190 9001 12 LA 9,1(0,9) increment for NAME field 003814 4410 40D6 13 EX 1,M30MOVE execute M30MOVE 003818 1A98 14 AR 9,8 addr of NAME + length for 2nd indicator 00381A 4310 9000 16 IC 1,0(0,9) length of addr in Reg 1 00381E 0610 17 BCTR 1,0 decrement reg 1 by 1 003820 4190 9001 18 LA 9,1(0,9) increment for address field 003824 4410 40DC 19 EX 1,M40MOVE execute M40MOVE 20 * --- 21 * --- 22 * --- 003828 23 NAMADDR DS CL42 variable name & address 003852 24 PRLINE DS CL133 print area 0038D7 00 0038D8 26 M30MOVE MVC PRLINE+20(0),0(9) move NAME to Print 0038DE 27 M40MOVE MVC PRLINE+50(0),0(9) move ADDRESS to Print --- If you follow this example carefully, there is a length byte in front of each variable-length field in the input that is read from a device. The length is one byte and in binary format. There are two fields alternating: NAME and ADDRESS. 0A ADAM SMITH 0C 423 BASIN ST nn NEXT NAME nn NEXT ADDR

  32. Last EX Example Continued Since the name is 10 characters long, the preceding length indicator contains X’0A’. The address is 12 characters long, and its preceding length indicator contains X’0C’. The entire record consists of 1 + 10 + 1 + 12 = 24 bytes. Other records would vary in length accordingly. The maximum record length is assumed to be 42 bytes. The purpose is to move the name and the address separately to the print area. IC extracts the length indicator, and the STC inserts the length indicator (minus 1 byte) into the second byte, the length, of the MVC instruction. At execution time, the computer adds 1 to the instruction length. At the end of execution, the print area looks like this: Print area: ADAM SMITH 423 BASIN ST PRINT + 20 PRINT + 40

  33. Editing • Used to Edit (Beautify) numeric data to packed decimal (and it UNPK’s it too) • Insert $-sign • Include commas in larger numbers • Insert the decimal point in financial numbers • Suppress leading zeros p.82 in Ch.4

  34. Some Edit Patterns

  35. Detailed Edit Example 1200 1203 02 57 42 6C Source: 1000 100C 40 20 20 6B 20 21 20 4B 20 20 40 C3 D9 Pattern: b d d , d ( d . d d b C R ED PATTERN(13),SOURCE(4) The SOURCE field is the value that you want to have beautified by inserting commas, if appropriate, dollar sign, and decimal point. The PATTERN field tells EDIT how to go about accomplishing the beautification. The PATTERN is shown in two places – the hex format in the light green box and the character interpretation in the white box below the green box. The instruction executes like most others (right to left) and the PATTERN must be the receiving field. SOURCE is unchanged after the instruction executes.

  36. Before decimal data in the packed format can be used in a printed report, digits and signs must be converted to printable characters. Moreover, punctuation marks, such as commas and decimal points, may have to be inserted in appropriate places. The highly flexible EDIT instruction performs these functions in a single instruction execution. The example on the previous slide shows step-by-step one way that the EDIT instruction can be used. The field to be edited (the source) is four bytes long; it is edited against a pattern 13 bytes long. The following symbols are used: SYMBOLMEANING b (hex 40) blank character ( (hex 21) significance started d (hex 20) digit selector As the instruction executes, it looks at each byte from left to right. The table below shows how each byte is treated by instruction execution.

  37. And the Answer Is … • In the table above there are 3 notes: • This character is the fill byte. • First nonzero decimal source digit turns on the significance indicator. • Plus sign in the four rightmost bits of the byte turns off the significance indicator. Pattern: 40 40 F2 6B F5 F7 F4 4B F2 F6 40 40 40 which prints as: 2,574.26 After ED executes, the condition code is set. 0 result is 0 1 result is negative 2 result is positive 3 not used

  38. More Examples of ED on p. 83 in Your Textbook • Suppress Leading Zeroes • Significance Starting • Insert commas and decimal points • Negative values handling

  39. EDMK • Used for printing money values • Same as Edit instruction except that the address of the 1st significant digit is saved in GRP 1 when EDMK executes • This makes it easier to insert a dollar-sign or other currency symbol into the field to the left of the amount p.238

  40. Printed Output: $2,574.26 EDMK Example 02 57 42 6C Source: 40 20 20 6B 20 21 20 4B 20 20 40 C3 D9 Pattern: EDMK PATTERN(13),SOURCE(4)BCTR 1,0MVI 0(1),C’$’ 40 5B F2 6B F5 F7 F4 4B F2 F6 40 40 40 Pattern:

  41. EDMK Examples on p.239 • Suppress leading zeroes • Significance Starting • Insert commas and decimal point • Non-blank fill character • Negative value handling • Editing dates • Suppressing fields

  42. Exercise • Due next week • Optional / Extra Credit • Bit Bash Assignment

More Related