Compressing Data into a Few Bits
Suppose we gave some data consisting of:
We would like to store this information in as little space as we can. How can we do that?
That will add up to 32 bits or 4 bytes.
What would the code look like? Suppose we have:
CARD DS 0C
ROOM DS ZL3 (Room number)
DS CL2
C1 DS ZL2 (Combination number 1)
DS CL2
C2 DS ZL2 (Combination number 2)
DS CL2
C3 DS ZL2 (Combination number 3)
DS CL2
DEPT DS ZL3 (Department number)
DS 60C
We will store the values in this fashion:
ROOM C1 C2 C3 DEPT bits 0-9 10-15 16-21 22-27 28-31
To achieve this, we need to use PACK, CVB, shifts and AR. Suppose we have:
XREAD CARD,80
*
PACK TEMP(8),ROOM(3) Pack the ROOM value
CVB 5,TEMP Convert it to binary
SLL 5,22 Move it over to bits 0-9
*
PACK TEMP(8),C1(2) Pack the C1 value
CVB 6,TEMP Convert it to binary
SLL 6,16 Move it over to bits 10-15
*
PACK TEMP(8),C2(2) Pack the C2 value
CVB 7,TEMP Convert it to binary
SLL 7,10 Move it over to bits 16-21
*
PACK TEMP(8),C3(2) Pack the C3 value
CVB 8,TEMP Convert it to binary
SLL 8,4 Move it over to bits 22-27
*
PACK TEMP(8),DEPT(2) Pack the DEPT value
CVB 9,TEMP Convert it to binary
* Is is already in bits 28-31
*
AR 5,6 Combine the values
AR 5,7 in the five registers
AR 5,8
AR 5,9
*
At the end of this, register 5 contains the 32 bits we want. We can use STCM or L to put the data in a variable somewhere.
Invent some data and try working through this by hand.
Suppose we have used STCM to put the 4-byte value somewhere in a table in a field called OFFICE.
We now might want to extract and print all this data. Ultimately we will print the values by having them in packed decimal variables and then using ED, but what do we do first?
Suppose we have:
ROOMP DS PL2 C1P DS PL2 C2P DS PL2 C3P DS PL2 DEPTP DS PL2
How do we extract the data from OFFICE into these variables?
ICM 5,B'1111',OFFICE Get the value in a register
SLL 5,28 Arrange to have 0s everywhere
SRL 5,28 except bits 28-31
CVD 5,TEMP Convert it to packed decimal
ZAP DEPTP(2),TEMP+6(2) Copy the value into DEPTP
*
ICM 5,B'1111',OFFICE Get the value in a register
SLL 5,22 Arrange to have 0s everywhere
SRL 5,26 except bits 22-27 and then
* move them to bits 26-31
CVD 5,TEMP Convert it to packed decimal
ZAP C3P(2),TEMP+6(2) Copy the value into C3P
*
ICM 5,B'1111',OFFICE Get the value in a register
SLL 5,22 Arrange to have 0s everywhere
SRL 5,26 except bits 16-21 and then
* move them to bits 26-31
CVD 5,TEMP Convert it to packed decimal
ZAP C2P(2),TEMP+6(2) Copy the value into C2P
*
ICM 5,B'1111',OFFICE Get the value in a register
SLL 5,22 Arrange to have 0s everywhere
SRL 5,26 except bits 10-15 and then
* move them to bits 26-31
CVD 5,TEMP Convert it to packed decimal
ZAP C1P(2),TEMP+6(2) Copy the value into C1P
*
ICM 5,B'1111',OFFICE Get the value in a register
SLL 5,22 Arrange to have 0s everywhere
SRL 5,26 except bits 0-9 and then
* move them to bits 22-31
CVD 5,TEMP Convert it to packed decimal
ZAP ROOMP(2),TEMP+6(2) Copy the value into ROOMP
Again: invent some data and try working through this by hand.