Skip to content

Instantly share code, notes, and snippets.

@jadudm
Created October 25, 2014 14:56
Show Gist options
  • Save jadudm/8137d280a7832742adbd to your computer and use it in GitHub Desktop.
Save jadudm/8137d280a7832742adbd to your computer and use it in GitHub Desktop.
EALU Starter Template for Midterm Checkpoint
/* EALU starter file for CSC 335 Midterm Checkup.
* CC0 2014 by Matt Jadud
* Compile with:
* gcc -o ealu ealu.c
* and execute then with
* ./ealu
*/
#include <stdint.h>
#include <stdio.h>
#define ERROR 0xFFFF
uint16_t alu (uint16_t x, uint16_t y, uint8_t instr) {
/* Your code to implement the extended ALU goes here. */
/* Please use a switch statement. */
/* The default case should return the value ERROR. */
/* literally,
*
* default:
* return ERROR;
* break;
*/
}
int main () {
uint16_t x, y;
uint8_t instr;
int error = 0;
/* Some simple tests. */
printf ("Tests for the EALU\n");
printf ("------------------\n");
if (!(alu(0x0042, 0xBEEF, 0x2A) == 0)) {
printf ("The EALU should return 0 in this case.\n");
error += 1;
}
if (!(alu(0x02, 0x02, 0x1F) == 0x03)) {
printf ("The EALU should return x+1, which is 2+1, or 3, in this case.\n");
error += 1;
}
/* You should write additional tests.
* Your tests should only be noisy in the case of failure.
*/
/* The following code should not need modification. It prints
* the results of your tests.
*/
if (error > 0) {
printf ("The EALU failed to pass %d test", error);
/* Proper plurality agreement is so difficult when writing code...
* Good Grammar Or Bust! *cough*
*/
if (error > 1) {
printf ("s.\n");
} else {
printf (".\n");
}
} else {
printf ("All tests passed!\n");
}
/* We can return anything here, so I choose to return the meaning of life,
* the universe, and everything, as defined by Doubglas Adams.
* Zero, of course, is traditional, and suggests everything worked OK.
*/
return 0x2A;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment