How To Read Register $t0 In Simulator
PCSpim is a freely available personal computer simulator for MIPS. It simulates behavior of a MIPS processor on an Intel based machine. SPIM was originally adult by Dr James Larus at the Academy of Wisconsin, Madison around 20 years ago. You tin can download it from the Academy of Wisconsin, Madison website: http://www.cs.wisc.edu/~larus/SPIM/pcspim.nothing. Using this simulator you can unmarried-stride your program instruction by education and run across the changes in register and retentiveness contents during the execution of the program. The programs are written in MIPS associates language using any text editor like Notepad. Delight annotation that you need to relieve your program using the extension ".asm" or ".s".
Understanding the PCSpim GUI
Before agreement pcspim you demand to install pcspim software on your system. check this video to know how to download and install pcspim software:
Double click on PCSpim and the following screen will appear (picture taken from internet).
Different areas of the PCSpim screen are explained below:
- This window is called the Registers Window. It contains data about the Program Counter (PC), General registers, Single and Double Floating Point Registers. Each of these registers is 32 bits wide. To view register values in decimal, select Settings in Simulator carte and unchecked View General Registers in Hex.
- This window displays the contents of the Text/Code Segment. The text segment is the portion of the memory that contains the code/instructions to be executed. The outset column contains the accost of the instruction. The second cavalcade contains the instruction expressed in Hex form (will be discussed in the class). The tertiary column contains the actual machine linguistic communication instruction (processor assembly) to be executed while the last column contains the original pedagogy in MIPS assembly that you wrote.
- This window displays the contents of the Information Segment. Data segment reserves the infinite for declarations (int, char, etc.) that y'all do while writing the program. You tin see the variables, arrays that you declared, here. It also shows the contents of the stack.
- This window shows the messages generated by PCSpim. It too informs if a plan was successfully loaded or if some fault was encountered.
Writing and Analyzing a Simple Program in pcspim
I take given a complete overview of pcspim software and also provided examples to write your first MIPS assembly language programme in MIPS. Bank check this video to know how to write your offset assembly program using pcspim.
Let usa run a simple program and see the working of the processor and the simulator. Open Notepad and type in the following code: (Note that PCSpim is case sensitive, also run into the spellings of globl, all plan code is in lower example except labels. The sign # is used for comments. Do non blazon comments.).text signifies the outset of the text section of the program.Manually piece of work out and write down the decimal values that various registers should comprise after the execution of this program. I have written results of each didactics, you lot should verify results of each education to get amend agreement.
writing first code in pcspim
.text .globl main # C equivalent principal: addi $s0, $zero, 10 # X = 10; $s0 = X, Value in $s0: 10 addi $s1, $zero, twenty # Y = 20; $s1 = Y, Value in $s1: 20 addi $s2, $goose egg, -30 # Z = -30;$s2 = Z, Value in $s2: -30 add $t0, $s0, $s1 # A = X+Y;$t0 = A, Value in $t0: 30 sub $t1, $s1, $s2 # B = Y-Z;$t1 = B, Value in $t1: 50 add together $t2, $t0, $t1 # C = A+B;$t2 = C, Value in $t2: 80 or $t3, $s0, $s2 # D = X|Z;$t3 = D, Value in $t3: -22 slt $t4, $s0, $s1 # Set on less then (slt) # $t4 is prepare to 1 if $s0 < $s1, 0 otherwise. # if(X<Y){E=1};$t4 = E Value in $t4: ane slti $t5, $s2, -400 # if(Z<-400){F=1};$t5 = F Value in $t5: 0
Relieve this code as "FirstProgram.s" in your Z drive or on the D drive of the Computer that you lot are using. Note that you need to save your programme using inverted commas like "FirstProgram.southward" in order to save your plan with the required extension.
How to run pcspim simulator
Load PCSpim by clicking its icon present on the desktop or by opening it from the Kickoff carte du jour. If information technology asks for a path to some file, provide the path file from the binder where you have installed or copied pcspim simulator. When PCSpim opens, pull downwardly the File menu and select Open. Open the file FirstProgram.s from the location where you lot saved it.
Running your plan One Instruction at a time (Single-stepping) in pcspim
To run the programme in single steps in pcspim press F10 for each instruction.Getting to Chief: Keep pressing F10 till you achieve the instruction at main's accost 0x00400024 (shown on left side in test window). This is where you program'due south principal starts and here you will be able to run across your plan in widow as mentioned above. Verify that the instructions from hither on wards represent to the instructions of your programme above.
If your programme is giving some strange error, make sure you have the following three lines of your code in the right social club (shown here). Remember this for all upcoming labs.
.text
.globl master
master:
Viewing Registers in pcspim equally they modify with each Pedagogy
Unmarried pace your plan using F10, stop and fill the following table after execution of each instruction by observing the register window. Y'all can as well use window's calculator as needed, just be informed that Windows built-in calculator is 64-bit and PCSPIM is 32-bit. Place a Ö in OK cavalcade if you lot concord with the reply (i.e., after comparison with the results that you worked out manually before) .. You shall exist required to provide all the answers in HEX form. However, you should view registers in decimal class to ostend your answers. I have already filled the table. But I suggest you to compare your results with this tabular array for better agreement.
Step 1: What is the value of $s0 later executing the first statement?
Decimal: 10, Hex: 0000000a, Ok: Ö
Step 2: What is the value of $s1 after executing the second statement?
Decimal: 20, Hex: 00000014, Ok: Ö
Step 3: What is the value of $s2 later executing the 3rd statement?
Decimal: −30, Hex: ffffffe2, Ok: Ö
Pace iv: What is the value of $t0 after executing the fourth statement?
Decimal: 30, Hex: 0000001e, Ok: Ö
Footstep five: What is the value of $t1 afterward executing the fifth statement?
Decimal: 50, Hex: 00000032, Ok: Ö
Step 6: What is the value of $t2 after executing the sixth argument?
Decimal: 80, Hex: 00000050, Ok: Ö
Step 7: What is the value of $t3 afterwards executing the seventh statement?
Decimal: −22, Hex: ffffffea, Ok: Ö
Stride viii: What is the value of $t4 after executing the eighth statement?
Decimal: 1, Hex: 00000001, Ok: Ö
Footstep 9: What is the value of $t5 afterward executing the 9th statement?
Decimal: 0, Hex: 00000000, Ok: Ö
For $t3, do the calculations in 32-fleck binary (by directly converting hex values of $s0 and $s1 given to a higher place) on the back of this page to verify your answer.
More than Logical Operations in pcspim
MIPS Shift Operations
srl and sll shift the number by a specified number of bits towards the right and left respectively. Recall that shifting a number in binary is equivalent to multiplying or dividing the number with powers of 2, e.k.
sll $t1, $t1, 3 multiplies the number in the register $t1 past 8.
srl $t1, $t1, iv divides the number in the register $t1 by 16.
More Bitwise Operations
and, or, andi, ori are bitwise operations available in MIPS.
Masking can be used to extract bits from a given number, e.g.
andi $t1, $t0, 64 extracts the 7th bit from $t0 and saves it in $t1. All other $.25 become zero.
andi $t1, $t0, fifteen extracts the last (least significant) iv bits from $t0 and saves them in $t1.
Instance number two in pcspim
Write a program to load the value 333 in $t0 register. Shift the value in $t0, left by 5, then shift it right by vii and and then shift it left past ii. Run the programme
What is the Hex value of 333 loaded in $t0: 0000014d
What is the Hex value of $t0 after it is shifted left by 5? 000029a0
What is the Hex value of $t0 afterward it is shifted correct by 7? 00000053
What is the Hex value of $t0 later on information technology is shifted left past 2? 0000014c
Is the final consequence unlike from 333? Why? Yes the answer is different from 333. It is 332. The reason for this divergence is that the number was left shifted by 5 first but then it was right shifted by 7 resulting in the loss of the last 2 bits which were 01 in binary and equivalent to ane in decimal and hex. Finally when the number was left shifted past 2, two 0s were inserted in place of 01.
Code of Do-2:
.text .globl main main: addi $t0, $null, 333 sll $t0, $t0, five srl $t0, $t0, seven sll $t0, $t0, two
Exercise 3:
Write a program to load 796 in register $s0. Mask $s0 using and performance to obtain least significant five bits of $s0 and store them in $s1. Notice the sum of 8×$s1 and $s1/4 using shift operations only. Apply $t0 to hold the result of eight×$s1, use $t1 to hold the event of $s1/four and use $t2 to hold the final sum. Run the program .
What is the Hex value of 796 loaded in $s0: 0000031c
What is the Hex value in $s1 after the masking operation? 0000001c
What is the Hex value of $t0 afterward the performance 8*$s1? 000000e0
What is the Hex value of $t1 after the operation $s1/4? 00000007
What is the Hex value of the final sum in $t2? 000000e7
Code for Exercise-three:
.text .globl main main: addi $s0, $cypher, 796 andi $s1, $s0, 31 sll $t0, $s1, 3 srl $t1, $s1, 2 add $t2, $t0, $t1
Do 4:
Think that immediate field in addi can hold 16 bits. We now learn how to load a 32-bit value in a register. Let us try that. Say, we would like to load 0x12345678 in a register.
The method is:
- Load upper (most pregnant) 16 $.25 in a register.
- Shift it left past 16 places.
- Add lower (to the lowest degree meaning) 16 bits to that annals.
Using the abovementioned method, load the value 0x12345678 in $t0. Y'all can load hex values using 0x notation, e.one thousand., addi $t0, $zero, 0x1234. Run the program .
Code for Exercise-4: .text .globl chief main: addi $t0, $zero, 0x1234 sll $t0, $t0, sixteen addi $t0, $t0, 0x5678
Pseudo Instructions in MIPS
Some instructions are more readable in assembly language but non directly converted into processor machine language. They are first converted to the processor'due south actual associates linguistic communication and then to its equivalent automobile language class. These are called Pseudo Instructions. Try the post-obit program:
.text .globl main master: li $t0, -100 # load -100 in $t0 li $t1, 0x1234abcd # load a 32-bit number li $t2, -1223455 # aforementioned
Load this program and come across how these instructions are converted into MIPS processor associates past observing the third cavalcade of the text segment.
How To Read Register $t0 In Simulator,
Source: https://microcontrollerslab.com/pcspim-tutorial-mips-simulator/
Posted by: cephaswhersely1982.blogspot.com
0 Response to "How To Read Register $t0 In Simulator"
Post a Comment