Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/14/19 in all areas

  1. 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. 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. 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. 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. 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. 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. 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. 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: LED output in order As you may notice from the code, this program will loop.
    1 point
×
×
  • Create New...