The Juno ALU is an 8 bit design supporting 8 functions selected via a 3 bit operation selector control.
The ALU takes its input from left and right buses and places the calculated output on the ALU's out bus. The output is not synchronised to the clock and therefore follows the inputs and will fluctuate for a period as both the inputs and internal logic stabilise.
The ALU additionally outputs a number of flags indicating carry, overflow, zero, negative conditions that are stored in the control register
Operation select - the ALU supports 8 mathematical and logical functions selected by the 3 bit operation select control lines.
- AND : logical AND
- OR : logical OR
- NOT : logical NOT
- XOR : logical XOR
- CMP : logical compare. Performs a subtraction and sets the Zero flag if the two inputs are equivalent. The result is discarded.
- ADD : mathematical addition without carry
- ADC : mathematical addition with carry in from the control register
- SUB : mathematical subtraction.
Flags - the flags are saved to the control register
- carry : set if the result of the mathematical operation was too big to fit in 8 bits. Note that the ALU will always calculate carry but the flag only makes sense if an unsigned mathematical operation was performed.
- overflow : set if the mathematical operation resulted in an overflow. Note that the ALU will always calculate overflow but the flag only makes sense if a 2's complement mathematical operation is being performed. In a 4 bit ALU 7 + 7 = 14 (1110) if the programmer is interpreting numbers as unsigned but if the programmer is interpreting numbers as 2's complement then the output is -2. The overflow flag can be checked for the occurrence of this type of error.
- zero : set if the output is 0. Useful for implementing loops when combined with Branch Not Equal. e.g. decrement counter and branch if not zero.
- negative - set if the MSB is 1. Only makes sense when 2's complement notation is being used.
Carry in - the carry flag from the control register is used by ADC. For ADD the carry in is forced to 0.
ALU left/right input buses - 8 bit left and right input buses.
ALU Output bus - 8 bit bus onto which the calculated output is placed.
NB in terms of implementation subtraction can be implemented by using XOR logic to invert the B input (XORing the input with 1 causes the input to be inverted whereas 0 leaves it unaffected) and forcing the carry input to the adder to be 1 to calculate the 2's complement (ORing the carry in from the control register with 1 if performing subtraction forces the carry to be set). This approach does not allow subtract with carry to be implemented as the carry input to the adder has been used to calculate the 2's complement. Subtraction with carry should therefore be performed using ADD and 2's complement representation.
No comments:
Post a Comment