10. Two Register Instructions
Part of
the Hawk Manual

10.1. Two Register Format
10.2. Bitwise Logical Operations
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       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.
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 OR EQU  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 exclusiveor of two operands can be computed using a combination of NOT and EQUIV. For example, the following sequence exclusiveors r[4] with r[3]:
EQUIV R3,R4 NOT R3
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 96bit registertoregister sum. Here, we store each 96bit operand in 3 consecutive 32bit registers, with the least significant 32 bits in the lowest numbered registers. The destination operand is in r[35] while the source operand is in r[68]:
ADD R3,R3,R6 ; add low 32 bits ADDC R4,R7 ; add middle 32 bits ADDC R5,R8 ; add high 32 bits
ADDC sets the BCDcarry bits in the processor status word. (see Section 1.3.4.1). As a result, in combination with ADD and ADJUST it can be used to do highprecision BCD or excess3 arithmetic (see Section 11.2).
For both ADDC and SUBB, src may be zero, in which case r[0] is taken as the constant zero. As a result, in combination with ADDSL The following sequence rotates the 32 bit value in r[1] 1 bit left, so that the old value of the sign bit goes into the least significant bit:
ADDSL R3,R0,1 ; shift 1 bit left ADDC R3,R0 ; bring carry around
The ADDC instruction alone, with src=dst, rotates the 33 bit value composed of the source register concatenated with the condition code register 1 bit left. This is useful for leftshifting multiword quantities, so ssemblers should treat ROL dst (rotate left) as a synonym for ADDC dst,dst.
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=dst  ROL  dst  r[dst]= (r[dst]<<1)+C 