Difference between revisions of "Lab 3: ALU Flags"

From Microlab Classes
Jump to navigation Jump to search
(Created page with " == Background == Arithmetic Logic Units, or ALUs, are blocks in our computer processors that are the main components responsible for computing binary arithmetic. It isn't a...")
 
Line 4: Line 4:
 
Arithmetic Logic Units, or ALUs, are blocks in our computer processors that are the main components responsible for computing binary arithmetic. It isn't a stretch to say that ALUs are responsible for the most computations in the modern world.
 
Arithmetic Logic Units, or ALUs, are blocks in our computer processors that are the main components responsible for computing binary arithmetic. It isn't a stretch to say that ALUs are responsible for the most computations in the modern world.
  
[[File:Alu figma.png|ALU, with its inputs and outputs shown]]
+
[[File:Alu figma.png|frame|ALU, with its inputs and outputs shown]]
  
 
An ALU has three inputs: the two operands, and an operation (OPCODE in the Figure). The OPCODE tells the ALU what to do to the operands, like add, subtract, multiply, or divide. It has one output which is the output of the ALU operation.
 
An ALU has three inputs: the two operands, and an operation (OPCODE in the Figure). The OPCODE tells the ALU what to do to the operands, like add, subtract, multiply, or divide. It has one output which is the output of the ALU operation.

Revision as of 17:43, 4 March 2025

Background

Arithmetic Logic Units, or ALUs, are blocks in our computer processors that are the main components responsible for computing binary arithmetic. It isn't a stretch to say that ALUs are responsible for the most computations in the modern world.

ALU, with its inputs and outputs shown

An ALU has three inputs: the two operands, and an operation (OPCODE in the Figure). The OPCODE tells the ALU what to do to the operands, like add, subtract, multiply, or divide. It has one output which is the output of the ALU operation.

Additionally, the ALU has special outputs called flags (STATUS in the Figure). Some examples include:

  • Zero flag (Z): 1 if the result is zero.
  • Negative flag (N): 1 if the result is negative.
  • Carry flag (C): Carry out of the ALU operation. Example: 1100 + 1001 will cause the carry flag to be set.
  • Overflow flag (O): 1 if the result has an overflow or an underflow. That is, the binary output arithmetic is not correctly representable in the current bitwidth. Example: 0111 (7) + 0001 (1) = 1000 (-8), or 1000 (-8) + 1110 (-2) = 0110 (6) will cause the overflow flag to be set.

Instructions

Your assignment is as follows:

  1. Download the ALU template in UVLe.
  2. Implement an 8-bit ALU that can perform ADD, SUBTRACT, Bitwise AND, and Bitwise OR, depending on the input ALU_OP. Make sure it follows the table below.
  3. Implement the 4 flags Z, N, C, O.

Do NOT use blocks from the arithmetic library in Logisim.

Notes:

  • Again, do not move any input or output pins in the template.