Intel i86W Manual page 163

Table of Contents

Advertisement

CHAPTER 9
PROGRAMMING EXAMPLES
9.1 SMALL INTEGERS
The 32-bit arithmetic instructions can be used to implement arithmetic on 8- or 16-bit
ordinals and integers. The integer load instruction places 8- or 16-bit values in the low-
order end of a 32-bit register and propagates the sign bit through the high-order bits of
the register.
Occasionally, it is necessary to sign extend 8- or 16-bit integers that are generated inter-
nally, not loaded from memory. Example 9-1 shows how.
II SIGN-EXTEND 8-BIT INTEGER TO 32 BITS
II
Assume the operand is already in rlb
shl
24,
rlb,
rlb
II
left-justify
shra
24,
rlb,
rlb
II
right-justify all but sign bit
Example 9-1. Sign Extension
Example 9-2 shows how to load a small unsigned integer, converting the sign-extended
form created by the load instruction to a zero-extended form.
II LOADING OF 8-BIT UNSIGNED INTEGERS
II
Assume the address is already in r19
II
Load the operand (sign-extended) into r20
Id.b
0(r19), r20
II
Mask out the high-order bits
and
0x000000FF, r20, r20
Example 9-2. Loading Small Unsigned Integers
9-1

Advertisement

Table of Contents
loading

Table of Contents