Experiment 1 and 2
Experiment 1 and 2
The goal of this experiment is to allow students to simulate the basic operations of an ALU,
which include addition, subtraction, AND, OR, and XOR operations.
Objective:
Experiment Steps:
#include <stdio.h>
int main() {
// Input values for testing the ALU function
unsigned int A = 8, B = 7; // Example inputs
unsigned int opcode = 0; // Opcode: 0 corresponds to
addition
unsigned int result = ALU(A, B, opcode); // Call ALU
function with inputs
This experiment introduces the concept of status flags that are commonly set in a CPU after
performing an ALU operation. These flags can indicate conditions such as "zero", "negative", or
"carry out".
Objective:
#include <stdio.h>
Explanation:
The Flags struct keeps track of the status flags: zero, negative, carry, and overflow.
The ALU function now also sets these flags based on the result of the operation. For
example:
o Zero flag is set if the result is zero.
o Negative flag is set if the result is negative.
o Carry flag is set if the result exceeds the limit of a byte (assuming 8-bit).
o Overflow flag is set when the result overflows for signed operations.