CPEG323 Homework Review I Long Chen October, 17 th, 2005.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

Lecture 5: MIPS Instruction Set
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
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.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
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.
MIPS Calling Convention Chapter 2.7 Appendix A.6.
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
Computer Architecture CSCE 350
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.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Ch. 8 Functions.
The University of Adelaide, School of Computer Science
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
The University of Adelaide, School of Computer Science
Lecture 8: MIPS Instruction Set
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
Intro to Computer Architecture
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
CHAPTER 2 ISA Instructions (logical + procedure call)
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
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.
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 7: MIPS Instructions III
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Procedure Basics Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Procedure Support From previous study of high-level languages,
1 Branches and Procedure Calls Lecture 14 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Lecture 4: MIPS Instruction Set
Computer Architecture CSE 3322 Lecture 4 crystal.uta.edu/~jpatters/cse3322 Assignments due 9/15: 3.7, 3.9, 3.11.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
COMPUTER ORGANIZATION LECTURE 3: ISA YASSER MOHAMMAD.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic4: Procedures José Nelson Amaral.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
Computer Architecture & Operations I
Rocky K. C. Chang Version 0.1, 25 September 2017
Lecture 5: Procedure Calls
CS2100 Computer Organisation
CSCI206 - Computer Organization & Programming
Lecture 4: MIPS Instruction Set
Procedures (Functions)
Procedures (Functions)
The University of Adelaide, School of Computer Science
CSCI206 - Computer Organization & Programming
What's wrong with this procedure?
Pick up the handout on your way in!!
CSCI206 - Computer Organization & Programming
Addressing in Jumps jump j Label go to Label op address 2 address
Solutions Chapter 2.
MIPS Instructions.
ECE232: Hardware Organization and Design
CSCI206 - Computer Organization & Programming
The University of Adelaide, School of Computer Science
Lecture 5: Procedure Calls
Logical and Decision Operations
Systems Architecture I
Computer Architecture
MIPS function continued
Conditional Branching (beq)
Presentation transcript:

CPEG323 Homework Review I Long Chen October, 17 th, 2005

Homework 1 Basic Computer Terms Problem 1: Find the correct word that best matches the given description Problem 1: Find the correct word that best matches the given description Problem 2: Classify the items into the categories Problem 2: Classify the items into the categories You need to read Chapter 1 of the textbook to understand/answer these questions

Homework 1 - cont Problem 3 Problem 3 –On average, it takes half a revolution for the desired data on the disk to spin under the read/write head. –Disk is rotating 7200 revolutions per minute (RPM) –Average time for the data to rotate under the disk head? Answer: 1 min / 7200 * ½ Answer: 1 min / 7200 * ½

Homework 1 - cont Problem 4 Problem 4 –One computer issues 30 requests per second –Each request is on average 64KB –Will a 100Mbit Ethernet link be sufficient? Answer Answer –30 * 64 KB/s = 1,920 KB/s = 15,360 Kbit/s –100Mbit/s > 15,360 Kbit/s, sufficient! –B (Byte) versus b (bit) (Bps versus bps)

Homework 2 Problem 1: Problem 1: –Draw the Control Flow Graph (CFG) of code for (i = 0; i < x, i ++) y = y + i; i = 0 i < x y = y + i; i = i + 1; Yes No Similarly, you can group the assembly instructions into basic blocks, then draw the CFG Basic block: no jump, no exit

Homework 2 - cont Problem 2 Problem 2 –A) Why doesn’t MIPS have a subtract immediate instruction? –Answer: MIPS includes add immediate instruction MIPS includes add immediate instruction Positive and negative immediate Positive and negative immediate Add neg imm = sub pos imm Add neg imm = sub pos imm –B) Hexadecimal number -> binary number –C) Binary number -> hexadecimal number

