bit manipulation & editing ch. 10 page 240. boolean instructions bits in the sending field are...

44
Bit Manipulation & Editing Ch. 10 Page 240

Upload: moris-todd

Post on 18-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 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

Bit Manipulation & Editing

Ch. 10

Page 240

Page 2: 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

Boolean Instructions

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

Instruction SI SS RX RR

OR OI OC O OR

AND NI NC N NR

EXCLUSIVE OR XI XC X XR

Page 3: 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

If one bit or both bits are “on”, then the resulting bit is “on”

OR Logic

Page 4: 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

Both bits must be “on” in order for the resulting bit to be “on”

AND Logic

Page 5: 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

X-OR Logic

If one bit or the other bit is “on”, but not both, then the resulting bit is “on”.

Page 6: 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

OR Family

O R1,D2(X2,B2)

OI D1(B1),I2

OC D1(L,B1),D2(B2)

OR R1,R2

The OR of the 1st and 2nd operands are placed at the first operand location

OI AREA+10,X’5C'

Example:

0011 0101Before: AREA+10

Mask 0101 1100

0111 1101After: AREA+10

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.

Page 7: 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

AND Family

N R1,D2(X2,B2)

NI D1(B1),I2

NC D1(L,B1),D2(B2)

NR R1,R2

The AND of the 1st and 2nd operands are placed at the first operand location

NI AREA+10,X’5C'

Example:

0011 0101Before: AREA+10

Mask 0101 1100

0001 0100After: AREA+10

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

Page 8: 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

X-OR Family

X R1,D2(X2,B2)

XI D1(B1),I2

XC D1(L,B1),D2(B2)

XR R1,R2

The X-OR of the 1st and 2nd operands are placed at the first operand location

XI AREA+10,X’5C'

Example:

0011 0101Before: AREA+10

Mask 0101 1100

0110 1001After: AREA+10

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.

Page 9: 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

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.

Page 10: 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

TM FLAGBYTE,X’C3’

1111 1011FLAGBYTE

1100 0011Mask

Result:

CC = 0CC = 1CC = 3

0'smixed

1's

CC set:If tested bits are:

CC=3All tested bits are 1’s

Page 11: 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

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’

Page 12: 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

Translation Instructions

• Translate – TR• Translate and Test – TRT• Execute - EX

p.328

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.

Page 13: 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

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.

Page 14: 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

0 1 2 3 4 5 6 7 8 9 A B C D E F

0_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

1_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

2_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

3_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

4_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

5_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

6_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

7_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

8_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

9_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

A_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

B_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

C_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

D_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

E_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

F_ 30 31 32 33 34 35 36 37 38 39 40 40 40 40 40 40

Page 15: 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

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

Page 16: 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

Translate - TR

TR EBCDIC,ASCIITAB

where EBCDIC contains: 1984

which in hex is: F1 F9 F8 F4

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.

Page 17: 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

Translate - TR

TR EBCDIC,ASCIITAB

Any other bit configuration would give back a blank character – X’40’

Page 18: 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

Defining ASCIITAB ?

ASCIITAB DS 0CL256DC 16X’40’ *00-0FDC 16X’40’ *10-1F DC 16X’40’ *20-2F

DC 16X’40’ *E0-EFDC X’303132333435’ *F0-F5DC X’36373839’ *F6-F9DC 12X’40’ *FA-FF

Page 19: 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

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

Page 20: 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

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

Page 21: 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

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.

Page 22: 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

0 1 2 3 4 5 6 7 8 9 A B C D E F

0_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

1_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

2_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

3_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

4_ 04 40 40 40 40 40 40 40 40 40 40 08 40 0C 10 40

5_ 14 40 40 40 40 40 40 40 40 40 40 18 1C 20 40 40

6_ 24 28 40 40 40 40 40 40 40 40 40 2C 40 40 40 40

7_ 40 40 40 40 40 40 40 40 40 40 40 30 34 38 3C 40

8_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

9_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

A_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

B_ 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40

C_ 40 00 00 00 00 00 00 00 00 00 40 40 40 40 40 40

D_ 40 00 00 00 00 00 00 00 00 00 40 40 40 40 40 40

E_ 40 40 00 00 00 00 00 00 00 00 40 40 40 40 40 40

F_ 00 00 00 00 00 00 00 00 00 00 40 40 40 40 40 40

Page 23: 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

Review closely the table on the previous slide:X’00’ in the table represent the alphanumeric characters in EBCDIC – letters and numbersX’40’ is used to indicate invalid characters – those that have no interestSome 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.

Page 24: 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

• 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

Page 25: 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

• 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)

LA R2,BRTABLETRT UNPKINST(21),TRTTABLE

Page 26: 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

• 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)

00 00 00 00 00 00 CA 84

GPR 1

00 00 00 00 00 00 30 04GPR 2

BC 4,0(2) *blank foundThis 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!

Page 27: 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

Condition Code Set 0 1 2 3Mask Bit Value 8 4 2 1

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’

Memory Location

Contents of Branch Table

3000 BC 4,0(2) BLANKSP

