Remember to check memory's bounds before accessing it!
Use uint32_t to represent data/instructions/register values
Use int to represent booleans and anything that doesn't need more than 16 bits (apparently ints can be only 16 bits on some systems)
Use bool to represent booleans and int (if you want) to represent anything that doesn't need more than 16 bits (apparently ints can be only 16 bits on some systems)
int32_t applyOperation(int opcode, int32_t operand1, int32_t operand2, int *carry, int *store)
Applies a binary operation (from an opcode) on two operators. Returns the result, and sets the supplied carry bit if it makes sense to do so.
Doesn't change the carry bit when performing a logical operation.
IMPLEMENTED
IMPLEMENTED, needs tests
void multiplyInstr(struct ProcessorState *processor, int address)
...
...
@@ -63,12 +63,12 @@ HELPER FUNCTIONS (probably used in more than one method):
uint32_t getBits(uint32_t source, int start, int end)
Reads bits from source in the range [start, end] (inclusive). Returns a uint32_t with the result as its least significant bits.
(e.g. getBits(8, 2, 3) == 2)
IMPLEMENTED
(e.g. getBits(8, 2, 3) == 2 because 8 == 0000'10'00)
IMPLEMENTED, TESTED
int isSet(uint32_t source, int index)
Shorthand for getBits(source, index, index)
IMPLEMENTED
IMPLEMENTED, TESTED
int validCond(uint32_t cond, struct ProcessorState *processor)
Returns 1 if the condition code 'cond' is satisfied by the processor's current state, and 0 otherwise.
...
...
@@ -76,12 +76,12 @@ int validCond(uint32_t cond, struct ProcessorState *processor)
uint32_t barrelShift(int immediate, uint32_t operand, int *carry, struct ProcessorState *processor)
Implements the functionality of the barrel shifter. The carry output is written to (*carry), just in case you need it.
NOTE: for some reason the I bit is used in opposite ways for data processing instructions vs for data transfer instructions. Arbitrarily, let this method
assume that the data processing instruction interpretation is the right one (so for data transfer instructions just call this method with NOT i).
IMPLEMENTED
NOTE: for some reason the I bit is used in opposite ways for data processing instructions vs for data transfer instructions. Arbitrarily, this method
uses the data processing instruction interpretation (so for data transfer instructions just call this method with !I).
IMPLEMENTED, TESTED
struct ProcessorState *makeProcessor(void)
Creates a new processor struct
Creates a new processor struct. Dynamically allocated, so don't forget to use free() at the end!
IMPLEMENTED
(optionally)
...
...
@@ -91,5 +91,24 @@ int32_t *accessMemory(struct ProcessorState *processor, int address)
Put other stuff you've implemented here!
TESTING STUFF:
void test(bool pass, char *testname)
prints out a formatted message stating the test name and whether it passed.
IMPLEMENTED
uint32_t bin(char* number)
converts a string representing a binary number (e.g. "01001") to a number. For testing purposes.
Ignores spaces and leading zeros, so you can format it like the instructions ("0001 0 00 1 0000").
Doesn't actually check the input at all, so only use it for testing.
IMPLEMENTED
implemented tests:
void testBitGetters(void)
void testBarrelShifter(void)
tests still needed:
applyOperation (and maybe validCond, but it's quite a simple function so idk)