0% found this document useful (0 votes)
131 views

9618 Ch-7.3 Lesson Notes

The document discusses using bit manipulation to control devices by setting flags represented by individual bits. It provides examples of assembly language code that can set and toggle bits to represent sensor states, including setting all bits to zero, toggling a single bit, setting a bit to one, and setting all but one bit to zero to check its value. The code loads bytes from memory addresses, performs bitwise logic operations to manipulate the bits, and stores the results back to the original addresses.

Uploaded by

Black Night
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views

9618 Ch-7.3 Lesson Notes

The document discusses using bit manipulation to control devices by setting flags represented by individual bits. It provides examples of assembly language code that can set and toggle bits to represent sensor states, including setting all bits to zero, toggling a single bit, setting a bit to one, and setting all but one bit to zero to check its value. The code loads bytes from memory addresses, performs bitwise logic operations to manipulate the bits, and stores the results back to the original addresses.

Uploaded by

Black Night
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

ST.

NICHOLAS’ INTERNATIONAL COLLEGE


7.03 Bit manipulation to control devices
The controlling computer or microprocessor has to have a real-time program running continuously. The
program can set values for Boolean variables subject to what the sensors detect.
IF SensorDifferencel > 0 THEN SensorlHighFlag ← TRUE
IF SensorDifferencel < 0 THEN SensorlLowFlag ← TRUE
IF SensorDifference2 > 0 THEN Sensor2HighFlag ← TRUE
IF SensorDifference2 < 0 THEN Sensor2LowFlag ← TRUE

Another part of the monitoring and control program would then be checking whether any of the four flags were
set. The machine code for running such a program could use individual bits to represent each flag. The way
that flags could be set and read are illustrated by the following assembly language code fragments.
1. The following illustrates the setting of all bits to zero which might be used when the system is switched on.

LDD 0034 Loads a byte into the accumulator from an address.


AND Uses a bitwise AND operation of the contents of the accumulator with the operand to
#B00000000 convert each bit to 0.

STO 0034 Stores the altered byte in the original address.

2. The following illustrates the toggling of the value for one bit. This changes the value of the flag it represents.
It might be needed because a problem has been encountered or alternatively because a problem has been
solved.

LDD 0034 Loads a byte into the accumulator from an address.


XOR Uses a bitwise XOR operation of the contents of the accumulator with the operand to
#B0000000l toggle the value of the bit stored in position 0.

STO 0034 Stores the altered byte in the original address.

3. The following illustrates the setting of a bit to have value 1 irrespective of its existing value. This would be a
simple way of just reporting a condition repetitively.

LDD 0034 Loads a byte into the accumulator from an address.


OR #B00000l00 Uses a bitwise OR operation of the contents of the accumulator with the operand to set
the flag represented by the bit in position 2. All other bit positions remain unchanged.

STO 0034 Stores the altered byte in the original address.


4. The following illustrates setting all bits to zero except one bit which is of interest. Following this operation, a
comparison can be made with a binary value to check if the bit is set. In this example the value would be
compared to the binary equivalent of denary 2.

LDD 0034 Loads a byte into the accumulator from an address.


AND Uses a bitwise AND operation of the contents of the accumulator with the operand to
#B000000l0 leave the value in position 1 unchanged but to convert every other bit to 0.

STO 0034 Stores the altered byte in the original address.

COMPUTER SCIENCE Chapter 15 – Software Development AL-9618

You might also like