You are on page 1of 17

ED (Edit) Instruction

Message characters like decimal (4B), / (61), $ (5B) are replaced by the fill character until the significance indicator is turned on, which happens when:
The significance starter is encountered, or A non-zero digit is encountered in the source number.
20

ED (Edit) Instruction
In a packed decimal number, the decimal point is not stored you have to keep track of it. Put a X4B (period) in that position in the pattern and the decimal will print.

18

ED (Edit) Instruction
So, use a significance starter (X21) to tell ED when to start printing zeros.
The first zero prints in the position after the significance starter. That is, the significance starter turns on the significance indicator and zeros start printing in the next position.

The significance starter also functions as a digit selector.

16

ED (Edit) Instruction
The significance indicator must be turned on before the decimal character is encountered or the decimal character will be replaced by the fill character.

21

ED (Edit) Instruction
When a positive sign digit is encountered in the last byte of the source number, the significance indicator is turned off. However, when a negative sign digit is encountered, the significance indicator stays on.
23

ED (Edit) Instruction
ED NUM1(5),NUM2 NUM2 12 3D
Negative number

NUM1 before 40 20 21 20 60 after 40 F1 F2 F3 60

(-123)

unchanged

prints 123
25

ED (Edit) Instruction
ED NUM1(7),NUM2 NUM2 12 3D
Negative number

NUM1 before 40 20 21 20 40 C3 D9 after

(-123)

40 F1 F2 F3 40 C3 D9 unchanged

prints 123 CR
26

ED (Edit) Instruction
ED NUM1(7),NUM2 NUM2 12 3C
Positive number

NUM1 before 40 20 21 20 40 C3 D9 after 40 F1 F2 F3 40 40 40

(+123)

unchanged

prints 123

27

EDMK Instruction
Using EDMK to insert a $ just in front of the first digit of a number:
LA 0 EDMK NUM1(7),NUM2 R1 Points at 1st printed no matter what. BCTR R1,R0 Move back 1 char. MVI 0(R1),C$ Insert $. ... NUM1 PL5 Decimal in pattern at 32 NUM1 + 4: 40 20 20 21 4B 20 20 R1,NUM1+4 Point R1 at decimal in case NUM2 =

CVB & CVD Instructions


Data in character format. PACK Data in packed decimal format. CVB Data in register in binary (fullword) format. Perform binary (fullword) math in register

Perform decimal math

Results in ED or character EDMK (printable) format. (UNPK /OI)

Results in packed decimal format.

CVD

Results in binary (fullword) format.

Character

Decimal

Binary

35

CVB Instruction
Possible errors on CVB:
specification exception if not on a doubleword boundary. data exception if not a valid packed decimal number. fixed-point divide exception if the number is too large to be stored in a fullword. addressing and protection exceptions.
39

CVD Instruction
Errors:
specification exception if not on a doubleword boundary. Addressing exception if address doesnt exist. Protection exception if address is outside the boundaries of the program.

42

Logical Operators: And, Or, Exclusive Or


AND: examines two bits, and if both bits are a B'1', then the result is a 1. Otherwise, the result is 0. OR: examines two bits, and if both bits are B'0', the result is 0. Otherwise, the result is 1. EXCLUSIVE OR: examines two bits, and if they are the same, the result is 0. If they are different, the result is 1. 6

AND Instruction
The net result is that performing an AND between 0 and an unknown bit results in Known 0; between 1 and an unknown bit leaves Pattern bits bit unaltered. 0110 1010 000000 1101 1000 111000 000000 0100 1000 Can use this to set selected bits to zero by putting a zero in those areas of the 9 pattern operand.

Or Instruction
The net result is that performing an OR between 0 and an unknown bit leaves the bit unaltered; between 1 and an unknown Pattern bit results in 1. 0110 1010 000000 1101 1000 111000 111000 1111 1010 Can use this to set selected bits to 1 by putting a 1 in those areas of the pattern 13 operand.

And and Or Instructions: Putting it Together


Example: Using the leftmost bit of an address register as a flag (because address uses only the rightmost 24 bits). O R3,=X80000000 B10000000
Turn flag (sign bit) on.

