top of page

Computer Architecture ECE/CS250

Easily one of the more challenging and fulfilling courses I've taken at Duke, ECE 250 unlocked the inner workings of a computer to me. The blackboxes and voodoos behind snazzy terms like caches, multithreading, and other wizardly speak was now a part of my daily vocabulary. Prof. John Board is a genius - he is clearly extremely passionate about the field and loves to speak about the entire world of computers. It was a pleasure to learn with him.


Below, I would like to chronologically share the work I've done in this course - each conducted with less sleep than the previous.


Note for all 250 Students: This is my commentary on the projects I've done in this class. All solutions have been hidden. Taking ideas is allowed, but taking the code itself is at risk of violating the Duke Community Standard.


Homework 1: Linked List Manipulation in C

This project dipped our toes into the world of programming that in Dr. Board's words would allow you to shoot yourself in the leg if you're not careful with what you're doing. The guardrails we were used to in Java no longer existed. Segfaults were a thing. Coding was a lot more precarious. The following is a code snippet. The full assignment is here.


  for (current = firstNode; current != NULL; current = current->next) {
        for (nextNode = current->next; nextNode != NULL; nextNode = nextNode->next) {

            float eff1 = current->energy/(float) current->sqfoot;
            float eff2 = nextNode->energy/(float) nextNode->sqfoot;

            //I will try pointer manipulation next! Not a fan of the wordiness
            if (eff1<eff2) {
                tempSq = current->sqfoot;
                tempEn = current->energy;
                tempName = current->buildName;

                current->sqfoot = nextNode->sqfoot;
                current->energy = nextNode->energy;
                strcpy(current->buildName, nextNode->buildName);

                nextNode->sqfoot = tempSq;
                nextNode->energy = tempEn;
                strcpy(nextNode->buildName, tempName);

            }
        }
    }

Homework 2: MIPS Assembly

You see the already menacing code that is simply the known friendly algorithm of bubble sort above? Well, try writing that in assembly. I have not spent more time over a homework project. Translating the previous assignment in assembly was definitely one of the hardest things I had to do. It was disorienting enough to work in C when we were introduced to assembly code.


 move $t0, $t5
    move $t3, $t5
    move $t4, $t5 
    move $a1, $t2 # string value
    li $t1, 0

    store_loop:
    lb $t2, 0($a1)      # Load a byte from the source string
    sb $t2, 0($t0)      # Store the byte in the allocated memory
    addi $a1, $a1, 1    # Move to the next byte in source string
    addi $t0, $t0, 1    # Move to the next byte in allocated memory
    addi $t1, $t1, 1    # Increment counter
    blt $t1, 64, store_loop  # Repeat until 64 bytes are stored

The above snippet was unfortunately the better bits. When we turned to the internet for conceptual understanding, many of our peers asked, "Why would you have to implement a linked list in MIPS Assembly?" The full assignment is here.


Homework 3: Finite State Machine

One of the most enjoyable assignments I've ever done, this involved building a finite state machine for an imaginary vending machine. It was wonderful to note that many seemingly complex protocols don't require a processor - they are easily executable with a complex array of ands and ors (gates). We first created a Moore Machine by creating a spreadsheet of the truth tables that defined the machine. Tasked with an albeit humourously worded problem, we were supposed to dispense pills that helped students stay awake when they inputted exactly $0.15. Below I've shown the FSM Diagram and the Truth Table for the same.


Finite State Diagram



Segment of the Machine in Logisim


Homework 4: CPU

Remember the finite state machine we built in logisim? We must now apply new principles and simulate a full CPU in logisim again. Albeit, the operations this CPU could do were limited to simple math, printing, reading, and loading, and storing from memory, it was certainly an insightful experience. Below is a snippet of the instruction memory being loaded and deciphered in each clock cycle.



Homework 5: Cachesim

Finally, the last program was simulating a cache - how the memory works inside a CPU from the lowest level in a register to the highest in the hard-drive, it was incredible to write code that simulated this hierarchical ordering of memory. This was certainly a more open ended problem with many methods of approaching it.



            unsigned int blockStartAdr = hexAd & ~((1<<offsetBits)-1);
            unsigned int blk_offset = hexAd & ((1<<offsetBits)-1);
            unsigned int index =  (blockStartAdr >> offsetBits) & ((1<<indexBits)-1);
            unsigned int tagIn = blockStartAdr >> (offsetBits+indexBits);

Harsh Mathur's Portfolio

©2024 Harsh Mathur

bottom of page