Two numeric operators, addition and subtraction, were introduced in Section 9.2. Many data items are better thought of as bit patterns rather than numerical entities. For example, study Table 2.7.1 and see if you can determine which bit determines the case (upper/lower) of the alphabetic characters.

In order to manipulate individual character codes in a text string, we introduce the bit-wise logical instructions in this section. The bitwise logical operations were shown in the truth tables in Table 4.3.2–Table 4.3.4. The instructions available to us to perform the three binary operations are:

<Rd> specifies the destination register, and <Rm> and <Rn> are the source registers. <Rs> contains the shift amount in the “register-shifted register” form.

\(-257 \le const \le +256\text{,}\) or \(const = +256, +260, +264, \ldots, +65280\text{,}\) or \(const = -261, -265, \ldots, -65281\text{.}\) This odd sequence of values will be explained in Section 11.3.3

In the “immediate” form, a bitwise AND is performed between <const> and the value in <Rn>. In the “register” and “register-shifted register” forms, a bitwise AND is performed between the value in <Rm> and the value in <Rn>. If a shift is specified, the value in <Rm> is shifted by the specified amount before the AND is performed. If <Rd> is present the result is stored there and <Rn> is unchanged. If not, the result is stored in <Rn>. The values in <Rm> and <Rs> are unchanged.

ORR

Performs a bitwise inclusive OR between two integers.

<Rd> specifies the destination register, and <Rm> and <Rn> are the source registers. <Rs> contains the shift amount in the “register-shifted register” form.

\(-257 \le const \le +256\text{,}\) or \(const = +256, +260, +264, \ldots, +65280\text{,}\) or \(const = -261, -265, \ldots, -65281\text{.}\) This odd sequence of values will be explained in Section 11.3.3

In the “immediate” form, a bitwise inclusive OR is performed between <const> and the value in <Rn>. In the “register” and “register-shifted register” forms, a bitwise inclusive OR is performed between the value in <Rm> and the value in <Rn>. If a shift is specified, the value in <Rm> is shifted by the specified amount before the inclusive OR is performed. If <Rd> is present the result is stored there and <Rn> is unchanged. If not, the result is stored in <Rn>. The values in <Rm> and <Rs> are unchanged.

EOR

Performs a bitwise exclusive EOR between two integers.

<Rd> specifies the destination register, and <Rm> and <Rn> are the source registers. <Rs> contains the shift amount in the “register-shifted register” form.

\(-257 \le const \le +256\text{,}\) or \(const = +256, +260, +264, \ldots, +65280\text{,}\) or \(const = -261, -265, \ldots, -65281\text{.}\) This odd sequence of values will be explained in Section 11.3.3

In the “immediate” form, a bitwise exclusive OR is performed between <const> and the value in <Rn>. In the “register” and “register-shifted register” forms, a bitwise exclusive OR is performed between the value in <Rm> and the value in <Rn>. If a shift is specified, the value in <Rm> is shifted by the specified amount before the exclusive OR is performed. If <Rd> is present the result is stored there and <Rn> is unchanged. If not, the result is stored in <Rn>. The values in <Rm> and <Rs> are unchanged.

The bitwise NOT instruction, mvn , and the bitwise compare instruction, tst , have already been given.

Listing 14.1.1 shows a how the and instruction can be used to convert lowercase characters to uppercase when some of the characters may already be uppercase. The algorithms of both the main and toUpper functions are very similar to those of main and writeStr in Exercise 13.2.1.4 and Exercise 13.2.1.2, respectively, so I go directly to assembly language rather than show the C solution first.

Subsection14.1.1Exercises

1

Write a program in assembly language that (a) prompts the user to enter some alphabetic characters, (b) converts any uppercase characters to lowercase, and (c) displays the resulting uppercase string. Your algorithm must allow for the user to enter lowercase characters and leave them as lowercase.