R3,=X7FFFFFFF B01111111
Turn flag (sign bit) off.

LTR R3,R3 BP/BM... bit.

Test: Set CC depending on sign 16

Exclusive Or Instruction
Performing an Exclusive OR between 0 and an unknown bit leaves the bit unaltered; between 1 and an unknownPattern bit results in reversing the value of the bit. 0110 1010 000000 11 10 11 01 1 10 01 00 0 11 10 00000 1 0
18

Exclusive Or Instruction
X
Result

r,address
Pattern

Compares fullword in register with fullword at address (pattern). Result replaces 1st

operand. X R3,=X80000000 Pattern = B10000000 Reverses the leftmost bit, all others 19 unchanged. CC = 0 if result all 0s; otherwise, CC = 1.

Exclusive Or Instruction
Example: Exchange the values of two registers (otherwise, this would require the use of a third register or the temporary use of a fullword in storage) XR XR XR R2,R3 R3,R2 R2,R3
Challenge: see if you can understand why this works. 21

Summary of And, Or, and Exclusive Or


And N, NR 0 1 ? ? 0 bit Or O, OR 0 1 ? ? bit 1 Excl. Or X, XR 0 1 ? ? bit

pattern unknown bit Result

In all cases, CC = 0 if result is all zeros; otherwise, CC = 1.

22

SI Versions of And, Or, and Exclusive Or


Used to perform the same logical operations as N, O, and X, but on an immediate byte in storage. NI address,byte And Immediate; used to turn bits to 0. OI address,byte Or Immediate; used to turn bits to 1. XI address,byte Excl. Or Immediate; used to reverse bits.23

SI Versions of And, Or, and Exclusive Or


Condition Code set to 0 if resulting byte is 00; set to 1 otherwise.

24

Common Uses of OI, NI, and XI


One-byte flags. Example in book: Using the NOP, NOPR instructions and altering the pattern of program branching on the fly not allowed.

25

SS Versions of And, Or, and Exclusive Or


Used to perform the same logical operations as N, O, and X, but on two areas in storage. NC addr1(L),addr2And; used to turn bits to 0. OC addr1(L),addr2Or; used to turn bits to 1. 28 XC addr1(L),addr2Exclusive Or; used to reverse bits.

The TM Instruction
Can use a single byte to keep track of multiple flags, one flag per bit. Use OI and NI to turn bytes on and off: OI FLAGBYTE,B'00100000' Turns 3rd flag on. NI FLAGBYTE,B'10111111' Turns 2nd flag off. 37 TM FLAGBYTE,B'00010000' Tests 4th flag.

Shift Logical Instructions


SLL R3,4
Before After R3 FF5B 8A12 F5B8 A120

SRL R3,4(R5) (R5 = 00000004)

R3 Before After FF5B 8A12 00FF 5B8A


43

ORG Command
location counter 000280 000280 000281 0002A9 000281 000295 0002A9 0002B3 002D0 INPUT TYPE NAME STREET CITY STATE ZIP CNTRY DS ORG DS DS DS ORG DS DS DS DS ORG ... CL80 INPUT CL1 CL40 CL39 Without this ORG, the INPUT+1 (or NAME) location counter would be CL20 positioned at the end of CL20 CL10 CNTRY, which is 9 bytes CL20 shy of where it should be. important!

Creates an overlay of new names that can be used to access the same storage areas.

Initial definition of INPUT storage.

ORG Command
STREET [39]

TYPE [1]

INPUT [80] NAME [40] CITY [20] STATE [20]

ZIP COUNTRY [9] [10] [20]

First ORG setsSecond up ORG sets upThird ORG moves this overlay. this overlay. location counter back to end of INPUT.

ORG Command
location counter 000280 000280 000281 0002A9 000281 000295 0002A9 0002B3 002D0 INPUT TYPE NAME STREET CITY STATE ZIP CNTRY DC ORG DS DS DS ORG DS DS DS DS ORG ... CL80 INPUT CL1 CL40 CL39 INPUT+1 (or NAME) CL20 CL20 Again, this is important CL10 to reset location to CL20

where it would have been without the ORGs. 8