MIPS Assembly Language Programming

Slides:



Advertisements
Similar presentations
Introduction to HT-IDE3000 Micro-C development System Department.
Advertisements

Lecture 9: MIPS Instruction Set
MIPS Assembly Language CPSC 321 Computer Architecture Andreas Klappenecker.
5Z032 Processor Design SPIM, a MIPS simulator Henk Corporaal
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
Syscall in MIPS Xinhui Hu Yuan Wang.
MIPS Function Continued
Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te
Ch. 8 Functions.
IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
Assembly Language Working with the CPU.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
ECE 0142 Recitation #5.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
SPIM : A MIPS Simulator Archi & Net Lab 이용석
Lab #1 PCSpim SPIM is a software simulator that loads and executes assembly language programs for the MIPS RISC computers. Download and install PCSpim.
1 MIPS Assembly Language Programming CDA 3101 Discussion Section 03.
First Programming Assignment For MIPS R3000 Processor Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki.
Active-HDL Interfaces Debugging C Code Course 10.
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.
 Requesting Additional Orders (pgs. 2-9) *Call CEC for assistance  Adding New Students/Registering Students (pgs ) *Call CEC for assistance  Editing.
Lecture # 1 SPIM & MIPS Programming. SPIM SPIM is a MIPS32 simulator that reads and executes assembly language program written for SPIM. Platform -Unix,
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Assembly Language CS 333 Sam Houston State University Dr. Tim McGuire.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Introduction Purpose  This training module provides an overview of debugging features.
Bit-DSP-MicrocontrollerTMS320F2812 Texas Instruments Incorporated European Customer Training Center University of Applied Sciences Zwickau (FH)
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.
9/29: Lecture Topics Conditional branch instructions
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:
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Assembly Language CS 333 Sam Houston State University Dr. Tim McGuire.
3-Apr-2006cse spim © 2006 DW Johnson and University of Washington1 SPIM simulator CSE 410, Spring 2006 Computer Systems
CS 312 Computer Architecture & Organization
MIPS Assembly Language Programming
Switch Statement Pre-requisites: 1D array addressing Updated 7/11/2013.
MIPS simulators There are 3 widely used MIPS simulators PC-SPIM, MARS, QTSPIM. PC-SPIM (the one we should use) the oldest one with poor graphics Very simple.
MIPS Instruction Set Advantages
Introduction to Lab #1 José Nelson Amaral.
MIPS I/O and Interrupt.
CS 286 Computer Organization and Architecture
MIPS Procedures.
MIPS Coding Continued.
ACOE301: Computer Architecture II Labs
MIPS instructions.
MIPS I/O and Interrupt.
MIPS coding.
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
MIPS Procedures.
Assembler Directives Example program: .data # DATA segment city: .asciiz “Seattle” .align 2 num: .word 2210, 2341, 26, 0x022ec,
MIPS Functions.
MIPS coding.
MIPS Functions.
MIPS coding.
MIPS Procedures.
MIPS Coding.
MIPS function continued
MIPS Functions.
MIPS Coding.
CS 286 Computer Organization and Architecture
Review.
MIPS Coding Continued.
MIPS coding.
Program Assembly.
9/27: Lecture Topics Memory Data transfer instructions
CS 286 Computer Architecture & Organization
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
MIPS Functions.
Introduction to SPIM Simulator
Presentation transcript:

MIPS Assembly Language Programming CDA 3101 Discussion Session 04 1 1 1

Outline MIPS simulator – PCSpim Installation Try it with small programs ! 2 2 2

Installation PCSpim From the textbook CD From the internet http://www.cs.wisc.edu/~larus/spim.html 3 3 3

Writing A Basic Program Let’s start by writing a program that sums all the numbers between 1 and 5. void main() { printf("Test Program #1\n"); int sum = 0; int i = 5; do sum = sum + i; i = i - 1; } while( i > 0 ); printf("Sum from 1 to 5 = %d",sum); printf("\nEnd of Program\n"); } 4 4 4

Writing A Basic Program Summing numbers between 1 and 5. Something… like this: void main() { printf("Test Program #1\n"); int sum = 0; int i = 5; do sum = sum + i; i = i - 1; } while( i > 0 ); printf("Sum from 1 to 5 = %d",sum); printf("\nEnd of Program\n"); } 5 5 5

