Question
For project 2 you are provided with a C++ class file ALU.cpp/.h which uses the enum function. Look at the source code and list the
For project 2 you are provided with a C++ class file ALU.cpp/.h which uses the enum function. Look at the source code and list the possible values that you can use for ALU_OP.
ALU.h:
#ifndef __ALU_H
#define __ALU_H
#include
#include
#include
#include
#include "Debug.h"
using namespace std;
enum ALU_OP { ADD, AND, SHF_L, SHF_R, CMP_LT, MUL, DIV };
class ALU {
private:
uint32_t upper, lower;
public:
uint32_t op(ALU_OP op, uint32_t src1, uint32_t src2);
uint32_t getUpper() const { return upper; }
uint32_t getLower() const { return lower; }
};
#endif
ALU.CPP:
#include "ALU.h"
uint32_t ALU::op(ALU_OP op, uint32_t src1, uint32_t src2) {
switch(op) {
case ADD : return (signed)src1 + (signed)src2;
case AND : return src1 & src2;
case SHF_L : return src1 << src2;
case SHF_R : return (signed)src1 >> src2;
case CMP_LT: return ((signed)src1 < (signed)src2) ? 1 : 0;
case MUL : {
uint64_t wide = (uint64_t)src1 * (uint64_t)src2;
lower = wide & 0xffffffff;
upper = wide >> 32;
}
break;
case DIV : if(src2 == 0) {
cerr << "division by zero!" << endl;
exit(-1);
}
lower = src1 / src2;
upper = src1 % src2;
break;
default: cerr << "unimplemented ALU operation: op = " << dec << op << endl;
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started