# 10. Two Register Instructions

## 10.1. Two Register Format

 07 06 05 04 03 02 01 00 15 14 13 12 11 10 09 08 0 0 0 1 dst - - - - src

The two register arithmetic format instructions are 16 bits each, specifying one source register r[src] and one destination register r[dst]. All instructions in this group combine the value in r[src] with the value in r[dst], changing only the latter and the condition codes.

## 10.2. Bitwise Logical Operations

 07 06 05 04 03 02 01 00 15 14 13 12 11 10 09 08 0 0 0 1 dst (nz) 1 0 1 1 src (nz) AND dst,src r[dst] =(r[dst] ∧ r[src]) 0 0 0 1 dst (nz) 1 0 1 0 src (nz) OR dst,src r[dst] =(r[dst] ∨ r[src]) 0 0 0 1 dst (xz) 1 0 0 1 src (0) EQU dst,src r[dst] =(r[dst] ≡ r[src])

 AND      OREQU N = r[dst]:31 — result is negative Z = (r[dst] = 0) — result is zero V = C = 0

AND, OR and EQU (equivalent) operations combine each bit of the source register with the corresponding bit of the destination register using the indicated boolean operation.

For AND, each bit of r[dst] will be set only if it was already set there and the corresponding bit was also set in r[src].

For OR, each bit of r[dst] will be set if it was already set there or if the corresponding bit was also set in r[src].

Both AND and OR require that the src and dst be nonzero. If r[0] is used, it will cause an instruction trap (see Chapter 13). Assemblers should flag use of r[0] as an error.

For EQU, each bit of r[dst] will be set only if the original value of that bit was equal to the corresponding bit in r[src]. In logical terms, EQU computes the inverse of the exclusive or of its oprands because (a≡b) = ~(a⊕b).

Because ~x (not x) is the same as x≡0 (comparing the bits of x with zero), use of r[0] as a source operand is legal with EQU and it is interpreted as holding constant zero. Assemblers should support NOT Rd as a synonym for EQU Rd,R0.

 07 06 05 04 03 02 01 00 15 14 13 12 11 10 09 08 0 0 0 1 dst (nz) 1 0 0 1  0 0 0 0 NOT dst r[dst] = ~r[dst]

Because EQU computes the inverse of exclusive or, the exclusive-or of two operands can be computed using a combination of NOT and EQUIV. For example, the following sequence exclusive-ors r[4] with r[3]:

```        EQUIV   R3,R4
NOT     R3
```

## 10.3. Extended Precision Arithmetic

 07 06 05 04 03 02 01 00 15 14 13 12 11 10 09 08 0 0 0 1 dst (x) 0 1 1 1 src (0) ADDC dst,src r[dst]=r[dst]+r[src]+C 0 0 0 1 dst (x) 0 1 1 0 src (0) SUBB dst,src r[dst]=r[dst]-r[src]-~C

 ADDC N = r[dst]:31 — result is negative Z = (r[dst] = 0) ∧ Z — result is zero V = (( r[dst]:31 ⊕ r[dst]':31 ) ∧ ( r[dst]':31 ≡ r[src]':31 )) C = carry out of adder SUBB N = r[dst]:31 Z = (r[dst] = 0) ∧ Z V = (( r[dst]:31 ⊕ r[dst]':31 ) ∧ ( r[dst]':31 ⊕ r[src]':31 )) C = not borrow from difference

ADDC (add with carry) and SUBB (subtract with borrow) are used to do integer arithmetic on quantities longer than 32 bits. These add or subtract one register from another taking into account the carry or borrow bit left over from the addition or subtraction of the less significant bits.

The condition codes (see Section 1.3.4.1) reflect the extended precision result. N is set if the result is negative, Z is set if the entire result is zero; that is, it is reset if the result was nonzero, and it remains set only if the result was zero and it was already set. V is set if two's complement overflow occurred, and C is set if there was a carry out of the most significant bit (equivalent to no borrow out of the most significant bit).

The following sequence starting with a regular ADD instruction (see Section 8.2) for the least significant 32 bits does a 96-bit register-to-register sum. Here, we store each 96-bit operand in 3 consecutive 32-bit registers, with the least significant 32 bits in the lowest numbered registers. The destination operand is in r[3-5] while the source operand is in r[6-8]:

```	ADD	R3,R3,R6	; add low 32 bits
```	ADDSL	R3,R0,1		; shift 1 bit left