QtSpim Demo & Tutorial ECE232@UMASS SPRING 2011.

Slides:



Advertisements
Similar presentations
CENG 311 Decisions in C/Assembly Language
Advertisements

Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
MIPS assembly. Review  Lat lecture, we learnt  addi,  and, andi, or, ori, xor, xori, nor,  beq, j, bne  An array is stored sequentially in the memory.
CS/COE0447 Computer Organization & Assembly Language
Branches Two branch instructions:
Lecture 9: MIPS Instruction Set
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
Introduction to Assembly language
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
MIPS Assembly Language CPSC 321 Computer Architecture Andreas Klappenecker.
5Z032 Processor Design SPIM, a MIPS simulator Henk Corporaal
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
SPRING 2015 QtSpim Demo & Tutorial. 2 By DGP Outline How to write your own MIPS assembly language program How to use QtSpim simulator.
SPIM and MIPS programming
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
Syscall in MIPS Xinhui Hu Yuan Wang.
MIPS Function Continued
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
MIPS Assembly Language Programming
Assembly Language Working with the CPU.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
ECE 0142 Recitation #5.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
 Procedures (subroutines) allow the programmer to structure programs making them : › easier to understand and debug and › allowing code to be reused.
Chap.2: Instructions: Language of the computer Jen-Chang Liu, Spring 2006 Adapted from
Computer Architecture Lecture 2 Instruction Set Principles.
Computer Architecture Lecture 3 C and Assembly. Intro to Assembly Language MIPS and Intel Variables and Constants int count = 10, I, j, k; count.word.
Feb 18, 2009 Lecture 4-2 instruction set architecture (Part II of [Parhami]) MIPS encoding of instructions Spim simulator more examples of MIPS programming.
CS 61C L14Introduction to MIPS: Instruction Representation II (1) Garcia, Spring 2004 © UCB Roy Wang inst.eecs.berkeley.edu/~cs61c-tf inst.eecs.berkeley.edu/~cs61c.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
MIPS Instruction Set Advantages
19/02/2009CA&O Lecture 05 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: PCSpim Tutorial Engr. Umbreen Sabir Computer Engineering.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Lecture # 1 SPIM & MIPS Programming. SPIM SPIM is a MIPS32 simulator that reads and executes assembly language program written for SPIM. Platform -Unix,
Ch2b- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Thanks for all the Memory! When 32 registers just won’t do. Many times (almost.
Lecture 10: MIPS Simulator Today’s topic –SPIM Simulator Readings –Appendix B 1.
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Intro to SPIM Justin Fiore Nathan Parish. Installing SPIM on Windows Download pcspim.zip from the SPIM website:
Addressing Modes. Register Addressing Immediate Addressing Base Addressing Indexed Addressing PC-Relative Addressing.
The Assembly Process Computer Organization and Assembly Language: Module 10.
Control Structures Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Conditional Control Structure if ( i < j ) goto A; else.
MIPS Instruction Set Advantages
Introduction to Lab #1 José Nelson Amaral.
CS2100 Computer Organisation
MIPS Coding Continued.
ACOE301: Computer Architecture II Labs
Computer Architecture & Operations I
MIPS instructions.
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Conditional Control Structure
MIPS coding.
Assembler Directives Example program: .data # DATA segment city: .asciiz “Seattle” .align 2 num: .word 2210, 2341, 26, 0x022ec,
MIPS coding.
MIPS coding.
Computer Organization and Design Assembly & Compilation
MIPS Coding.
MIPS Functions.
MIPS Coding.
COMS 361 Computer Organization
Review.
MIPS Coding Continued.
MIPS coding.
MIPS Assembly Language Programming Computer Architecture
CS334: MIPS language _Mars simulator Lab 2_1
Program Assembly.
Conditional Control Structure
MIPS Functions.
Presentation transcript:

QtSpim Demo & Tutorial ECE232@UMASS SPRING 2011

Outline How to write your own MIPS assembly language program How to use QtSpim simulator

First steps Define clearly the problem you’re going to tackle Example: 1 Write your program: #include <cstdio> int main(int argc, char** argv) { int vectorA[5] = {1,2,3,4,5}; int vectorB[5] = {2,4,6,8,10}; int result = 0; int i=0; while (i<5) { result += vectorA[i]*vectorB[i]; i+=1; } printf(“result %d\n”,result); Test it: g++ main.cpp ./a.out Result 110 Example: Calculate the dot product of two vectors: Scalar = [A]•[B] = ∑ai*bi with i=1…5 Then, write a C code for it:

Simplify your C code - 1 To make the transformation to Assembly simpler #include <cstdio> int main(int argc, char** argv) { int vectorA[5] = {1,2,3,4,5}; int vectorB[5] = {2,4,6,8,10}; int result = 0; int i=0; while (i<5) { result += vectorA[i]*vectorB[i]; i+=1; } printf(“result %d\n”,result); 1 2 int main(int argc, char** argv) { int vectorA[5] = {1,2,3,4,5}; int vectorB[5] = {2,4,6,8,10}; int result = 0; int i=0; int valueA = 0; int valueB = 0; while (i<5) { valueA = vectorA[i]; valueB = vectorB[i]; result += valueA*valueB; i+=1; } reading values

separate branching from Simplify your C code - 2 3 2 int main(int argc, char** argv) { int vectorA[5] = {1,2,3,4,5}; int vectorB[5] = {2,4,6,8,10}; int result = 0; int i=0; int valueA = 0; int valueB = 0; bool condition = true; while (condition) { valueA = vectorA[i]; valueB = vectorB[i]; result += valueA*valueB; i+=1; condition = (i>=5) ? false : true; } int main(int argc, char** argv) { int vectorA[5] = {1,2,3,4,5}; int vectorB[5] = {2,4,6,8,10}; int result = 0; int i=0; int valueA = 0; int valueB = 0; while (i<5) { valueA = vectorA[i]; valueB = vectorB[i]; result += valueA*valueB; i+=1; } separate branching from condition evaluation

Simplify your C code - 3 3 4 break down operations int main(int argc, char** argv) { int vectorA[5] = {1,2,3,4,5}; int vectorB[5] = {2,4,6,8,10}; int result = 0; int intermidiateResult = 0; int i=0; int* addressA = vectorA; int* addressB = vectorB; int valueA = 0; int valueB = 0; bool condition = true; while (condition) { valueA = *(addressA); valueB = *(addressB); intermidiateResult = valueA*valueB; result = result + intermidiateResult; i+=1; addressA+=1; addressB+=1; condition = (i>=5) ? false : true; } 3 4 int main(int argc, char** argv) { int vectorA[5] = {1,2,3,4,5}; int vectorB[5] = {2,4,6,8,10}; int result = 0; int i=0; int valueA = 0; int valueB = 0; bool condition = true; while (condition) { valueA = vectorA[i]; valueB = vectorB[i]; result += valueA*valueB; i+=1; condition = (i>=5) ? false : true; } break down operations break down memory accesses

Simplify your C code - 4 4 1 Break your code into its basic OPs #include <cstdio> Int main(int argc, char** argv) { int vectorA[5] = {1,2,3,4,5}; int vectorB[5] = {2,4,6,8,10}; int result = 0; int i=0; while (i<5) { result += vectorA[i]*vectorB[i]; i+=1; } printf(“result %d\n”,result); int main(int argc, char** argv) { int vectorA[5] = {1,2,3,4,5}; int vectorB[5] = {2,4,6,8,10}; int result = 0; int intermediateResult = 0; int i=0; int* addressA = vectorA; int* addressB = vectorB; int valueA = 0; int valueB = 0; bool condition = true; while (condition) { valueA = *(addressA); valueB = *(addressB); intermediateResult = valueA*valueB; result += intermediateResult; i+=1; addressA+=1; addressB+=1; condition = (i>=5) ? false : true; } 1 4 Break your code into its basic OPs

Transform C code into MIPS Assembly Map your variables to MIPS regs int main(int argc, char** argv) { int vectorA[5] = {1,2,3,4,5}; $s0 int vectorB[5] = {2,4,6,8,10}; $s1 int result = 0; $s2 int intermidiateResult = 0; $t6 int i=0; $s3 int* addressA = vectorA; $t2 int* addressB = vectorB; $t3 int valueA = 0; $t4 int valueB = 0; $t5 bool condition = true; while (condition) { valueA = *(addressA); valueB = *(addressB); intermidiateResult = valueA*valueB; result += intermidiateResult; i+=1; addressA+=1; addressB+=1; condition = (i>=5) ? false : true; } Annotate your mappings $s0 stores the address of vectorA $s1 stores the address of vectorB $s2 stores the final result (initialized to $zero) $s3 counter i $t0 condition $t1 internal flag used to compare to 1 $t2 stores the address of vectorA[i] $t3 stores the address of vectorB[i] $t4 stores the value of vectorA[i] $t5 stores the value of vectorB[i] $t6 stores the intermidiate addition of t4 and t5

Code your Assembly using this template # ====================================== # Description: perform dot product of 2 vectors # Test: # A = [1,2,3,4,5] = [0x1,0x2,0x3,0x4,0x5] # B = [2,4,6,8,10] = [0x2,0x4,0x6,0x8,0xA] # Expected result # R = A.B = 2+8+18+32+50 = 110 = 0x6E # Your annotated registers # ========== Data Segment .data #your data will come here # ========== Code Segment .text .globl main main: # your code will come here EXIT: li $v0,10 syscall # End of file

Annotate your register assignments & data # ====================================== # Description: perform dot product of 2 vectors # Test: # A = [1,2,3,4,5] = [0x1,0x2,0x3,0x4,0x5] # B = [2,4,6,8,10] = [0x2,0x4,0x6,0x8,0xA] # Expected result # R = A.B = 2+8+18+32+50 = 110 = 0x6E # Your annotated registers # ========== Data Segment .data #your data will come here # ========== Code Segment .text .globl main main: # your code will come here EXIT: li $v0,10 syscall # End of file $s0 stores the address of vectorA $s1 stores the address of vectorB $s2 stores the final result (initialized to $zero) $s3 counter i $t0 condition $t1 internal flag used to compare to 1 $t2 stores the address of vectorA[i] $t3 stores the address of vectorB[i] $t4 stores the value of vectorA[i] $t5 stores the value of vectorB[i] $t6 stores the intermediate addition of t4 and t5 vectorA: .word 1,2,3,4,5 vectorB: .word 2,4,6,8,10

Transform C code into MIPS Assembly main: la $s0, vectorA # [pseudo] puts address of vectorA into $s0 la $s1, vectorB # [pseudp] puts address of vectorB into $s1 addi $s2, $zero, 0 # initialized the result to zero addi $s3, $zero, 0 # i=0 addi $t1, $zero, 1 # $t1=1 addi $t2, $s0, 0 # $t2 stores the address of a[0] addi $t3, $s1, 0 # $t3 stores the address of b[0] LOOP: slti $t0, $s3, 5 # $t0=1 if i < 5 bne $t0, $t1, EXIT # if i >= 5, exit from the loop lw $t4, 0($t2) # load a[i] to $t4 lw $t5, 0($t3) # load b[i] to $t5 mult $t5, $t4 # $LO<=b[i]*a[i] mflo $t6 # $t0<=$LO add $s2,$s2,$t6 addi $s3, $s3, 1 # i=i+1 addi $t2, $t2, 4 # increment address of a[] by 4 bytes, 1 ptr. addi $t3, $t3, 4 # increment address of b[] by 4 bytes, 1 ptr. j LOOP EXIT: int main(int argc, char** argv) { int vectorA[5] = {1,2,3,4,5}; int vectorB[5] = {2,4,6,8,10}; int result = 0; int intermidiateResult = 0; int i=0; int* addressA = vectorA; int* addressB = vectorB; int valueA = 0; int valueB = 0; bool condition = true; while (condition) { valueA = *(addressA); valueB = *(addressB); intermidiateResult = valueA*valueB; result += intermidiateResult; i+=1; addressA+=1; addressB+=1; condition = (i>=5) ? false : true; }

Quick remark on pointers In C/C++ int vectorA[5] = {1,2,3,4,5} int* addressA = vectorA; addressA+=1; In MIPS [32 bit architecture] vectorA: .word 1,2,3,4,5 la $s0, vectorA addi $t2, $s0, 0 addi $t2, $t2, 4 $t2 $t2+4 4 bytes 1 2 3 4 5 1 2 3 4 5

Now that you have MIPS code => SPIM # ====================================== # Description: perform dot product of 2 vectors # Test: # A = [1,2,3,4,5] = [0x1,0x2,0x3,0x4,0x5] # B = [2,4,6,8,10] = [0x2,0x4,0x6,0x8,0xA] # Expected result # R = A.B = 2+8+18+32+50 = 110 = 0x6E # $s0 stores the address of vectorA # $s1 stores the address of vectorB # $s2 stores the final result (initialized to $zero) # $s3 counter i # $t0 condition # $t1 internal flag used to compare to 1 # $t2 stores the address of vectorA[i] # $t3 stores the address of vectorB[i] # $t4 stores the value of vectorA[i] # $t5 stores the value of vectorB[i] # $t6 stores the intermediate addition of t4 and t5 # ========== Data Segment .data vectorA: .word 1,2,3,4,5 vectorB: .word 2,4,6,8,10 # ========== Code Segment .text .globl main main: la $s0, vectorA # [pseudo] puts the address of vectorA into $s0 la $s1, vectorB # [pseudp] puts the address of vectorB into $s1 addi $s2, $zero, 0 # initialized the result to zero addi $s3, $zero, 0 # i=0 addi $t1, $zero, 1 # $t1=1 addi $t2, $s0, 0 # $t2 stores the address of a[0] addi $t3, $s1, 0 # $t3 stores the address of b[0] LOOP: slti $t0, $s3, 5 # $t0=1 if i < 5 bne $t0, $t1, EXIT # if i >= 5, exit from the loop lw $t4, 0($t2) # load a[i] to $t4 lw $t5, 0($t3) # load b[i] to $t5 mult $t5, $t4 # $LO<=b[i]*a[i] mflo $t6 # $t0<=$LO add $s2,$s2,$t6 addi $s3, $s3, 1 # i=i+1 addi $t2, $t2, 4 # increment address of a[] by 4 bytes, 1 ptr. addi $t3, $t3, 4 # increment address of b[] by 4 bytes, 1 ptr. j LOOP EXIT: li $v0,10 syscall # End of file

QtSpim spim is a simulator that runs MIPS32 programs It’s been around for more than 20 years (improving over time). QtSpim is a new interface for spim built on the Qt UI framework which supports various platforms (Windows, Mac, Linux) It reads and executes assembly language programs. It contains a simple debugger

Outline How to write your own MIPS assembly language programs How to use QtSpim simulator

Start SPIM

Load Program

Execute Program

Program data

Set a break point Set a break point at the conditional instruction

Debug by stepping your code line by line