CS41B MACHINE David Kauchak CS 52 – Fall 2015. Admin  Midterm Thursday  Review question sessions tonight and Wednesday  Assignment 3?  Assignment.

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

10/6: Lecture Topics Procedure call Calling conventions The stack
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
Computer Architecture CSCE 350
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Ch. 8 Functions.
Procedures II (1) Fall 2005 Lecture 07: Procedure Calls (Part 2)
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 and Stacks. Outline Stack organization PUSH and POP instructions Defining and Calling procedures.
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
CSS 372 Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture Traps Interrupts.
1 Function Calls Professor Jennifer Rexford COS 217 Reading: Chapter 4 of “Programming From the Ground Up” (available online from the course Web site)
CS 536 Spring Code generation I Lecture 20.
20/06/2015CSE1303 Part B lecture notes 1 Functions, part 2 Lecture B15 Lecture notes, section B15.
Intro to Computer Architecture
CMSC 414 Computer and Network Security Lecture 20 Jonathan Katz.
CS-2710 Dr. Mark L. Hornick 1 Defining and calling procedures (subroutines) in assembly And using the Stack.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Functions and Procedures. Function or Procedure u A separate piece of code u Possibly separately compiled u Located at some address in the memory used.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
Lesson 13 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
CS41B MACHINE David Kauchak CS 52 – Fall Admin  Assignment 3  due Monday at 11:59pm  one small error in 5b (fast division) that’s been fixed.
Procedure Basics Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Procedure Support From previous study of high-level languages,
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
Lecture 4: MIPS Instruction Set
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
ITEC 352 Lecture 19 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Stacks Function activation / deactivation.
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.
Function Calling. Mips Assembly Call and Return Steps for procedure calling –Save the return address –Jump to the procedure (function) –Execute the procedure.
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Programming Model CS 333 Sam Houston State University Dr. Tim McGuire.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Section 5: Procedures & Stacks
The Little man computer
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
Computer Science 210 Computer Organization
Lecture 5: Procedure Calls
David Kauchak CS 52 – Spring 2017
The Stack.
Lecture 4: MIPS Instruction Set
143A: Principles of Operating Systems Lecture 4: Calling conventions
David Kauchak CS 52 – Spring 2016
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Introduction to Compilers Tim Teitelbaum
CS41B recursion David Kauchak CS 52 – Fall 2015.
Assembly Programming using MIPS R3000 CPU
Pick up the handout on your way in!!
Stack Frame Linkage.
MIPS Instructions.
ECE232: Hardware Organization and Design
The University of Adelaide, School of Computer Science
Lecture 5: Procedure Calls
10/4: Lecture Topics Overflow and underflow Logical operations
Program and memory layout
Assembly Programming using MIPS R3000 CPU
Program and memory layout
Some Assembly (Part 2) set.html.
Computer Architecture
Program and memory layout
Program and memory layout
Procedure Support From previous study of high-level languages, we know the basic issues: - declaration: header, body, local variables - call and return.
Topic 2b ISA Support for High-Level Languages
Implementing Functions: Overview
Presentation transcript:

CS41B MACHINE David Kauchak CS 52 – Fall 2015

Admin  Midterm Thursday  Review question sessions tonight and Wednesday  Assignment 3?  Assignment 4 out soon  Due Monday 10/12

Examples from this lecture

CS41B machine CPU processor registers ic r0 r1 r2 r3 instruction counter (location in memory of the next instruction in memory) holds the value 0 (read only) -general purpose -read/write

CS41B code Four main types of operations 1. math 2. branch/conditionals 3. memory 4. control the machine (e.g. stop it)

CS41B execution

operation name (always three characters)

operation arguments R = register (e.g. r0) S = signed number (byte)

operation function dest = first register src0 = second register src1 = third register arg = number/argument

adc r1 r0 8 neg r2 r1 sub r2 r1 r2 What number is in r2?

adc r1 r0 8 neg r2 r1 sub r2 r1 r2 r1 = 8 r2 = -8, r1 = 8 r2 = 16

sto = save data in register TO memory loa = put data FROM memory into a register Special cases: -saving TO (sto) address 0 prints -reading from (loa) address 0 gets input from user

Basic structure of CS41B program ; great comments at the top! ; instruction1; comment instruction2; comment... hlt end whitespace before operations/instructions

