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
4.
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.
Branches Two branch instructions:
The University of Adelaide, School of Computer Science
Lecture 9: MIPS Instruction Set
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
Assembly Code Example Selection Sort.
SPRING 2015 QtSpim Demo & Tutorial. 2 By DGP Outline How to write your own MIPS assembly language program How to use QtSpim simulator.
The University of Adelaide, School of Computer Science
SPIM and MIPS programming
Chapter 2 Instructions: Language of the Computer
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.
The University of Adelaide, School of Computer Science
Assembly Language Working with the CPU.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
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.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
MIPS Instruction Set Advantages
MIPS coding. SPIM Some links can be found such as:
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.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
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.
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.
Computer Organization Instructions Language of The Computer (MIPS) 2.
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 Coding. Exercise – the bubble sort 7/9/2016week04-3.ppt2.
Computer Architecture & Operations I
MIPS Assembly Language Programming
Computer Architecture & Operations I
MIPS Instruction Set Advantages
MIPS Procedures.
MIPS Coding Continued.
MIPS instructions.
Decision Making.
The University of Adelaide, School of Computer Science
MIPS coding.
MIPS Procedures.
Assembler Directives Example program: .data # DATA segment city: .asciiz “Seattle” .align 2 num: .word 2210, 2341, 26, 0x022ec,
MIPS coding.
MIPS Functions.
MIPS Functions.
MIPS coding.
MIPS Procedures.
MIPS Coding.
MIPS Functions.
MIPS Coding.
MIPS I/O and Interrupt.
QtSpim Demo & Tutorial SPRING 2011.
Review.
MIPS Coding Continued.
MIPS coding.
MIPS assembly.
Program Assembly.
Conditional Control Structure
MIPS Functions.
MIPS instructions.
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.

Using slt slt $t3, $t1, $t2 bne $t3, $zero, L21 ori $t0, $t1, 0 j L22 L21: ori $t0, $t2, 0 L22:

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.

1/4/2016week04-3.ppt8 Compiling a while loop in C How to translate the following to MIPS assembly? – We first translate into a C program using if and goto

1/4/2016week04-3.ppt9 Compiling a while loop in C Assume that i and k correspond to registers $s3 and $s5 and starting address of array save is in $s6

1/4/2016week04-3.ppt10 Compiling a while loop in C Assume that i and k correspond to registers $s3 and $s5 and starting address of array save is in $s6

1/4/2016week04-3.ppt11 While Loop How many instructions will be executed for the following array save? – Assume that k = 10 and i = 0 initially

1/4/2016week04-3.ppt12 Optimized How many instructions now? – Assume k = 10 and i = 0 initially

The loop code.data save:.word 10, 10, 10, 10, 10, 11, 12,.text.globl main main: li $s3, 0 li $s5, 10 la $s6, save Loop: sll $t1, $s3, 2 add $t1, $t1, $s6 lw $t0, 0($t1) bne $t0, $s5, Exit addi $s3, $s3, 1 j Loop Exit: done: li $v0, 10 # these two lines are to tell the simulator to stop syscall

Data segment and code segment The code has a data segment and a code (text) segment. The beginning of the data segment in the assembly source code is indicated as.data and followed by several declarations such as – A:.word 0,1,2,3,4,5,6,7,8,9 meaning an array of words whose starting address is associated with label `` A.’’ – Several notes: It will allocate continuous spaces in the memory for the data.word means everything is 4 bytes save: is a label associated with the address of the first byte allocated. Like the label for the instructions, label for an address is also an address.