登录

Bit Manipulation

Label

Opcode

Operand

Explanation

AND

#n/Bn/&n

Bitwise AND operation of the contents of ACC with the operand

AND

<address>

Bitwise AND operation of the contents of ACC with the contents of <address>

XOR

#n/Bn/&n

Bitwise XOR operation of the contents of ACC with the operand

XOR

<address>

Bitwise XOR operation of the contents of ACC with the contents of <address>

OR

#n/Bn/&n

Bitwise OR operation of the contents of ACC with the operand

OR

<address>

Bitwise OR operation of the contents of ACC with the contents of <address>

LSL

#n

Bits in ACC are shifted logically n places to the left. Zeros are introduced on the right hand end

LSR

#n

Bits in ACC are shifted logically n places to the right. Zeros are introduced on the left hand end

<label>:

<opcode>

<operand>

Labels an instruction

<label>:

<data>

Gives a symbolic address <label> to the memory location with contents <data>

  • All questions will assume there is only one general purpose register available (Accumulator) ACC denotes Accumulator

  • IX denotes Index Register

  • <address> can be an absolute or symbolic address

  • # denotes a denary number, e.g. #123

  • B denotes a binary number, e.g. B01001010 & denotes a hexadecimal number, e.g. &4A

  • ## Binary shifts

  • Logical shift – bits shifted out of the register are replaced with zeros.

  • Arithmetic shift – the sign of the number is preserved.

  • Cyclic shift –Bits shifted out of one end of the register are introduced at the other end of the register.

  • Left shift – bits are shifted to the left; gives the direction of shift for logical, arithmetic and cyclic shifts.

  • Right shift – bits are shifted to the right; gives the direction of shift for logical, arithmetic and cyclic shifts.

Opcode

Operand

Explanation

LSL

n

Bits in ACC are shifted logically n places to the left. Zeros are introduced on the right hand end

LSR

n

Bits in ACC are shifted logically n places to the right. Zeros are introduced on the left hand end

Shifts are always performed on the ACC

Bit manipulation used in monitoring and control

In monitoring and control, each bit in a register or memory location can be used as a flag and would need to be tested, set or cleared separately.

  • AND is used to check if the bit has been set.

  • OR is used to set the bit.

  • XOR is used to clear a bit that has been set.

Opcode

Operand

Explanation

AND

n

Bitwise AND operation of the contents of ACC with the operand

AND

<address>

Bitwise AND operation of the contents of ACC with the contents of <address>

XOR

n

Bitwise XOR operation of the contents of ACC with the operand

XOR

<address>

Bitwise XOR operation of the contents of ACC with the contents of <address>

OR

n

Bitwise OR operation of the contents of ACC with the operand

OR

<address>

Bitwise OR operation of the contents of ACC with the contents of <address>

  • The results of logical bit manipulation are always stored in the ACC.

  • <address> can be anabsolute address or a symbolic address.

  • The operand is used as the mask to set or clear bits.

Bit operation
填空题
ID:118

State the contents of the accumulator after the following instructions have been executed. The accumulator contains 00011001.

  • LSL #4 (ACC:)

  • LSR #5 (ACC:)

[0/2]

Bit operation
填空题
ID:119

Write an assembly language instruction to

  • set bit 4 in the accumulator ()

  • clear bit 1 in the accumulator ()

[0/2]

登录