Writing A Basic Program How can we translate this into MIPS? void main() { printf("Test Program #1\n"); int sum = 0; int i = 5; do sum = sum + i; i = i - 1; } while( i > 0 ); printf("Sum from 1 to 5 = %d",sum); printf("\nEnd of Program\n"); } 6 6 6

Writing A Basic Program How can we translate this into MIPS? void main() { printf("Test Program #1\n"); int sum = 0; int i = 5; do sum = sum + i; i = i - 1; } while( i > 0 ); printf("Sum from 1 to 5 = %d",sum); printf("\nEnd of Program\n"); } # Our first test program for MIPS Simulator (pcSpim)‏ .data .disp1: .asciiz “Test Program #1\n” .disp2: .asciiz “Sum from 1 to 5 = “ .disp3: .asciiz “\nEnd of program\n .text #Tells us this is the code section. .globl main #Tells compiler that this is a #public location (function)‏ main: … #The start of the function 7 7 7

Writing A Basic Program How can we translate this into MIPS? void main() { printf("Test Program #1\n"); int sum = 0; int i = 5; do sum = sum + i; i = i - 1; } while( i > 0 ); printf("Sum from 1 to 5 = %d",sum); printf("\nEnd of Program\n"); } … main: li $t0, 0 #int sum = 0; li $v0, 5 #int i = 5; So we will be using $t0 as sum, and $v0 as i 8 8 8

Writing A Basic Program How can we translate this into MIPS? … main: li $t0, 0 #int sum = 0; li $v0, 5 #int i = 5; #do loop: … bgtz $v0, loop #while(i > 0); To make a do … while loop, we will need a label to jump to. It’s really the old goto function. void main() { printf("Test Program #1\n"); int sum = 0; int i = 5; do sum = sum + i; i = i - 1; } while( i > 0 ); printf("Sum from 1 to 5 = %d",sum); printf("\nEnd of Program\n"); } 9 9 9

Writing A Basic Program How can we translate this into MIPS? void main() { printf("Test Program #1\n"); int sum = 0; int i = 5; do sum = sum + i; i = i - 1; } while( i > 0 ); printf("Sum from 1 to 5 = %d",sum); printf("\nEnd of Program\n"); } … main: li $t0, 0 #int sum = 0; li $v0, 5 #int i = 5; #do loop: add $t0, $t0, $v0 #sum = sum + i; addi $v0, $v0, -1 #i = i – 1; bgtz $v0, loop #while(i > 0); Now we can perform the real work. 10 10 10

How can we translate this into MIPS? main: li $v0,4 la $a0,disp1 syscall li $t0, 0 #int sum = 0; li $v0, 5 #int i = 5; loop: add $t0, $t0, $v0 #sum = sum + i; addi $v0, $v0, -1 #i = i – 1; bgtz $v0, loop #while(i > 0); la $a0,disp2 li $v0,1 move $a0,$t0 la $a0,disp3 li $v0,10 void main() { printf("Test Program #1\n"); int sum = 0; int i = 5; do sum = sum + i; i = i - 1; } while( i > 0 ); printf("Sum from 1 to 5 = %d",sum); printf("\nEnd of Program\n"); } 11 11 11

PC Spim 12 12 12

PC Spim Note the top window – it contains the state of all registers. 13 13 13

PC Spim The button on the top right runs the program to its end, after you click “OK” on the dialog box. Note that you won’t see the register changes until the program ends. 14 14 14

PC Spim Click this menu item to reinitialize PC Spim – it’s like rebooting your computer. It’s often necessary to click Reload to run your program again. 15 15 15

PC Spim Click this menu item to change settings for the emulator. 16

PC Spim Click this menu item to change settings for the emulator. Sometimes it’s helpful to uncheck “General registers in hexadecimal” so that you can read values as regular numbers. 17 17 17

PC Spim Click the button that looks like a hand to set breakpoints. The program will stop running at positions you indicate, and wait for your authorization to continue upon reaching said point. You will also see the register values updated. 18 18 18