3004 BC 4,0(2) PERIOD3008 BC 4,0(2) LEFT PAREN300C BC 4,0(2) PLUS SIGN3010 BC 4,0(2) AMPERSAND3014 BC 4,0(2) DOLLAR SIGN3018 BC 4,0(2) ASTERISK301C BC 4,0(2) RIGHT PAREN3020 BC 4,0(2) DASH3024 BC 4,0(2) FORW’D SLASH3028 BC 4,0(2) COMMA302C BC 4,0(2) POUND SIGN3030 BC 4,0(2) AT SIGN3034 BC 4,0(2) APOSTROPHE3038 BC 4,0(2) EQUAL SIGN303C I think you get the idea…

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

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)

Page 29: 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

FORMAT

OPERANDS

RR R1,R2

RS R1,R3,D2(B2)

RX R1,D2(X2,B2)

SI D1(B 1),I2

SS(1) D1(L,B1),D2(B2)

SS(2) D1(L1,B1),D2(L2,B2)

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

Page 30: 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

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 R5EX 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 R6EX 6,STOREGS store regs 13-15---

SAVEREGS DS 3F 3 fullwordsDS 0H boundary alignment to even

STOREGS STM 0,0,SAVEREGS RS target instruction

Page 31: 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

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 R7EX 7,STORCH store right byte of R7---

SAVEBYTE DS C one byte – characterDS 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 R8EX 8,MOVIMM move $ to print area---

PRINT DC CL133’ ‘ print area blanked outDS 0H force boundary alignment

MOVIMM MVI PRINT+20,X’00’ target instrution

Page 32: 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

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 R9EX 9, MOVECHAR move *** to print area---

PRINT DC CL133’ ‘ print area definitionDS 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 R10EX 10,ADDPK Add FLD2 to FLD1---

FLD1 DS PL4FLD2 DS PL3

DS 0HADDPK AP FLD1(0),FLD2(0) target of EX instruction

Page 33: 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

Last EX Example

003802 1711 6 XR 1,1 Clear Reg 1003804 4190 4026 7 LA 9,NAMADDR Addr 1st length indicator003808 4310 9000 8 IC 1,0(0,9) length of NAME in Reg 100380C 1881 9 LR 8,1 save length in Reg 800380E 0610 11 BCTR 1,0 decrement Reg 1 by 1003810 4190 9001 12 LA 9,1(0,9) increment for NAME field003814 4410 40D6 13 EX 1,M30MOVE execute M30MOVE003818 1A98 14 AR 9,8 addr of NAME + length for 2nd indicator00381A 4310 9000 16 IC 1,0(0,9) length of addr in Reg 100381E 0610 17 BCTR 1,0 decrement reg 1 by 1003820 4190 9001 18 LA 9,1(0,9) increment for address field003824 4410 40DC 19 EX 1,M40MOVE execute M40MOVE

20 * ---21 * ---22 * ---

003828 23 NAMADDR DS CL42 variable name & address003852 24 PRLINE DS CL133 print area0038D7 000038D8 26 M30MOVE MVC PRLINE+20(0),0(9) move NAME to Print0038DE 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

Page 34: 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

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

Page 35: 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

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

Page 36: 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

Some Edit Patterns

Char Meaning

20 Digit selector

21 Significance starter

40 Blank character

4B Decimal point

60 Minus sign

6B comma

Page 37: 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

Detailed Edit Example

02 57 42 6CSource:

40 20 20 6B 20 21 20 4B 20 20 40 C3 D9Pattern:

ED PATTERN(13),SOURCE(4)

b d d , d ( d . d d b C R

1200 1203

1000 100C

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.

Page 38: 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

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:

SYMBOL MEANINGb (hex 40) blank character( (hex 21) significance startedd (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.

PATTERN DIGITSIGNIFICANCE

INDICATOR(before/after)

RULE LOCATION1000-100C

b off/off leave (1) bdd,d(d.ddbCRd 0 off/off fill bbd,d(d.ddbCRd 2 off/on(2) digit bb2,d(d.ddbCR, on/on leave samed 5 on/on digit bb2,5(d.ddbCR( 7 on/on digit bb2,57d.ddbC

Rd 4 on/on digit bb2,574.ddbC

R. on/on leave samed 2 on/on digit bb2,574.2dbC

Rd 6 + on/off(3) digit bb2,574.26bC

Rb off/off fill sameC off/off fill bb2,574.26bb

RR off/off fill bb2,574.26bbb

Page 39: 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

And the Answer Is …

Pattern: 40 40 F2 6B F5 F7 F4 4B F2 F6 40 40 40

In the table above there are 3 notes:1. This character is the fill byte.2. First nonzero decimal source digit turns on the significance indicator.3. Plus sign in the four rightmost bits of the byte turns off the significance indicator.

which prints as: 2,574.26

After ED executes, the condition code is set.0 result is 01 result is negative2 result is positive3 not used

Page 40: 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

More Examples of ED on p. 83 in Your Textbook

• Suppress Leading Zeroes• Significance Starting• Insert commas and decimal points• Negative values handling

Page 41: 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

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

Page 42: 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

02 57 42 6C

40 20 20 6B 20 21 20 4B 20 20 40 C3 D9

Source:

Pattern:

EDMK Example

EDMK PATTERN(13),SOURCE(4)BCTR 1,0MVI 0(1),C’$’

40 5B F2 6B F5 F7 F4 4B F2 F6 40 40 40Pattern:

$2,574.26Printed Output:

Page 43: 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

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

Page 44: 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

Exercise

• Due next week• Optional / Extra Credit• Bit Bash Assignment