Homework 2 - cont Problem 3 Problem 3 –Implement the C code in MIPS –Draw the status of the stack –Indicate locations of $sp and $fp –Stack pointer: a value denoting the most recently allocated address in a stack –Frame pointer: a value denoting the location of the saved registers and local variables for a given procedure (point to the first word of the frame of a procedure)

Homework 2 - cont Illustration of the stack allocation (a) before, (b) during, and (c) after the procedure call -Reproduce from P & H “Computer Organizatio and Design” 3 rd Edition

Homework 2 - cont int i; void set_array(int num) { int arrray[10]; for (i=0;i<10;i++){ array[i]=compare(num,i); array[i]=compare(num,i);}} set_array: addi $sp, $sp, -52 # move stack pointer sw $fp, 48($sp) # save frame pointer sw $ra, 44($sp) # save return address sw $a0, 40($sp) # save parameter (num) addi $fp, $sp, 48 # establish frame pointer add $s0, $zero, $zero # i = 0 addi $t0, $zero, 10 # max iterations is 10 loop: sll $t1, $s0, 2 # $t1 = i * 4 add $t2, $sp, $t1 # $t2 = address of array[i] add $a0, $a0, $zero # pass num as parameter add $a1, $s0, $zero # pass i as parameter jal compare # call compare(num, i) sw $v0, 0($t2) # array[i] = compare(num, i); addi $s0, $s0, 1# i = i+ 1 bne $s0, $t0, loop # loop if i<10 lw $a0, 40($sp) # restore parameter (num) lw $ra, 44($sp) # restore return address lw $fp, 48($sp) # restore frame pointer addi $sp, $sp, 52 # restore stack pointer jr $ra # return

Homework 2 - cont int compare( int a, int b) { if (sub(a, b) >= 0) return 1; else return 0; } compare: addi $sp, $sp, -8 # move stack pointer sw $fp, 4($sp) # save frame pointer sw $ra, 0($sp) # save return address addi $fp, $sp, 4 # establish frame pointer jal sub # can jump directly to sub slt $v0, $v0, $zero # if sub(a,b) >= 0, return 1 slti $v0, $v0, 1 lw $ra, 0($sp) # restore return address lw $fp, 4($sp) # restore frame pointer addi $sp, $sp, 8 # restore stack pointer jr $ra # return sub: sub $v0, $a0, $a1 # return a-b jr $ra # return int sub( int a, int b) { return a – b; } This function does not change argument registers, so, we do not need to save these registers, i.e. $a0, $a1 We don’t save anything. Why?

Homework 2 - cont The status of the stack

Homework 2 - cont Problem 4 Problem 4 –Comment the following MIPS code –Descript the functionality ($v0 = ?) –As inputs, $a0 = a; $a1 = b add $t0, $zero, $zero loop: beq $a1, $zero, finish add $t0, $t0, $a0 sub $a1, $a1, 1 j loop finish: addi $t0, $t0, 100 add $v0, $t0, $zero # initialize running sum $t0 = 0 # finished when $a1 is 0 # sum $t0 = $t0 + $a0 # compute this $a1 times # add 100 to a * b # return a * b + 100

Homework 2 - cont Problem 5 Problem 5 –Explain why an assembler might have problems directly implementing the branch instruction in the following code segment here:beq$s0, $s2, there … there:add$s0, $s0, $s0

Homework 2 - cont Jump instruction: j10000 Conditional branch instruction: beq$s0, $s2, there New PC = PC + Branch address (PC-relative addressing) bits 26 bits bits 16 bits bits If that address is too far away, we won’t be able to use 16 bits to describe where it is relative to the PC

Homework 2 - cont One simple solution would be here: bne $s0, $s2, skip j there skip:… there: add $s0, $s0, $s0 This will work as long as our program does not cross the 256MB (why?) address boundary described in the elaboration on page 98 in the textbook.

Homework 3 Please refer to the solution to be posted by tonight

Good Luck on your test! Good Luck on your test!