Search This Blog

Wednesday, June 15, 2022

My dive into Computer Architecture (Quick look at MIPS)


Intro and Overview:

 While taking 2 courses on Computer Architecture (lab and lecture) with MIPS, I decided to compile the best resources that I could find and share some fun things I learned and built! 

I also built several interesting programs including a calculator, implemented bubble sort, and much more... I will share all the code at the end of the semester! 

MIPS is a RISC processer (reduced instruction set), the opposite would be CISC (complex), with processers such as the Intel Core and AMD Ryzen CPUS. 

The practical course primarily dealt with integers, which makes life way easier. We coded in the MIPS Mars Simulator (which has some cool tricks to it). Towards the end of the theoretical course we did cover Floating Point Conversions and Booth's Algorithm for multiplication. 



Firstly, Digital Systems is a requirement for this course: 

  • You need to understand all the basic logic gates, registers, ALUs, conversion between bases, sign magnitude ,2s complement, Boolean addition, subtraction, and multiplication. 

Next, I advise you to take an Intro to Computer Science course before starting a Computer Architecture course.

  • This will allow you to understand the bigger picture in addition to assisting you with programming in the MIPS language. 

Additional subject matter:


  • Thankfully these courses don't require a high level of math, with that being said... you should know your powers of 2...
    • including 2^0 and the negative exponents.
    • this is because we are constantly using binary digits and need to convert easily 
  • Basic addition, long division, multiplication. 
    • Mainly for converting between different bases.

The Fun Part:

I came with prior coding experience but never dealt with assembly or anything remotely close to it before. I enjoyed learning about the instruction set and converting the logic I had previously into a program with assembly. For example, a for loop looks quite different than it would in C++ or Java.
        li $t0, 10 #run loop 10 times 
        li $t1, 0 #init counter 
loop: #loop through all items
beq $t1, $t0, result #reached end
#do action
addi $t1, $t1, 1 #increment counter
                j loop #jump back to loop
                #perform action after ending the loop

Thankfully, MIPS is a reduced instruction set processer (referred to as RISC, even though MIPS might not technically be a RISC compatible processer), so there are a handful of commands that you will often use vs. thousands on a CISC (complex instruction set computer). While the code might look foreign now, there isn't much of a learning curve.

In addition, it was interesting to learn how the data-path and a computer works on the most basic level, even to just add two integers together. In addition, they had a lot of optimizations. Such as if you wanted to check that one number is equal to another... on the basic level, you just subtract one number from the other... and if the result is a 0, then they are equivalent.  


The MIPS Green Sheet is amazing, some courses let you even take it to the test with you (but not a calculator). Essentially it is a 2 page paper with all the major commands (most of them are not pseudocode), the register numbers, possible instruction types (I,J, R) and their formats. 

For practical lab-work and programming this is a good guide for starting out 


You can use this cool tool to quickly convert a C or C++ program into MIPS Assembly Code (on the web)! 
- I'm using it with mips gcc 11.2.0, there are other versions of the mips gcc compiler in addition to some RISC ones! 

Another popular tool is the MARS Simulator which runs on Java and works for Windows and MacOS. There are other tools but they aren't as easy to use... MARS also has some cool tricks up it's sleeves (mainly for Single-Cycle)... I'll make another post on this later. 


In addition, I would like to recommend this book "Computer Organization and Design MIPS Edition" , which aided me a lot in computer architecture. Note that in some additions, they have a chapter on Pipelining and others remove that chapter and replace it with Multi-Cycle... My course required us to know both, so it was a bit annoying to have to get another edition of the book. 

Please ask your professor if they are going to cover Pipelining and/or/neither Multi-Cycle and then you can make your decision based off of that. 

- the book authors also have presentation slides which your school might utilize.

I have the 3rd Edition Morgan-Kaufmann version which has a chapter on Pipelining as well as a portion on Multi-Cycle processers.

See MIPS Run is also a popular addition.

Note that Digital Systems was a prerequisite for this course, so you should also read this: 

Introduction to Logic Circuits & Logic Design with VHDL (VHDL is a net bonus and the course I took didn't require it, I study CS and not Engineering which is why). You can skip those parts in the chapter if you wish!

You can purchase the books online, borrow from a library, or find some of them online. 


While researching for the course, I found many college slide decks on each topic that helped immensely... I'd like to highlight certain institutions which did a stellar job of this: 

FSU MIPS Slides - clean design and very helpful


Here is a playlist of the best videos I found covering coding in assembly as well as the theocraticals:


I plan on making some of the code from the course public and open source in the near future, in the meantime please follow my profile on twitter and github to be updated! 

No comments:

Post a Comment