MIPS, C, and You. Ropes struct ropeNode { char * string; // 0x0 offset struct ropeNode * next; // 0x4 offset } typedef struct ropeNode* rope; rope weave(char.

Slides:



Advertisements
Similar presentations
Incomplete Structs struct B; struct A { struct B * partner; // other declarations… }; struct B { struct A * partner; // other declarations… };
Advertisements

Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
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
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.
Exploring Security Vulnerabilities by Exploiting Buffer Overflow using the MIPS ISA Andrew T. Phillips Jack S. E. Tan Department of Computer Science University.
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
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.
Solution 2nd Exam.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Procedure Calls Prof. Sirer CS 316 Cornell University.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
Assembly Code Example Selection Sort.
The University of Adelaide, School of Computer Science
Chapter Fourteen Strings Revisited. Strings A string is an array of characters A string is a pointer to a sequence of characters A string is a complete.
Array_strcpy void array_strcpy(char dest[], char src[]) { int i = 0; while (src[i] != '\0') { dest[i] = src[i]; i++; } dest[i] = '\0'; }
Computer Architecture CSCE 350
MIPS Function Continued
Csci136 Computer Architecture II Lab#4. - Stack and Nested Procedures
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
Ch. 8 Functions.
The University of Adelaide, School of Computer Science
.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,
The University of Adelaide, School of Computer Science
CS3350B Computer Architecture Winter 2015 Lecture 4
Procedure call frame: Hold values passed to a procedure as arguments
Lecture 8: MIPS Instruction Set
Solution to Problem Recitation #1 (Week 2) ECEN350 Prof. Choi.
Pointer, malloc and realloc 1. Name entered was 6 char, not enough space to put null terminator 2 Array of char.
Homework 2 Review Cornell CS Calling Conventions int gcd(int x, int y) { int t, a = x, b = y; while(b != 0) { t = b; b = mod(a, b); a = t; } return.
CS61C Final Review Fall Overview 1 st Half (Jeremy) –Number Rep (Int/Float) –C (Pointers & Malloc) –MIPS Assembly –Combinational Logic –Audience.
Register Conventions (1/4) °CalleR: the calling function °CalleE: the function being called °When callee returns from executing, the caller needs to know.
Intro to Computer Architecture
1 Lecture 5: MIPS Examples Today’s topics:  the compilation process  full example – sort in C Reminder: 2 nd assignment will be posted later today.
String C and Data Structures Baojian Hua
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
MIPS function continued. Recursive functions So far, we have seen how to write – A simple function – A simple function that have to use the stack to save.
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.
Recitation Material of Quiz 1 June 11, Problem 1.
CS61C Midterm 1 Review Summer 2004 Pooya Pakzad Ben Huang Navtej Sadhal.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /22/2013 Lecture 12: Character Data Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
1 CS61C L6 Machine Rep CENG 311 Procedure Conventions & The Stack.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Function Calls in Assembly MIPS R3000 Language (extensive use of stack) Updated 7/11/2013.
Computer structure: Procedure Calls
Lecture 5: Procedure Calls
MIPS Assembly Language Programming
CSCI206 - Computer Organization & Programming
Procedures (Functions)
CDA 3101 Spring 2016 Introduction to Computer Organization
CSCI206 - Computer Organization & Programming
Prof. Hakim Weatherspoon
MIPS Procedures.
Calling Conventions Hakim Weatherspoon CS 3410, Spring 2012
Addressing in Jumps jump j Label go to Label op address 2 address
Instructor Eric Chang Greet class… SLOOOOOOOOOOWWW DOOOOOWNNNNN
CSCI206 - Computer Organization & Programming
The University of Adelaide, School of Computer Science
MIPS Functions.
MIPS functions.
MIPS function continued
Procedures and Calling Conventions
MIPS function continued
MIPS R3000 Subroutine Calls and Stack
Presentation transcript:

MIPS, C, and You

Ropes struct ropeNode { char * string; // 0x0 offset struct ropeNode * next; // 0x4 offset } typedef struct ropeNode* rope; rope weave(char * str, rope r){ // append str to the front of r (copy str) } void fray(rope r){ // free all memory associated with r }

Weave, C->MIPS struct ropeNode { char * string; // 0x0 offset struct ropeNode * next; // 0x4 offset } rope weave(char * str, rope r){ rope end = (rope) malloc (sizeof(struct ropeNode)); end->string = (char *) malloc ((strlen(str) + 1)*sizeof(char)); strcpy(end->string, str); end->next = r; return end; } # $s0 = str, $s1 = r, $s2 = end weave: # FILL ME IN!

Weave, in MIPS weave: #prologue addiu $sp, $sp, -16 sw $ra, 0($sp) sw $s0, 4($sp) sw $s1, 8($sp) sw $s2, 12($sp) #body move $s0, $a0 move $s1, $a1 li $a0, 8 jal malloc move $s2, $v0 move $a0, $s0 jal strlen addiu $a0, $v0, 1 jal malloc sw $v0, 0($s2) move $a0, $v0 move $a1, $s0 jal strcpy sw $s1, 4($s2) move $v0, $s2 #epilogue lw $ra, 0($sp) lw $s0, 4($sp) lw $s1, 8($sp) lw $s2, 12($sp) addiu $sp, $sp, 16 jr $ra

Fray, C->MIPS struct ropeNode { char * string; // 0x0 offset struct ropeNode * next; // 0x4 offset } void fray(rope r){ if (r->next != NULL) fray(r->next); free(r->string); free(r); } fray: #fill me in!

Fray, in MIPS fray: addiu $sp, $sp, -8 sw $ra, 0($sp) sw $s0, 4($sp) move $s0, $a0 lw $t0, 4($s0) beq $t0, $zero, done move $a0, $t0 jal fray done:lw $a0, 0($s0) jal free move $a0, $s0 jal free lw $ra, 0($sp) lw $s0, 4($sp) addiu $sp, $sp, 8 jr $ra