MIPS Coding.

Slides:



Advertisements
Similar presentations
Goal: Write Programs in Assembly
Advertisements

Lecture 5: MIPS Instruction Set
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
Arrays First step is to reserve sufficient space for the array.
CDA 3100 Recitation Week 8. Question 1.data A:.word 21,3,2,9,100,22,6,15,33,90.text.globl main main: la $a0, A li $a1, 17 li $a2, 10 jal funct li $v0,
CDA 3100 Recitation Week 15. What does the function f1 do:.data A:.word 10,21,45,8,100,15,29,12,3,19 B:.word 2,5,33,5,20,1,53,52,5,5 C:.word 6,8,5,4,5,22,53,12,33,89.text.globl.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
1 Answers to Test 1, Question 1 The function determines if the number is divisible by 6. It performs this by dividing the number first by 3 and then by.
MIPS Assembly Language CPSC 321 Computer Architecture Andreas Klappenecker.
Chapter 2 — Instructions: Language of the Computer — 1 Branching Far Away If branch target is too far to encode with 16-bit offset, assembler rewrites.
The University of Adelaide, School of Computer Science
Chapter 2 Instructions: Language of the Computer
Lecture 8: MIPS Instruction Set
MIPS Coding. Exercise – the bubble sort 5/8/2015week04-3.ppt2.
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
CS 300 – Lecture 6 Intro to Computer Architecture / Assembly Language Instructions.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
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.
Chapter 2 Decision-Making Instructions (Instructions: Language of the Computer Part V)
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
9/29: Lecture Topics Conditional branch instructions
Computer Organization CS224 Fall 2012 Lessons 7 and 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.
EET 4250 Instruction Representation & Formats Acknowledgements: Some slides and lecture notes for this course adapted from Prof. Mary Jane Penn.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
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 Instruction Set Advantages
COMPUTER ARCHITECTURE & OPERATIONS I
MIPS Procedures.
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
ELEN 468 Advanced Logic Design
MIPS instructions.
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Pseudo instructions.
Computer Architecture & Operations I
The University of Adelaide, School of Computer Science
MIPS processor continued
MIPS coding.
SPIM Syscalls.
MIPS Procedures.
Lecture 4: MIPS Instruction Set
How to represent signed integers
Computer Architecture & Operations I
MIPS Instruction Encoding
ECE232: Hardware Organization and Design
MIPS coding.
MIPS Functions.
Pseudo instructions.
MIPS Instruction Encoding
Instruction encoding The ISA defines Format = Encoding
MIPS Functions.
MIPS coding.
MIPS Procedures.
Review.
MIPS Coding.
The University of Adelaide, School of Computer Science
MIPS Functions.
COMS 361 Computer Organization
Review.
MIPS Coding Continued.
MIPS coding.
Conditional Control Structure
MIPS Functions.
Conditional Branching (beq)
Presentation transcript:

MIPS Coding

Review Everything is stored in the computer as sequences of 0s and 1s Each assembly instruction is uniquely mapped to a unique sequence of 0s and 1s There are three types of instruction types in MIPS: R-Types: opcode, rs, rt, rd, shamt, funt I-Types: opcode, rs, rt, immediate J-Types: opcode, immediate

Review opcode (6 bits): defines the operation rs/rt/rd (5 bits): register names / address shamt (5 bits): amount to shift in sll/srl funct (6 bits): further defines R-Types immediate (16 bits for I-Type / 26 for J-Type): addresses and constants

Exercise – the bubble sort for (int i = 0; i < N-1; i++) { for (int j = 0; j < N-i-1; j++) if (A[j] < A[j+1]) swap(A[j], A[j+1]); } 2/23/2019 week04-3.ppt

Exercise – the bubble sort Need two loops – just encapsulate one in the other Need to read the elements – done before. Need to compare two numbers – done before Need to swap – not that hard

Setup the program .data A: .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 .text .globl main main: la $s7, A # Address of A li $s6, 9 # N-1 done: li $v0,10 syscall Setup the program

Getting the first loop done .data A: .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 .text .globl main main: la $s7, A # getting the address li $s6, 9 # N-1 li $s0, 0 # i = 0 LOOP1: addi $s0, $s0, 1 # i = i + 1 bne $s0, $s6, LOOP1 # if i != N-1, outer loop again done: li $v0,10 syscall Getting the first loop done

Getting both loop done .data A: .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 .text .globl main main: la $s7, A # getting the address li $s6, 9 # N-1 li $s0, 0 # i = 0 LOOP1: li $s1, 0 # j = 0 LOOP2: addi $s1, $s1, 1 # j = j + 1 sub $t7, $s6, $s0 # $t7 will get N-1-i bne $s1, $t7, LOOP2 # if j != N-1-i, inner loop again addi $s0, $s0, 1 # i = i + 1 bne $s0, $s6, LOOP1 # if i != N-1, outer loop again done: li $v0,10 syscall Getting both loop done

Adding the code to read the elements A[j] and A[j+1] .data A: .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 .text .globl main main: la $s7, A # getting the address li $s6, 9 # N-1 li $s0, 0 # i = 0 LOOP1: li $s1, 0 # j = 0 LOOP2: sll $t0, $s1, 2 # $t0 = j * 4 add $t0, $t0, $s7 # $t0 is the address of A[j] lw $t1, 0($t0) # $t1 = A[j] lw $t2, 4($t0) # $t2 = A[j+1] addi $s1, $s1, 1 # j = j + 1 sub $t7, $s6, $s0 # $t7 will get N-1-i bne $s1, $t7, LOOP2 # if j != N-1-i, inner loop again addi $s0, $s0, 1 # i = i + 1 bne $s0, $s6, LOOP1 # if i != N-1, outer loop again done: li $v0,10 syscall Adding the code to read the elements A[j] and A[j+1]

Adding the comparison and swapping .data A: .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 .text .globl main main: la $s7, A # getting the address li $s6, 9 # N-1 li $s0, 0 # i = 0 LOOP1: li $s1, 0 # j = 0 LOOP2: sll $t0, $s1, 2 # $t0 = j * 4 add $t0, $t0, $s7 # $t0 is the address of A[j] lw $t1, 0($t0) # $t1 = A[j] lw $t2, 4($t0) # $t2 = A[j+1] bgt $t1, $t2, L1 # if A[j] > A[j+1] goto L1, bypass the swapping sw $t1, 4($t0) # do the swap sw $t2, 0($t0) # do the swap L1: addi $s1, $s1, 1 # j = j + 1 sub $t7, $s6, $s0 # $t7 will get N-1-i bne $s1, $t7, LOOP2 # if j != N-1-i, inner loop again addi $s0, $s0, 1 # i = i + 1 bne $s0, $s6, LOOP1 # if i != N-1, outer loop again done: li $v0,10 syscall Adding the comparison and swapping

Pseudo instruction A pseudo instruction is not a real instruction supported by the hardware. It is created to make the coding easier. It is mapped to a unique sequence of real instructions by the assembler. blt $t0, $t1, L1 slt $at, $t0, $t1 bne $at, $0, L1 bgt $t0, $t1, L1 slt $at, $t1, $t0 ble $t0, $t1, L1 beq $at, $0, L1 bge $t0, $t1, L1 li/la $t0, 0x3BF20 lui $t0, 0x0003 ori $t0, $0, 0xBF20 not $t0, $s0 nor $t0, $s0, $0 move $t0, $t1 ori $t0, $t1, $0 http://www.utdallas.edu/~cantrell/ee2310/spim.inst.txt

In-class exercise -- Loop