Halfword Instructions:
Up to this point, we have been working with instructions (ST, L, A, etc...) that work with 32-bit signed integers that are stored as fullwords. We're now going to look at a set of instructions that work with 16-bit signed integers that are stored as halfwords.
Halfword storage areas and constants are generated by using DS and DC statements with a storage class of H. Using the H will force halfword alignment.
Load Halfword
Format: label LH R,D(X,B)
Copies into R the 32-bit representation of the number at the absolute address represented by D(X,B). The 2 leftmost bytes are set to X'0000' if the number is positive or X'FFFF' if the number is negative.
Execution of:
LH R4,=H'-12'
will change the contents of register 4 to X'FFFFFFF4'
Store Halfword
Format: label STH R,D(X,B)
Places a copy of the rightmost 2 bytes of R at the absolute address represented by D(X,B).
Assuming that register 4 contains X'FFFFFFF4', execution of:
STH R4,HALF
HALF DS H
will change the contents of HALF to X'FFF4'
Compare Halfword
Format: label CH R,D(X,B)
Compares the rightmost 2 bytes of R to the halfword at the absolute address represented by D(X,B) and sets the condition code.
Code Meaning 0 Equality 1 Halfword in R is low 2 Halfword at D(X,B) is low
Assuming that register 4 contains X'FFFFFFF4', execution of:
CH R4,HALF
HALF DC H'5'
will set the condition code to 1 because the contents
of register 4 (-12) is less than the contents of HALF (5)
Add Halfword
Format: label AH R,D(X,B)
The halfword at D(X,B) is added to the rightmost 2 bytes of R. The sum is stored in R. The condition code is set.
Code Meaning 0 Sum is 0 1 Sum is less than 0 2 Sum is greater than 0 3 Overflow - sum cannot be stored as a halfword
Assuming that register 4 contains X'FFFFFFF4', execution of:
AH R4,HALF
HALF DC H'13'
will change the contents of register 4 to X'00000001'
Subtract Halfword
Format: label SH R,D(X,B)
The halfword at D(X,B) is subtracted from the rightmost 2 bytes of R. The difference is stored in R. The condition code is set.
Code Meaning 0 Difference is 0 1 Difference is less than 0 2 Difference is greater than 0 3 Overflow - difference cannot be stored as a halfword
Assuming that register 4 contains X'FFFFFFF4', execution of:
SH R4,HALF
HALF DC H'2'
will change the contents of register 4 to X'FFFFFFF2'
Multiply Halfword
Multiplying with halfwords is slightly different from multiplying with fullwords. A single register will be used rather than using an even-odd pair.
Format: label MH R,D(X,B)
The halfword at D(X,B) and the rightmost 2 bytes of R are multiplied together. The result is stored as a 32-bit number in R.
Assuming that register 5 contains X'FFFFFFF4', execution of:
MH R5,HALF
HALF DC H'-2'
will change the contents of register 5 to X'00000018'