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
Branches Two branch instructions:
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,
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
Feb 18, 2009 Lecture 4-2 instruction set architecture (Part II of [Parhami]) MIPS encoding of instructions Spim simulator more examples of MIPS programming.
Instruction Representation II (1) Fall 2007 Lecture 10: Instruction Representation II.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Instruction Representation II (1) Fall 2005 Lecture 10: Instruction Representation II.
MIPS Instruction Set Advantages
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.
Computer Organization Instructions Language of The Computer (MIPS) 2.
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.
Addressing Modes. Register Addressing Immediate Addressing Base Addressing Indexed Addressing PC-Relative Addressing.
The Assembly Process Computer Organization and Assembly Language: Module 10.
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.
Lecture 17: 10/31/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
MIPS Coding. Exercise – the bubble sort 7/9/2016week04-3.ppt2.
MIPS Assembly Language Programming
Computer Architecture & Operations I
MIPS Assembly Language Programming
MIPS Instruction Set Advantages
MIPS Procedures.
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
MIPS instructions.
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Instructions for Making Decisions
The University of Adelaide, School of Computer Science
MIPS coding.
MIPS Procedures.
CSCI206 - Computer Organization & Programming
Solutions Chapter 2.
MIPS Instructions.
MIPS Instruction Encoding
ECE232: Hardware Organization and Design
MIPS coding.
MIPS Functions.
MIPS Instruction Encoding
Instruction encoding The ISA defines Format = Encoding
MIPS Functions.
MIPS Procedures.
Review.
MIPS Coding.
The University of Adelaide, School of Computer Science
MIPS function continued
MIPS Functions.
3.
MIPS Coding.
Review.
MIPS Coding Continued.
MIPS coding.
MIPS assembly.
9/27: Lecture Topics Memory Data transfer instructions
MIPS Functions.
MIPS function continued
MIPS Functions.
MIPS Processor.
MIPS instructions.
Conditional Branching (beq)
MIPS Assembly.
Presentation transcript:

MIPS coding

Questions If $t0 is holding 30, in the binary of instruction add $t2, $t0, $t1, the rs field should be 30? No, should be the index of $t0

Questions Is it true that because the j instruction has to specify the entire address, it has a smaller opcode field? no

Questions Is it correct to write an instruction addi $t0, $t0, 100000? No, the number is too large

Questions Is it true that instruction beq $t0, $t1, L1 does not store the entire address associated with L1 but the offset with respect to its own address? Yes

Questions Is it true that the PC (program counter) always stores the address of the current instruction, except when encountering beq, bne, and j? no

Questions It would be nice if we have an instruction like beq $t0, 5, L1 which compares $t0 with the constant 5 and jumps if they are the same. Does MIPS have this instruction? Why? Does not have it. Cannot fit in two immediate numbers.

Loop example 2 How to translate the following to MIPS assembly? 1/2/2019 Loop example 2 How to translate the following to MIPS assembly? We first translate into a C program using if and goto 1/2/2019 week04-3.ppt CDA3100

Compiling a while loop in C 1/2/2019 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/2/2019 week04-3.ppt CDA3100

Compiling a while loop in C 1/2/2019 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/2/2019 week04-3.ppt CDA3100

1/2/2019 While Loop How many instructions will be executed for the following array save? Assume that k = 10 and i = 0 initially 1/2/2019 week04-3.ppt CDA3100

Optimized How many instructions now? Assume k = 10 and i = 0 initially 1/2/2019 Optimized How many instructions now? Assume k = 10 and i = 0 initially 1/2/2019 week04-3.ppt CDA3100

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

Loop Example 3 Finding the largest element in an array The idea is to use a register, say, $t9, to keep the largest number we have seen so far, go through the array, if encounter a number larger than the one in $t9, replace $t9 with this number

Loop ex 3 data A: .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 .text .globl main main: la $s0, A li $s1, 10 # number of elements in the array li $t0, 0 # $t0 as i li $t9, 0 # $t9 as the max number LOOP: sll $t1, $t0, 2 # these 3 instructions read A[i] into $t1 add $t1, $t1, $s0 lw $t1, 0($t1) slt $t2, $t9, $t1 # compare $t1 with $t9, $t2 should be 1 if $t9 is smaller beq $t2, $0, LOOP_NEXT # if $t2 is 0, means $t9 is larger than $t1, nothing needs to be done ori $t9, $t1, 0 # if came here, $t2 is 1, replace $t9 with $t1 LOOP_NEXT: addi $t0, $t0, 1 # increment i by 1 bne $t0, $s1, LOOP # if i!=$s1, continue to the next element in the array done: li $v0,10 # these two lines tell the simulator to stop syscall