MIPS Functions.

Slides:



Advertisements
Similar presentations
Branches Two branch instructions:
Advertisements

The University of Adelaide, School of Computer Science
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.
MIPS Assembly Language CPSC 321 Computer Architecture Andreas Klappenecker.
5Z032 Processor Design SPIM, a MIPS simulator Henk Corporaal
SPIM and MIPS programming
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.
MIPS Assembly Language Programming
1 Computer Architecture MIPS Simulator and Assembly language.
The University of Adelaide, School of Computer Science
Assembly Language Working with the CPU.
.text fact: addiu $sp, $sp, -32 sw $ra, 20($sp) sw $fp, 16($sp) addiu $fp, $sp, 28 sw $a0, 0($fp) bgtz $a0, L2 li $v0, 1 b suffix L2: addi $a0, $a0,
ECE 0142 Recitation #5.
MIPS Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
CSCE 212 Quiz 2 – 2/2/11 1.What is the purpose of the jal instruction? 2.What are the two conditional branching (if, goto; not the slt instruction) instructions.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
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 coding. SPIM Some links can be found such as:
In Class Execise. .data A:.word 0,1,2,3,4,5,6,7,8,9.text.globl main main: la $a0,A li $a1,6 li $a2,5 jal onUpStream done: li $v0, 10# exit syscall onUpStream:
Character Data and 32-bit Constants (Lecture #20) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
Strings in MIPS. Chapter 2 — Instructions: Language of the Computer — 2 Character Data Byte-encoded character sets – ASCII: 128 characters 95 graphic,
Subroutines, parameters and the stack Bryan Duggan.
Lecture 10: MIPS Simulator Today’s topic –SPIM Simulator Readings –Appendix B 1.
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.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /22/2013 Lecture 12: Character Data Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
CS 312 Computer Architecture & Organization
System Calls & Arithmetic
Lecture 5: Procedure Calls
Computer Architecture & Operations I
MIPS Assembly Language Programming
Writing an Embedded Controller
Lecture 7: MARS, Computer Arithmetic
MIPS Procedures.
MIPS Coding Continued.
MIPS instructions.
Pseudo instructions.
CDA 3101 Spring 2016 Introduction to Computer Organization
MIPS coding.
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
SPIM Syscalls.
MIPS Procedures.
MPIS Instructions Functionalities of instructions Instruction format
MIPS Instructions.
MIPS coding.
MIPS Functions.
Pseudo instructions.
Lecture 7: Examples, MARS, Arithmetic
MIPS Functions.
MIPS coding.
Компьютерийн зохион байгуулалт, ассемблер CS201
MIPS Procedures.
Review.
MIPS Coding.
MIPS function continued
Компьютерийн зохион байгуулалт, ассемблер CS201
MIPS Functions.
Writing an Embedded Controller
MIPS Coding Continued.
MIPS coding.
MIPS Assembly Language Programming Computer Architecture
MIPS Functions.
CS 286 Computer Architecture & Organization
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
MIPS function continued
MIPS Functions.
Presentation transcript:

MIPS Functions

Character and String Operations 11/29/2018 Character and String Operations Characters are encoded as 0’s and 1’s using ASCII most commonly American Standard Code for Information Interchange Each character is represented using 8 bits (or a byte) MIPS provides instructions to move bytes Load byte (lb) loads a byte to the rightmost 8 bits of a register Store byte (sb) write the rightmost 8 bits of a register to memory 11/29/2018 week04-3.ppt CDA3100 week04-3.ppt

SPIM syscalls li $v0,1 # print an integer in $a0 li $a0,100 syscall li $v0,5 # read an integer into $v0 li $v0,4 # print an ASCIIZ string at $a0 la $a0,msg_hello li $v0,10 #exit

String Copy Procedure 11/29/2018 11/29/2018 week04-3.ppt CDA3100 week04-3.ppt

msg_hello: .asciiz "Hello\n“ msg_empty: .space 400 .text .globl main .data msg_hello: .asciiz "Hello\n“ msg_empty: .space 400 .text .globl main Main: li $v0,4 la $a0,msg_hello syscall li $v0,4 la $a0,msg_empty la $a0,msg_empty #dst la $a1,msg_hello #src jal strcpy li $v0,10 #exit strcpy: lb $t0, 0($a1) sb $t0, 0($a0) addi $a0, $a0, 1 addi $a1, $a1, 1 bne $t0, $0, strcpy jr $ra

Stack Key things to keep in mind: Stack is a software concept – last in first out, that’s it. In MIPS, you implement the stack by yourself by keeping $sp always pointing to the top element on the stack Stack can be used in functions to save register values, and is the standard approach to save register values. But You can also use stack for other purposes This is not the only way to save register values.

msg: .asciiz "hello world" endl: .asciiz "\n" .text .globl main .data msg: .asciiz "hello world" endl: .asciiz "\n" .text .globl main main: addi $sp,$sp,-1 sb $0,0($sp) la $t1, msg L0: lb $t0,0($t1) beq $t0,$0, L1 addi $sp,$sp,-1 sb $t0,0($sp) addi $t1,$t1,1 j L0 L1: la $t1,msg L2: lb $t0,0($sp) addi $sp,$sp,1 sb $t0,0($t1) beq $t0, $0, L3 addi $t1,$t1,1 j L2 L3: la $a0,msg li $v0,4 syscall la $a0,endl li $v0,10 #exit