Running the CS41B machine Look at subtract.a41 - load two numbers from the user - subtract - print the result

CS41B simulater Different windows  Memory (left)  Instruction execution (right)  Registers  I/O and running program

What do these operations do?

Modify ic, the instruction counter… which changes the flow of the program!

beq r3 r0 done What does this do?

beq r3 r0 done If r3 = 0, branch to the label “done” if not (else) ic is incremented as normal to the next instruction

ble r2 r3 done What does this do?

ble r2 r3 done If r2 <= r3, branch to the label done

-Conditionals -Loops -Change the order that instructions are executed

Basic structure of CS41B program ; great comments at the top! ; instruction1; comment instruction2; comment... label1 instruction; comment label2... hlt end - whitespace before operations/instructions - labels go here

More CS41B examples Look at max_simple.a41 - Get two values from the user - Compare them - Use a branch to distinguish between the two cases - Goal is to get largest value in r3 - print largest value

What does this code do? bge r3 r0 elif sbc r2 r0 1 brs endif elif beq r3 r0 else adc r2 r0 1 brs endif else add r2 r0 r0 endif sto r0 r2 hlt end

What does this code do? bge r3 r0 elif sbc r2 r0 1 brs endif elif beq r3 r0 else adc r2 r0 1 brs endif else add r2 r0 r0 endif sto r0 r2 hlt end if( r3 < 0 ){ r2 = -1 }else if( r3 != 0 ){ r2 = 1 }else{ r2 = 0 }

What does this code do? bge r3 r0 elif; if r3 >= 0 go to elif sbc r2 r0 1; r3 < 0: r2 = -1 brs endif; jump to end of if/elif/else elif beq r3 r0 else; if r3 = 0 go to else adc r2 r0 1; r3 > 0: r2 = 1 brs endif; jump to end of if/elif/else else add r2 r0 r0; r3 = 0: r2 = 0 endif sto r0 r2; print out r2 hlt end

Your turn Write some code that prints out abs(r3)

abs Look at abs.a41

Memory layout 0 Code Heap Stack Where dynamically allocated program data is stored Where program/function execution information is stored, parameters, and local variables

Stacks Two operations  push: add a value in the register to the top of the stack  pop: remove a value from the top of the stack and put it in the register

Stack frame Key unit for keeping track of a function call - return address (where to go when we’re done executing) - parameters - local variables

CS41B function call conventions r1 is reserved for the stack pointer r2 contains the return address r3 contains the first parameter additional parameters go on the stack (more on this) the result should go in r3

Structure of a single parameter function fname psh r2; save return address on stack...; do work using r3 as argument ; put result in r3 pop r2; restore return address from stack jmp r2; return to caller conventions: -argument is in r3 -r1 is off-limits since it’s used for the stack pointer -return value goes in r3

Our first function call loa r3 r0 ; get variable lcw r2 increment ; call increment cal r2 r2 sto r0 r3 ; write result, hlt ; and halt increment psh r2 ; save the return address on the stack adc r3 r3 1 ; add 1 to the input parameter pop r2 ; get the return address from stack jmp r2 ; go back to where we were called from

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2 r3 Stack sp (r1)

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2 r3 Stack sp (r1)

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2 r310 Stack sp (r1)

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2 r310 Stack sp (r1)

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2increment r310 Stack sp (r1)

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2increment r310 Stack sp (r1) 1.Go to instruction address in r2 (2 nd r2) 2.Save current instruction address in r2

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2loc: cal r310 Stack sp (r1) 1.Go to instruction address in r2 (2 nd r2) 2.Save current instruct address in r2

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2loc: cal r310 Stack sp (r1)

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2loc: cal r310 Stack sp (r1) loc: cal

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2loc: cal r310 Stack sp (r1) loc: cal

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2loc: cal r311 Stack sp (r1) loc: cal

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2loc: cal r311 Stack sp (r1) loc: cal

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2loc: cal r311 Stack sp (r1)

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2loc: cal r311 Stack sp (r1)

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2loc: cal r311 Stack sp (r1)

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2loc: cal r311 Stack sp (r1) 11

Our first function call loa r3 r0 lcw r2 increment cal r2 r2 sto r0 r3 hlt increment psh r2 adc r3 r3 1 pop r2 jmp r2 r2loc: cal r311 Stack sp (r1)

Examples from this lecture