MicroComputer Engineering IntroLab1 page 1 Introduction Lab1  A crash course in assembler programming  Learn how a processor works!  Decode a coded.

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

The University of Adelaide, School of Computer Science
Slides revised 3/25/2014 by Patrick Kelley. 2 Procedures Unlike other branching structures (loops, etc.) a Procedure has to return to where it was called.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
©UCB CS 161 Lecture 4 Prof. L.N. Bhuyan
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
The University of Adelaide, School of Computer Science
Computer Architecture CSCE 350
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.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
Procedures II (1) Fall 2005 Lecture 07: Procedure Calls (Part 2)
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
Procedure call frame: Hold values passed to a procedure as arguments
 Procedures (subroutines) allow the programmer to structure programs making them : › easier to understand and debug and › allowing code to be reused.
CS 536 Spring Code generation I Lecture 20.
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.
RISC Concepts, MIPS ISA and the Mini–MIPS project
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
331 Practice Exam.1Fall 2003 Naming Conventions for Registers 0$zero constant 0 (Hdware) 1$atreserved for assembler 2$v0expression evaluation & 3$v1function.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
Some material taken from Assembly Language for x86 Processors by Kip Irvine © Pearson Education, 2010 Slides revised 2/2/2014 by Patrick Kelley.
Memory/Storage Architecture Lab Computer Architecture MIPS Instruction Set Architecture ( Supporting Procedures )
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Computer Engineering IntroLab1 page 1 Beginners explanation on how a processor works! The labs will teach you the truth.
Slides revised 3/25/2014 by Patrick Kelley. 2 Procedures Higher Level languages have adopted a standard Referred to as C-style calling Uses the stack.
CSE331 W02.1Irwin Fall 2001 PSU Computer Architecture Discussion Lecture # 2 MIPS Programming.
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.
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.
Computer Organization CS224 Fall 2012 Lessons 9 and 10.
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.
© G. Drew Kessler and William M. Pottenger1 Subroutines, Part 2 CSE 262, Spring 2003.
Lecture 2: Instruction Set Architecture part 1 (Introduction) Mehran Rezaei.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 3.
MIPS Lab CMPE 142 – Operating Systems. MIPS Simulator First Time Startup Setting Options.
Function Calling. Mips Assembly Call and Return Steps for procedure calling –Save the return address –Jump to the procedure (function) –Execute the procedure.
MicroComputer Engineering ActivationConcept page 1 Problem: !bell!help! !1! 2! !Bal help! !!! Bal bell! 3Jr $31!!! !Jr $31 ! What happend here? What will.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
Computer Architecture & Operations I
Computer Science 210 Computer Organization
Computer structure: Procedure Calls
Prof. Hsien-Hsin Sean Lee
Example Addiu $t1 $r0 3 Addiu $t1 $t1 5 Addiu $t1 $t1 7.
Procedures 101: There and Back Again
Lecture 4: MIPS Instruction Set
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Procedures (Functions)
Procedures (Functions)
Assembly Programming using MIPS R3000 CPU
Instructions - Type and Format
MIPS Instructions.
The University of Adelaide, School of Computer Science
Lecture 5: Procedure Calls
Problem: ! bell ! help ! ! 1 ! 2 ! ! Bal help ! ! ! !
Problem: ! bell ! help ! ! 1 ! 2 ! ! Bal help ! ! ! !
Assembly Programming using MIPS R3000 CPU
Computer Architecture
Where is all the knowledge we lost with information? T. S. Eliot
Introduction Lab1 A crash course in assembler programming
Presentation transcript:

MicroComputer Engineering IntroLab1 page 1 Introduction Lab1  A crash course in assembler programming  Learn how a processor works!  Decode a coded text passage

MicroComputer Engineering IntroLab1 page 2 Lab 1 Procedure calls. Byte and word array indexing, pointers. Conditional branch instructions. Simple loops. Reading/ writing from/to data memory.

MicroComputer Engineering IntroLab1 page 3 Branch instruction (part of) Beqrs rt label Bners rt label Together with Slt-instruction and $0 enough for first lab.

MicroComputer Engineering IntroLab1 page 4 Register conventions (fig A9) Reg. nameNrUsage zero 0Constant 0 at1Reserved for assembler v0 - v12-3Expr. evaluation, function results a0 - a34-7Argument 1-4 t0 - t78-15Temporary (not saved) s0 - s716-23Saved Temporary t8 - t924-25Temporary (not saved) k0 - k126-27Reserved for OS kernel gp28Pointer to global area sp29Stack pointer fp30Frame pointer ra31Return address

MicroComputer Engineering IntroLab1 page 5 Lab 1 register usage Use only $sxfor accessing global variables $txfor your local variables $axfor parameters $vxfor results $r0(=$0)

MicroComputer Engineering IntroLab1 page 6 Lab 1 register usage Use only $sxfor accessing global variables $txfor your local variables $axfor parameters $vxfor results $r0(=$0)

MicroComputer Engineering IntroLab1 page 7 Lab 1 - stack frame ============== "sum" with frame pointer ================ ===== example of a subroutine with frame pointer. ===== ===== easier to restore and manage the stack. ===== ===== little bit less efficient code. ===== # ================================== # compute sum = n + (n-1)+(n-2) # call only for n 0. # sum( n: int ): int (direct-recursive) # x: int; (example of local variable) # if n = 1 # then return( 1 ) # else return( n + sum(n-1) ); sum: addiu $sp, $sp, -4 sw $31, 0($sp)# push the return addr addiu $sp, $sp, -4 sw $fp, 0($sp)# push the old frame pointer move $fp, $sp# establish new frame pointer. addiu $sp, $sp, -8# make room for 2 full # word local variables # everything above is called the "entry sequence". # the stack now looks like this. # YOU MUST SHOW US A DIAGRAM LIKE THIS, FOR ALL # THE SUBROUTINES YOU WRITE IN YOUR FIRST LAB. # # # | uninit, for "x" | -8($fp) <= $sp points here # # | uninit, for "n" | -4($fp) # # | old frame pointer | 0($fp) <= $fp points here # # | our return addr | 4($fp) # # | | # | caller's stack | # | | # # (we don't need "x" below, just given as an example.) # now this activation can access its activation record # RELATIVE TO THE FRAME POINTER, like this: save: sw $a0, -4($fp)# save "n" into local var if: ori $t0, $zero, 1# $t0 := 1 bne $a0, $t0, else# n 1, jump to "else" then: ori $v0, $zero, 1# n = 1: return value := 1, b exit# escape to exit sequence. else: addiu $a0, $a0, -1# compute n-1 (destroys $a0). bal sum# $v0 := sum( n-1 ). lw $t0, -4($fp)# fetch value "n". addu $v0, $v0, $t0# $v0 := n + sum( n-1 ). # the exit sequence reverses the entry sequence: exit: move $sp, $fp# all local var's gone: easy ! lw $fp, 0($sp)# restore old $fp addiu $sp, $sp, 4# and pop that word, lw $31, 0($sp)# restore return address, addiu $sp, $sp, 4# and pop that word. jr $31# return =========== end "sum" with frame pointer ===============