Jump to content

Introduction to MIPS (load values, LEDs, and jump instruction)


WarFox
 Share

Recommended Posts

Introduction

 

Before the compiler, there was the assembler. The invention of the assembler revolutionized early computers. Previous to the assembler, instructions were submitted to a computer physically by some action as throwing a physical switch. The pre-assembler world meant programming a computer in the machine's own native tongue, machine code. A tricky combination of countless 1s and 0s for even the simplest calculations. While, most challenges today do not require the use of assembly, it is still vital to learn. Through my learning, I have learned a deeper understanding of what is going on at the lower level. It is refining the process of thinking through solving challenges at a higher language and giving concrete ideas to  what an array, stack, or other data structures look like in the CPU's world.

 

Tool

 

The tool used is one that my university uses. It is called PLPTool. It is an IDE and simulation environment for assembly based on the MIPS Instruction set. It does not support the full MIPS instruction set, but 27 instructions that are most vital in MIPS. It is an educational tool. PLPTool is written in Java, so to run you will need a jvm/jre to run. From the site, they have executables for linux, mac, and windows. However, beaware that if your running java that is greater than version 8, it will not recognize this. If this is the case, just download the jar and run it from the command prompt/terminal.

java -jar <JAR File>

 

Link to PLPtool site: http://progressive-learning-platform.github.io/home.html

PLPtool comes with a lot of ways to visualize and simulate actions. There is a tool built in to view the registry file, givings a look at values held within registers. There is an LED tool to see LEDs that are lit up, and switches to use switches to interact with the program. These are just a few examples. Below are two images.

Spoiler

954542232_Screenshotfrom2019-09-1204-44-55.png.7f41e4ebbd796f17b44e0c50b9aca02d.png

Spoiler

1196098307_Screenshotfrom2019-09-1204-46-33.thumb.png.2bfeb627a4086d328201a5bd90154653.png

 

Registers

 

Registers can be thought of as just storage locations. PLPTool has 9 temporary registers that we will use for an introduction to assembly with this tool. These registers are $t0-$t9. Registers in PLPTool will typically hold a maximum value of 'oxfffffffff' in hexidecimal. That is 8 'f's. A converter can be used to find the decimal value.

Inputs into registers can come in several different forms. For this tutorial, I will focus on 3. We can define values for registers using binary, decimal and hexadecimal. If you are unfamiliar with these three numbers systems, I would recommend reading about those systems before continuing with this tutorial.

Load Immediate Instruction

The first instruction to learn is called the load immediate instruction. This instruction is more of like a function of 2 more basic functions, but I will not cover that here. The load immediate instructions takes as arguments a register and a value. When it is ran, the value will be placed in the register defined. It takes two clock cycles for this instruction to complete. Think of it is as the instruction running twice.

646365172_Screenshotfrom2019-09-1205-00-09.png.f5f1118627c8af8975445b05348fa124.png

2076010825_Screenshotfrom2019-09-1205-00-22.png.b917eadc764ddc73e101b0cdc65f1558.png

The program above shows the syntax. The command is li, followed by the register and a value. This is decimal value of 1. Accompanied by it is another image that shows what the registry file looks like after it is ran. The value of 1 is stored in register $t0.

260883360_Screenshotfrom2019-09-1205-03-39.png.aae645bdb49c5b3a8b5e1ec9ade3a1b5.png

1198784459_Screenshotfrom2019-09-1205-03-48.png.da7568010666eab55cfaba7c42841302.png

 

Special Memory Locations

Special memory locations exists. These special locations in memory are often used to interface with I/O devices. If you are familiar with C, the locations look like a memory location output of a pointer. The addresses are in hexidecimal.

1330359559_Screenshotfrom2019-09-1205-07-56.png.1cb41dc31368f0ab457df8f52813df3d.png

For now, we will focus on the LED. In order to use the LEDs, we must first set a register to the value of the memory address. When we access the register, we will be accessing the memory address store in.

1972114563_Screenshotfrom2019-09-1205-16-56.png.03ed69427afa6a77fe9017fce9c9bf0a.png

Store Word Instruction

In order to make the LEDs output a value, we will need to use the store word instruction. This instruction takes 2 registers, and store the value of one inside of the other. In the case of LEDs, it will copy the value from one register into the memory address store in the other register.

1133231518_Screenshotfrom2019-09-1205-19-27.png.4bb7acb84c5bf3b5c717ef10e0729d2d.png

1807212123_Screenshotfrom2019-09-1205-19-38.png.56ce3e38afd5d75f3296d16548810f6b.png

 

Beginning control flow

 

Control flow is vital to how a computer program operates. We are familiar with them in languages such as C or java via if/else statements and methods/procedures/subroutines/functions. The first instruction for controling the flow of a program to learn in MIPS is the jump instruction. Think of it as making a function that is going to return void. Also, an important note, it will not leave the jump instruction to resume it's position in the program where it left off prior to the jump. Think of it as working in one direction. Here is some psuedo code that will hopefully explain it.

Spoiler

Main:

    set x equal to 10

    jump to add-1

    set y equal to 12

add-1:

    set x equal to x + 1

 

sub-1:

    set x equal to x - 1

 

In the pseudo code, we have a main function and two other functions. When executing this, we will set x equal to 10. Followed by jumping to the instructions in  'add-1'. Inside of 'add-1', we will add 1 to the value stores in x. The next code that will be executed in assembly will be the code inside of the function 'sub-1'. The code does not jump back up to main and execute set y equal to 12.

 

Labels

Before we begin jumps, we must learn how to define a "function." We simple name the function then follow it with a colon. It is the same as to how I defined main, add-1, and sub-1 in the pseudo code above.

 

Jump statement

The jump statement has a simple syntax.

j my_label

Sample code:

1987536574_Screenshotfrom2019-09-1205-32-28.png.9064e95271131893fba10afc2c170a21.png

 

LED output in order

Spoiler

992665650_Screenshotfrom2019-09-1205-33-45.png.5d498af87516dd9d274990a03f24bf39.png

1227965635_Screenshotfrom2019-09-1205-33-59.png.408a64bb6d8739fd9b4dd6da4cb3587b.png

211165940_Screenshotfrom2019-09-1205-34-09.png.ccfa9a08d1f19822206b0bf004fcf378.png

1118133373_Screenshotfrom2019-09-1205-34-19.png.8f70a43a3f58ef503cd10adca538f94c.png

As you may notice from the code, this program will loop.

  • I Like This! 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...