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.

Slides:



Advertisements
Similar presentations
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Advertisements

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.
Branches Two branch instructions:
The University of Adelaide, School of Computer Science
Lecture 20: 11/12/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Lecture 9: MIPS Instruction Set
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
Assembly Language Working with the CPU.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
ECE 0142 Recitation #5.
MIPS Coding. Exercise – the bubble sort 5/8/2015week04-3.ppt2.
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.
Lab #1 PCSpim SPIM is a software simulator that loads and executes assembly language programs for the MIPS RISC computers. Download and install PCSpim.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
Lecture 5: Procedures. Function call book-keeping in C main() { int i,j,k,m;... i = mult(j,k);... m = mult(i,i);... } /* really dumb mult function */
MIPS Instruction Set Advantages
MIPS I/O and Interrupt. SPIM I/O and MIPS Interrupts The materials of this lecture can be found in A7-A8 (3 rd Edition) and B7-B8 (4 th Edition).
MIPS coding. SPIM Some links can be found such as:
First Programming Assignment For MIPS R3000 Processor Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki.
MIPS I/O and Interrupt. .data val1:.float 0.6 val2:.float 0.8 msg_done:.asciiz "done\n".text.globl main main: li.s $f0, mfc1 $a0, $f0 jal calsqrt.
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.
17 - Jumps & Branches. The PC PC marks next location in Fetch, Decode, Execute cycle.
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.
MIPS I/O and Interrupt.
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:
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Assembly Language CS 333 Sam Houston State University Dr. Tim McGuire.
March 21, 2016© Craig ZIlles (adapted from slides by Howard Huang) 1 What does this code do? label:sub$a0, $a0, 1 bne$a0, $zero, label Arf.
Control Structures Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Conditional Control Structure if ( i < j ) goto A; else.
MIPS Assembly Language Programming
Computer Architecture & Operations I
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.
Decision Making.
MIPS I/O and Interrupt.
The University of Adelaide, School of Computer Science
MIPS coding.
Pick up the handout on your way in!!
MIPS I/O and Interrupt.
MIPS Procedures.
Logical and Decision Operations
Ronny Krashinsky and Mike Sung
MIPS coding.
MIPS coding.
MIPS Procedures.
MIPS Coding.
MIPS Functions.
COMS 361 Computer Organization
MIPS I/O and Interrupt.
QtSpim Demo & Tutorial SPRING 2011.
CS 286 Computer Organization and Architecture
Review.
MIPS Coding Continued.
MIPS coding.
Program Assembly.
MIPS Functions.
Introduction to SPIM Simulator
Conditional Branching (beq)
Presentation transcript:

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 1 if $t1 < 100 ; else clear $t3 to be 0.

Complete MIPS code The text segment in the source code usually starts with.text.globl main main: where `` main ’’ is the label associated with the address of the first instruction of the code. And the code usually ends with li $v0,10 # telling the simulator to stop syscall Comment with `#’

SPIM Run codes with SPIM. SPIM is a simulator. – Use any editor to write the source file, save it as an.asm file. – Run SPIM, load the source file. – F10 to step through the code. Monitor how the registers change. – F5 to run the code – Can set breakpoints for debugging SPIM can be downloaded at Lots of good references online, like

Working with the simulator Can check – How the program runs – How the instructions are encoded, addressed – How to monitor the change of the registers – Later, how the memory is used to store data

Some Comments Being able to write if-else, we can have all other fancy things like for loop, while loop…. That is why we do not have an instruction for the for loop or while loop, but we build it from the if-else.

Loop A loop is needed when we need to do something repeatedly It must have – A loop body (what you should do in each iteration) – A checking point to see if we still need to go on – A mechanism to bring us from the end of the loop back to the beginning of the loop (therefore it is called a loop)

Loop example 1 How to count the number of 1s in a register?

Counting the number of 1s.text.globl main main: # counting the number of 1s in register $s0, no need to save it li $s0, 97 li $t0, 0 LOOP:andi $t1, $s0, 1 add $t0, $t0, $t1 srl $s0, $s0, 1 bne $s0, $zero, LOOP done:li $v0, 10 syscall