Opening SPIM
Start PCSpim on your workstation. Detailed instructions on where to get it and how to run it can be found here. Back to Top
RegistersZeroed out, except for the stack pointer, which points to an empty stack (see the third window)Code.Contains the kernel code and code to execute the code that is loaded.Data, Stack and Kernel DataData and stack are zeroed out. Kernel Data contains data needed by the Kernel Code.BlurbThe only relevant detail is "Loaded ... exceptions.s"Memory Organization
Back to Top
Back to Top
#Comments begin with a '#' and continue till #the end of the line # #Lab 1: Register Swapping & SPIM orientation # # # Assembler Directive to load the # data segment, text segment .data .word 7 .word 3 .text .globl main main: lui $s0, 0x1001 #load upper part of register s0(16) with 0x1001 s0 = 0x10010000 lw $s1, 0($s0) #load s1 with the contents of memory address 0x10010000 = 7, #since we loaded the data there. lw $s2, 4($s0) #load s2 with the contents of memory address 0x10010004 = 3, #since we loaded the data there. sw $s2, 0($s0) #store contents of s2 into memory address 0x10010000 sw $s1, 4($s0) #store contents of s1 into memory address 0x10010004Back to Top
Written together, it will look like 001111 00000 10000 0001 0000 0000 0001 To express this binary string in hexadecimal, we need to group them into groups of four each, thus: This binary string, expressed in hexadecimal, is 0x3c101001, which is the machine code for the instruction An example of the machine code of a load instruction is: lw $s0,0($s1)
Note: note the way that the opcode is constructed. 0x23 does not have the usual representation of 0010 0011 because 8 bits are not available. It is represented as 10 0011 in 6 bits. The machine code, therefore, is 1000 1110 0001 0001 0000 0000 0000 0000 or, 0x8e11000. Back to Top
Load the file Lab1.spim into pcspim [File->Open->(whatever path you have saved into)\Lab1.spim] Note the immediate changes:
The stack is still empty as we have not started executing the code. Back to Top
Once the program has been loaded, we will step through the execution of the program.
Select [Simulator->Go]. Step through the code using < F10 >. After the first step, observe Register 16 (s0) in the topmost window. It has become 0x1001000.
Press < F10 >. Register 17 (s1) now contains 7, the contents of 0x1001000. The contents in the memory have been swapped. Back to Top
The following questions should be answered and submitted to the TA, Yuly, via email: ysuvorov@iastate.edu. Make sure your subject line is "Comp Sci 321 Lab1"
In this lab, we have seen:
|