Wednesday, September 27, 2017

Size: px
Start display at page:

Download "Wednesday, September 27, 2017"

Transcription

1 Wednesday, September 27, 2017 Topics for today Chapter 6: Mapping High-level to assembly-level The Pep/9 run-time stack (6.1) Stack-relative addressing (,s) SP manipulation Stack as scratch space Global variables and local variables Parameter passing and return values The Pep/9 run-time stack (Section 6.1) The Pep/9 run-time stack is at the high end of the memory allocated to the user (see e.g., Fig. 4.41). This is to minimize the possibility that when the stack grows it runs into the user program. The stack pointer register (SP) holds the address of the top item of the stack. Stacks in general The stack data structure is sometimes referred to as a Last-in First-out queue (or First-In, Lastout) meaning that the last item put into the stack is the first one to be removed. Think of a stack of books or a stack of plates. The push operation adds an item to the stack (at the top) and the pop operation removes the top item Push 3 Push 7 Pop Push 4 Push 9 Pop Comp 162 Notes Page 1 of 10 September 27, 2017

2 Stack in Pep/9 The Pep/9 stack plays a large part in non-trivial assembly code programs - those with subroutine calls. The Pep/9 stack is used for: - storing local variables - remembering a return address when a subroutine is called - passing parameters into subroutines - returning values from subroutines - scratch space We do not (usually) need to know the actual memory address of any item in the stack because we can access them using stack-relative addressing. So far, we have seen two of Pep/9 s eight addressing modes: Direct addressing: E.g. ldwa 3,d ; load contents of address 3 (and 4) into register A Immediate addressing: E.g. ldwa 3,i ; load the number 3 into register A In section 6.1, Warford introduces the third addressing mode (stack-relative addressing) and shows how the stack is used in providing space for local variables (he uses the example of the locals in the main program function). Stack-relative addressing E.g. ldwa 3,s loads into register A the word that begins at memory[ SP + 3] that is, loads the word that starts three bytes down from the top of the stack If the bytes of the stack (in hex) are Comp 162 Notes Page 2 of 10 September 27, 2017

3 A7 SP E 4C then after the load instruction, register A contains 7E4C. Similarly, loads 1355 into Register X. ldwx 1,s The number before,s can be negative allowing us to access locations above the stack pointer. There are various reasons why we might want to do that see later. Note that the Pep/9 stack grows upwards towards address zero (000016) so items that are in the middle of the stack have larger addresses than the item at the top of the stack. You may have encountered the stack Abstract Data Type (ADT) in a data structures class. In the case of the stack ADT we are only permitted to access the top of the stack using POP and PUSH operations to remove or add items respectively. At the assembly language level we may need to be able to quickly access items stored within the stack; stack relative addressing lets us do that. Changing the size of the stack Some instructions (see later) change the size of the stack (the value in SP) as a side effect of their actions (think pop and push). In addition, there are two instructions that let us directly manipulate the SP register. We use these two instructions to allocate and deallocate space on the stack. ADDSP - add to SP, i.e. move SP away from zero so make the stack smaller SUBSP - subtract from SP, i.e. move the SP towards zero so make the stack bigger. [Note that Pep/9 does not really need two different instructions. For example, ] SUBSP 6,i ADDSP -6,i Comp 162 Notes Page 3 of 10 September 27, 2017

4 Stack trace question. What does the stack look like after the following sequence? subsp 5,i ldwa 0x9876,i ldwx 0x1234,i stwa 2,s stwx 3,s adda 1,i addsp 4,i stba -4,s Answer 77?? Preview of stack operations During the course of Chapter 6 we will look at the various ways in which the stack is used. Here is a preview of some of them don t worry yet about the details. (1) Stack used as scratch space We can use the stack as temporary space without changing SP. In the following code we input three numbers then output them in reverse order. deci -2,s deci -4,s deci -6,s deco -6,s deco -4,s deco -2,s Technically we are not using the stack but the area above it. This is usually a safe thing to do and avoids having to declare variables to hold temporary values. Comp 162 Notes Page 4 of 10 September 27, 2017

5 (2) Stack contains local variables In the following example C program there are global variables (a,b and c) that can be accessed anywhere variables local to test (p,q and r) that can accessed only from inside test variables local to main (x, y and z) that can be accessed only from inside main. #include <stdio.h> int a,b,c; test() int p,q,r; // these are globals // p, q and r are local to test main () int x,y,z; test(); // x, y and z are local to main // calling test When a function is called, we have to allocate bytes on the stack for its local variables (if any) and adopt some convention about which location corresponds to which variable. For example, here is how the stack might look as the program runs. On entry to a function (main or test) we allocate space for the local variables. When we exit from the call of a function we deallocate this space. In addition, we have the space for the return address (RA) that lets us return to the correct location in main when we have finished the call of test. z y x RA z y x r q p RA z y x Initially Main starts Main calls test Test running Test finishes Main resumes End RA z y x z y x Comp 162 Notes Page 5 of 10 September 27, 2017

6 Consider the following C program #include <stdio.h> int A,B; int main() int C,D,E; A = C+D; Ignoring for the moment the fact that main is really a function, this might be translated into Pep/9 assembly code as br main A:.block 2 B:.block 2 main: subsp 6,i ; allocate stack space for C, D and E ldwa 4,s ; C adda 2,s ; D stwa A,d addsp 6,i stop.end ; end of main so finished with C, D and E At the end of the "main" function it does not really matter if we deallocate the stack space allocated at the beginning of main because the program is about to terminate. However, in the case of all other functions it is normally critically important that we tidy up the stack before exiting - more later. The following run of a C program illustrates that in at least one environment, when we allocate space for local variables we get whatever values are in those locations last time they were used. If no other function calls intervene then we might find values left over from the previous call of one of our functions. #include <stdio.h> void test() int A,B,C; printf("%d %d %d\n",a,b,c); // print initial contents of locals A=1; B=2; C=3; printf("%d %d %d\n",a,b,c); int main() test(); test(); Comp 162 Notes Page 6 of 10 September 27, 2017

7 The program output shows that the first time test was called, the initial values of the local variables were garbage but the second time, the space still had the numbers left there by the first call. ~$./a.out Here is a summary of some differences between local variables and global variables as commonly implemented in Pep/9. Globals Locals Declaration using.block,.word,.byte allocated space on the stack dynamically Accessibility anywhere in the program. In theory, only while appropriate function is active (space goes away on exit from the function) Referenced by identifier stack-relative addressing Initialization by.word,.byte,.ascii at load time. by assignment of values at run-time (3) Return addresses, passed parameters and return values Suppose we have the Pep/9 equivalent of the following C function int functionname (int B, int C) int D, E; *** and it is being called as follows W = functionname(p,q) Comp 162 Notes Page 7 of 10 September 27, 2017

8 then during the execution of the function, at the point marked ***, the topmost locations on the stack can be depicted Space for local variable D Space for local variable E Address to return to when function terminates Value of parameter P Value of parameter Q Space for the value returned by functionname (P and Q could be the other way round; D and E could be the other way round). We will look later at many examples of translations of C functions into Pep/9 (including recursive ones!). The stack is a shared memory location that lets information (parameter values) be passed from main program to subprogram and information (returned value) be passed from subprogram to main program Reading. Section 6.1. We will begin looking at functions (C) and subroutines (Pep/9) next week but Section 6.3 is tricky so read slowly. Comp 162 Notes Page 8 of 10 September 27, 2017

9 Review Questions 1. If this diagram represents the top of the stack 32 4F E What number does the following instruction put in Register A? ldwa 1,s 2. If register A contains ABCD 16 which byte in the stack of Q1 changes and what is the new value when the following instruction is executed? stba 3,s 3. Consider the following two sequences of instructions subsp 4,i deci -4,s deci 0,s deci -2,s deci 2,s subsp 4,i Do they have the same net effect on memory and the SP register? 4. Consider the diagram from earlier Space for local variable D Space for local variable E Address to return to when function terminates Value of parameter P Value of parameter Q Space for the value returned by functionname Which of these 6 spaces is always the same size and how big is it? 5. If E and Q are char and D and P are int and the function returns a char, how much total space is needed for the 6 items in the diagram? Comp 162 Notes Page 9 of 10 September 27, 2017

10 Review Answers 1. 4F is changed to CD 3. Yes. 4. The return address is always 2 bytes bytes ( ) Comp 162 Notes Page 10 of 10 September 27, 2017

Monday, September 28, 2015

Monday, September 28, 2015 Monda, September 28, 2015 Topics for toda Chapter 6: Mapping High-level to assembl-level The Pep/8 run-time stack (6.1) Stack-relative addressing (,s) SP manipulation Stack as scratch space Global variables

More information

Wednesday, February 19, 2014

Wednesday, February 19, 2014 Wednesda, Februar 19, 2014 Topics for toda Solutions to HW #2 Topics for Eam #1 Chapter 6: Mapping High-level to assembl-level The Pep/8 run-time stack Stack-relative addressing (,s) SP manipulation Stack

More information

Wednesday, February 28, 2018

Wednesday, February 28, 2018 Wednesday, February 28, 2018 Topics for today C functions and Pep/9 subroutines Introduction Location of subprograms in a program Translating functions (a) Void functions (b) Void functions with parameters

More information

Monday, March 13, 2017

Monday, March 13, 2017 Monday, March 13, 2017 Topics for today Arrays and Indexed Addressing Global arrays Local arrays Buffer exploit attacks Arrays and indexed addressing (section 6.4) So far we have looked at scalars (int,

More information

Monday, March 6, We have seen how to translate void functions. What about functions that return a value such as

Monday, March 6, We have seen how to translate void functions. What about functions that return a value such as Monday, March 6, 2017 Topics for today C functions and Pep/9 subroutines Translating functions (c) Non-void functions (d) Recursive functions Reverse Engineering: Pep/9 to C C Functions and Pep/9 Subroutines

More information

Wednesday, February 15, 2017

Wednesday, February 15, 2017 Wednesday, February 15, 2017 Topics for today Before and after assembly: Macros, Linkers Overview of Chapter 6 Branching Unconditional Status bits and branching If statements While statements The V and

More information

Monday, March 27, 2017

Monday, March 27, 2017 Monday, March 27, 2017 Topics for today Indexed branching Implementation of switch statement Reusable subroutines Indexed branching It turns out that arrays are useful in translating other language constructs,

More information

Wednesday, March 14, 2018

Wednesday, March 14, 2018 Wednesday, March 14, 2018 Topics for today Arrays and Indexed Addressing Arrays as parameters of functions Multi-dimensional arrays Option A: Space-minimal solution Option B: Iliffe vectors Array bound

More information

Wednesday, March 29, Implementation of sets in an efficient manner illustrates some bit-manipulation ideas.

Wednesday, March 29, Implementation of sets in an efficient manner illustrates some bit-manipulation ideas. Wednesday, March 29, 2017 Topics for today Sets: representation and manipulation using bits Dynamic memory allocation Addressing mode summary Sets Implementation of sets in an efficient manner illustrates

More information

Monday, October 17, 2016

Monday, October 17, 2016 Monday, October 17, 2016 Topics for today C functions and Pep/8 subroutines Passing parameters by reference Globals Locals Reverse Engineering II Representation of Booleans C Functions and Pep/8 Subroutines

More information

Monday, March 9, 2015

Monday, March 9, 2015 Monday, March 9, 2015 Topics for today C functions and Pep/8 subroutines Passing parameters by reference Globals Locals More reverse engineering: Pep/8 to C Representation of Booleans C Functions and Pep/8

More information

Wednesday, September 20, 2017

Wednesday, September 20, 2017 Wednesday, September 20, 2017 Topics for today More high-level to Pep/9 translations Compilers and Assemblers How assemblers work Symbol tables ILC Pass 1 algorithm, Error checking Pass 2 Immediate mode

More information

Wednesday, February 7, 2018

Wednesday, February 7, 2018 Wednesday, February 7, 2018 Topics for today The Pep/9 memory Four example programs The loader The assembly language level (Chapter 5) Symbolic Instructions Assembler directives Immediate mode and equate

More information

Wednesday, November 15, 2017

Wednesday, November 15, 2017 Wednesday, November 15, 2017 Topics for today Code generation Synthesis Algorithm 5: tree to code Optimizations Code generation Algorithm 5: generating assembly code Visiting all the nodes in a linked

More information

Wednesday, March 12, 2014

Wednesday, March 12, 2014 Wednesday, March 12, 2014 Topics for today Solutions to HW #3 Arrays and Indexed Addressing Global arrays Local arrays Buffer exploit attacks Solutions to Homework #3 1. deci N,d < (a) N not defined lda

More information

Monday, February 16, 2015

Monday, February 16, 2015 Monday, February 16, 2015 Topics for today How assemblers work Symbol tables ILC Pass 1 algorithm, Error checking Pass 2 Immediate mode and equate Assembler variants: Disassembler, Cross assembler Macros

More information

Wednesday, September 21, 2016

Wednesday, September 21, 2016 Wednesday, September 21, 2016 Topics for today More high-level to translations Compilers and Assemblers How assemblers work Symbol tables ILC Pass 1 algorithm, Error checking Pass 2 Immediate mode and

More information

Monday, November 7, Structures and dynamic memory

Monday, November 7, Structures and dynamic memory Monday, November 7, 2016 Topics for today Structures Structures and dynamic memory Grammars and Languages (Chapter 7) String generation Parsing Regular languages Structures We have seen one composite data

More information

Wednesday, April 19, 2017

Wednesday, April 19, 2017 Wednesday, April 19, 2017 Topics for today Process management (Chapter 8) Loader Traps Interrupts, Time-sharing Storage management (Chapter 9) Main memory (1) Uniprogramming (2) Fixed-partition multiprogramming

More information

Monday, October 24, 2016

Monday, October 24, 2016 Monday, October 24, 2016 Topics for today Arrays and Indexed Addressing Arrays as parameters of functions Multi-dimensional arrays Option A: Space-minimal solution Option B: Iliffe vectors Array bound

More information

Wednesday, October 17, 2012

Wednesday, October 17, 2012 Wednesday, October 17, 2012 Topics for today Arrays and Indexed Addressing Arrays as parameters of functions Multi-dimensional arrays Indexed branching Implementation of switch statement Arrays as parameters

More information

CSC 221: Computer Organization, Spring 2009

CSC 221: Computer Organization, Spring 2009 1 of 7 4/17/2009 10:52 AM Overview Schedule Resources Assignments Home CSC 221: Computer Organization, Spring 2009 Practice Exam 2 Solutions The exam will be open-book, so that you don't have to memorize

More information

Wednesday, April

Wednesday, April Wednesday, April 9. 2014 Topics for today Addressing mode summary Structures Structures and dynamic memory Grammars and Languages (Chapter 7) String generation Parsing Regular languages Summary of addressing

More information

Q1: /20 Q2: /30 Q3: /24 Q4: /26. Total: /100

Q1: /20 Q2: /30 Q3: /24 Q4: /26. Total: /100 ECE 2035(B) Programming for Hardware/Software Systems Fall 2013 Exam Two October 22 nd 2013 Name: Q1: /20 Q2: /30 Q3: /24 Q4: /26 Total: /100 1/6 For functional call related questions, let s assume the

More information

Wednesday, April 22, 2015

Wednesday, April 22, 2015 Wednesday, April 22, 2015 Topics for today Topics for Exam 3 Process management (Chapter 8) Loader Traps Interrupts, Time-sharing Storage management (Chapter 9) Main memory (1) Uniprogramming (2) Fixed-partition

More information

Implementing Procedure Calls

Implementing Procedure Calls 1 / 39 Implementing Procedure Calls February 18 22, 2013 2 / 39 Outline Intro to procedure calls Caller vs. callee Procedure call basics Calling conventions The stack Interacting with the stack Structure

More information

Wednesday, September 13, Chapter 4

Wednesday, September 13, Chapter 4 Wednesday, September 13, 2017 Topics for today Introduction to Computer Systems Static overview Operation Cycle Introduction to Pep/9 Features of the system Operational cycle Program trace Categories of

More information

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture COMP 303 Computer Architecture Lecture 3 Comp 303 Computer Architecture 1 Supporting procedures in computer hardware The execution of a procedure Place parameters in a place where the procedure can access

More information

Subroutines. int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;}

Subroutines. int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;} Subroutines Also called procedures or functions Example C code: int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;} // subroutine converts Celsius to kelvin int celtokel(int i) { return (i

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #6: Memory Management CS 61C L06 Memory Management (1) 2006-07-05 Andy Carle Memory Management (1/2) Variable declaration allocates

More information

Wednesday, November 8, 2017

Wednesday, November 8, 2017 Wednesday, November 8, 207 Topics for today Grammars and Languages (hapter 7) Finite State Machines Semantic actions ode generation - Overview Finite State Machines (see 7.2) If a language is regular (Type

More information

Notes on the Exam. Question 1. Today. Comp 104:Operating Systems Concepts 11/05/2015. Revision Lectures (separate questions and answers)

Notes on the Exam. Question 1. Today. Comp 104:Operating Systems Concepts 11/05/2015. Revision Lectures (separate questions and answers) Comp 104:Operating Systems Concepts Revision Lectures (separate questions and answers) Today Here are a sample of questions that could appear in the exam Please LET ME KNOW if there are particular subjects

More information

Monday, April 9, 2018

Monday, April 9, 2018 Monday, April 9, 208 Topics for today Grammars and Languages (Chapter 7) Finite State Machines Semantic actions Code generation Overview Finite State Machines (see 7.2) If a language is regular (Type 3)

More information

Monday, August 28, 2017

Monday, August 28, 2017 Monday, August 28, 2017 Topics for today Course in context. Course outline, requirements, grading. Administrivia: Tutoring: Department, PLTL, LRC Knowledge Survey The concept of a multi-level machine Motivations

More information

Implementing Subroutines. Outline [1]

Implementing Subroutines. Outline [1] Implementing Subroutines In Text: Chapter 9 Outline [1] General semantics of calls and returns Implementing simple subroutines Call Stack Implementing subroutines with stackdynamic local variables Nested

More information

Comp 204: Computer Systems and Their Implementation. Lecture 25a: Revision Lectures (separate questions and answers)

Comp 204: Computer Systems and Their Implementation. Lecture 25a: Revision Lectures (separate questions and answers) Comp 204: Computer Systems and Their Implementation Lecture 25a: Revision Lectures (separate questions and answers) 1 Today Here are a sample of questions that could appear in the exam Please LET ME KNOW

More information

CPS311 Lecture: Procedures Last revised 9/9/13. Objectives:

CPS311 Lecture: Procedures Last revised 9/9/13. Objectives: CPS311 Lecture: Procedures Last revised 9/9/13 Objectives: 1. To introduce general issues that any architecture must address in terms of calling/returning from procedures, passing parameters (including

More information

Functions in MIPS. Functions in MIPS 1

Functions in MIPS. Functions in MIPS 1 Functions in MIPS We ll talk about the 3 steps in handling function calls: 1. The program s flow of control must be changed. 2. Arguments and return values are passed back and forth. 3. Local variables

More information

Instruction Set Architectures (4)

Instruction Set Architectures (4) Computer Architecture Week 06 Instruction Set Architectures (4) College of Information Science and Engineering Ritsumeikan University subroutines functions, procedures remember the next instruction s address

More information

Stacks and Function Calls

Stacks and Function Calls Stacks and Function Calls Embedded Systems 3-1 Remember the Memory Map for Our MCU Embedded Systems 3-2 Classifying Data Variables Automatic declared within a function Only exist while the function executes

More information

Systems I. Machine-Level Programming V: Procedures

Systems I. Machine-Level Programming V: Procedures Systems I Machine-Level Programming V: Procedures Topics abstraction and implementation IA32 stack discipline Procedural Memory Usage void swap(int *xp, int *yp) int t0 = *xp; int t1 = *yp; *xp = t1; *yp

More information

Wednesday, April 16, 2014

Wednesday, April 16, 2014 Wednesday, pril 16, 2014 Topics for today Homework #5 solutions Code generation nalysis lgorithm 4: infix to tree Synthesis lgorithm 5: tree to code Optimization HW #5 solutions 1. lda 0,i ; for sum of

More information

Subprograms, Subroutines, and Functions

Subprograms, Subroutines, and Functions Subprograms, Subroutines, and Functions Subprograms are also called subroutines, functions, procedures and methods. A function is just a subprogram that returns a value; say Y = SIN(X). In general, the

More information

Assembly labs start this week. Don t forget to submit your code at the end of your lab section. Download MARS4_5.jar to your lab PC or laptop.

Assembly labs start this week. Don t forget to submit your code at the end of your lab section. Download MARS4_5.jar to your lab PC or laptop. CSC258 Week 10 Logistics Assembly labs start this week. Don t forget to submit your code at the end of your lab section. Download MARS4_5.jar to your lab PC or laptop. Quiz review A word-addressable RAM

More information

Run Time Environment

Run Time Environment CS 403 Compiler Construction Lecture 12 Run Time Environment and Management [Based on Chapter 7 of Aho2] 1 Run Time Environment From Lecture 1 to 11, we have seen many jobs that are done by a compiler.

More information

Lecture 5. Announcements: Today: Finish up functions in MIPS

Lecture 5. Announcements: Today: Finish up functions in MIPS Lecture 5 Announcements: Today: Finish up functions in MIPS 1 Control flow in C Invoking a function changes the control flow of a program twice. 1. Calling the function 2. Returning from the function In

More information

Lectures 5. Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS

Lectures 5. Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS Lectures 5 Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS 1 OOPS - What does this C code do? int foo(char *s) { int L = 0; while (*s++) { ++L; } return L; } 2

More information

CS356: Discussion #6 Assembly Procedures and Arrays. Marco Paolieri

CS356: Discussion #6 Assembly Procedures and Arrays. Marco Paolieri CS356: Discussion #6 Assembly Procedures and Arrays Marco Paolieri (paolieri@usc.edu) Procedures Functions are a key abstraction in software They break down a problem into subproblems. Reusable functionality:

More information

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 1. Do a page check: you should have 8 pages including this cover sheet. 2. You have 50 minutes

More information

MIPS Programming. A basic rule is: try to be mechanical (that is, don't be "tricky") when you translate high-level code into assembler code.

MIPS Programming. A basic rule is: try to be mechanical (that is, don't be tricky) when you translate high-level code into assembler code. MIPS Programming This is your crash course in assembler programming; you will teach yourself how to program in assembler for the MIPS processor. You will learn how to use the instruction set summary to

More information

Where does the insert method place the new entry in the array? Assume array indexing starts from 0(zero).

Where does the insert method place the new entry in the array? Assume array indexing starts from 0(zero). Suppose we have a circular array implementation of the queue,with ten items in the queue stored at data[2] through data[11]. The current capacity of an array is 12. Where does the insert method place the

More information

Run-time Environment

Run-time Environment Run-time Environment Prof. James L. Frankel Harvard University Version of 3:08 PM 20-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Storage Organization Automatic objects are

More information

Computer Systems Lecture 9

Computer Systems Lecture 9 Computer Systems Lecture 9 CPU Registers in x86 CPU status flags EFLAG: The Flag register holds the CPU status flags The status flags are separate bits in EFLAG where information on important conditions

More information

ECE331: Hardware Organization and Design

ECE331: Hardware Organization and Design ECE331: Hardware Organization and Design Lecture 8: Procedures (cont d), Binary Numbers and Adders Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Review: Procedure Calling Steps

More information

Question 1. Notes on the Exam. Today. Comp 104: Operating Systems Concepts 11/05/2015. Revision Lectures

Question 1. Notes on the Exam. Today. Comp 104: Operating Systems Concepts 11/05/2015. Revision Lectures Comp 104: Operating Systems Concepts Revision Lectures Today Here are a sample of questions that could appear in the exam Please LET ME KNOW if there are particular subjects you want to know about??? 1

More information

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 28 November 2012

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 28 November 2012 Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

More information

QUIZ. Name all the 4 parts of the fetch-execute cycle.

QUIZ. Name all the 4 parts of the fetch-execute cycle. QUIZ Name all the 4 parts of the fetch-execute cycle. 1 Solution Name all the 4 parts of the fetch-execute cycle. 2 QUIZ Name two fundamental differences between magnetic drives and optical drives: 3 QUIZ

More information

Shift and Rotate Instructions

Shift and Rotate Instructions Shift and Rotate Instructions Shift and rotate instructions facilitate manipulations of data (that is, modifying part of a 32-bit data word). Such operations might include: Re-arrangement of bytes in a

More information

reply db y prompt db Enter your favourite colour:, 0 colour db 80 dup(?) i db 20 k db? num dw 4000 large dd 50000

reply db y prompt db Enter your favourite colour:, 0 colour db 80 dup(?) i db 20 k db? num dw 4000 large dd 50000 Declaring Variables in Assembly Language As in Java, variables must be declared before they can be used Unlike Java, we do not specify a variable type in the declaration in assembly language Instead we

More information

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College Assembly Language Programming CPSC 252 Computer Organization Ellen Walker, Hiram College Instruction Set Design Complex and powerful enough to enable any computation Simplicity of equipment MIPS Microprocessor

More information

QUIZ. Name all the 4 parts of the fetch-execute cycle.

QUIZ. Name all the 4 parts of the fetch-execute cycle. QUIZ Name all the 4 parts of the fetch-execute cycle. 1 Solution Name all the 4 parts of the fetch-execute cycle. 2 QUIZ Name two fundamental differences between magnetic drives and optical drives: 3 Solution

More information

ECE251: Tuesday September 11

ECE251: Tuesday September 11 ECE251: Tuesday September 11 Finish Branch related instructions Stack Subroutines Note: Lab 3 is a 2 week lab, starting this week and covers the Stack and Subroutines. Labs: Lab #2 is due this week. Lab

More information

Wednesday, February 4, Chapter 4

Wednesday, February 4, Chapter 4 Wednesday, February 4, 2015 Topics for today Introduction to Computer Systems Static overview Operation Cycle Introduction to Pep/8 Features of the system Operational cycle Program trace Categories of

More information

Monday, April 15, We will lead up to the Analysis and Synthesis algorithms involved by first looking at three simpler ones.

Monday, April 15, We will lead up to the Analysis and Synthesis algorithms involved by first looking at three simpler ones. Monday, pril 15, 2013 Topics for today Code generation nalysis lgorithm 1: evaluation of postfix lgorithm 2: infix to postfix lgorithm 3: evaluation of infix lgorithm 4: infix to tree Synthesis lgorithm

More information

143A: Principles of Operating Systems. Lecture 4: Calling conventions. Anton Burtsev October, 2017

143A: Principles of Operating Systems. Lecture 4: Calling conventions. Anton Burtsev October, 2017 143A: Principles of Operating Systems Lecture 4: Calling conventions Anton Burtsev October, 2017 Recap from last time Stack and procedure calls What is stack? Stack It's just a region of memory Pointed

More information

Understand Execution of a Program

Understand Execution of a Program Understand Execution of a Program Prof. Zhang September 17, 2014 1 Program in Memory When you execute a program, the program (i.e., executable code) is loaded into the memory (i.e., main memory, RAM) in

More information

Today. Putting it all together

Today. Putting it all together Today! One complete example To put together the snippets of assembly code we have seen! Functions in MIPS Slides adapted from Josep Torrellas, Craig Zilles, and Howard Huang Putting it all together! Count

More information

introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion

introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion Today s video will talk about an important concept in computer science which is

More information

Today's Topics. CISC 458 Winter J.R. Cordy

Today's Topics. CISC 458 Winter J.R. Cordy Today's Topics Last Time Semantics - the meaning of program structures Stack model of expression evaluation, the Expression Stack (ES) Stack model of automatic storage, the Run Stack (RS) Today Managing

More information

ECE251: Tuesday September 12

ECE251: Tuesday September 12 ECE251: Tuesday September 12 Finish Branch related instructions Stack Subroutines Note: Lab 3 is a 2 week lab, starting this week and covers the Stack and Subroutines. Labs: Lab #2 is due this week. Lab

More information

DEEPIKA KAMBOJ UNIT 2. What is Stack?

DEEPIKA KAMBOJ UNIT 2. What is Stack? What is Stack? UNIT 2 Stack is an important data structure which stores its elements in an ordered manner. You must have seen a pile of plates where one plate is placed on top of another. Now, when you

More information

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero Do-While Example In C++ do { z--; while (a == b); z = b; In assembly language loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero 25 Comparisons Set on less than (slt) compares its source registers

More information

Monday, October 26, 2015

Monday, October 26, 2015 Monday, October 26, 2015 Topics for today Indexed branching Implementation of switch statement Reusable subroutines Indexed branching It turns out that arrays are useful in translating other language constructs,

More information

Lecture 5: Procedure Calls

Lecture 5: Procedure Calls Lecture 5: Procedure Calls Today s topics: Procedure calls and register saving conventions 1 Example Convert to assembly: while (save[i] == k) i += 1; i and k are in $s3 and $s5 and base of array save[]

More information

Part 7. Stacks. Stack. Stack. Examples of Stacks. Stack Operation: Push. Piles of Data. The Stack

Part 7. Stacks. Stack. Stack. Examples of Stacks. Stack Operation: Push. Piles of Data. The Stack Part 7 Stacks The Stack Piles of Data Stack Stack A stack is an abstract data structure that stores objects Based on the concept of a stack of items like a stack of dishes Data can only be added to or

More information

just a ((somewhat) safer) dialect.

just a ((somewhat) safer) dialect. Intro_to_C Page 1 Intro to C Tuesday, September 07, 2004 5:30 PM C was developed specifically for writing operating systems Low level of abstraction. "Just above machine language." Direct access to the

More information

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11 CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11 CS 536 Spring 2015 1 Handling Overloaded Declarations Two approaches are popular: 1. Create a single symbol table

More information

Wednesday, November 4, 2009

Wednesday, November 4, 2009 Wednesday, November 4, 2009 Topics for today Storage management Main memory (1) Uniprogramming (2) Fixed-partition multiprogramming (3) Variable-partition multiprogramming (4) Paging (5) Virtual memory

More information

143A: Principles of Operating Systems. Lecture 5: Calling conventions. Anton Burtsev January, 2017

143A: Principles of Operating Systems. Lecture 5: Calling conventions. Anton Burtsev January, 2017 143A: Principles of Operating Systems Lecture 5: Calling conventions Anton Burtsev January, 2017 Stack and procedure calls Stack Main purpose: Store the return address for the current procedure Caller

More information

Provided by - Microsoft Placement Paper Technical 2012

Provided by   - Microsoft Placement Paper Technical 2012 Provided by www.yuvajobs.com - Microsoft Placement Paper Technical 2012 1. Analytical 25 questions ( 30 minutes) 2. Reasoning 25 questions (25 minutes) 3. Verbal 20 questions (20 minutes) Analytical (some

More information

238P: Operating Systems. Lecture 3: Calling conventions. Anton Burtsev October, 2018

238P: Operating Systems. Lecture 3: Calling conventions. Anton Burtsev October, 2018 238P: Operating Systems Lecture 3: Calling conventions Anton Burtsev October, 2018 What does CPU do internally? (Remember Lecture 01 - Introduction?) CPU execution loop CPU repeatedly reads instructions

More information

Lecture 10 Notes Linked Lists

Lecture 10 Notes Linked Lists Lecture 10 Notes Linked Lists 15-122: Principles of Imperative Computation (Spring 2016) Frank Pfenning, Rob Simmons, André Platzer 1 Introduction In this lecture we discuss the use of linked lists to

More information

Wednesday, October 4, Optimizing compilers source modification Optimizing compilers code generation Your program - miscellaneous

Wednesday, October 4, Optimizing compilers source modification Optimizing compilers code generation Your program - miscellaneous Wednesday, October 4, 2017 Topics for today Code improvement Optimizing compilers source modification Optimizing compilers code generation Your program - miscellaneous Optimization Michael Jackson Donald

More information

Monday, February 11, 2013

Monday, February 11, 2013 Monday, February 11, 2013 Topics for today The Pep/8 memory Four example programs The loader The assembly language level (Chapter 5) Symbolic Instructions Assembler directives Immediate mode and equate

More information

CS 2113 Software Engineering

CS 2113 Software Engineering CS 2113 Software Engineering Do this now!!! From C to Java git clone https://github.com/cs2113f18/c-to-java.git cd c-to-java./install_java Professor Tim Wood - The George Washington University We finished

More information

Extra-credit QUIZ Pipelining -due next time-

Extra-credit QUIZ Pipelining -due next time- QUIZ Pipelining A computer pipeline has 4 processors, as shown above. Each processor takes 15 ms to execute, and each instruction must go sequentially through all 4 processors. A program has 10 instructions.

More information

12/4/18. Outline. Implementing Subprograms. Semantics of a subroutine call. Storage of Information. Semantics of a subroutine return

12/4/18. Outline. Implementing Subprograms. Semantics of a subroutine call. Storage of Information. Semantics of a subroutine return Outline Implementing Subprograms In Text: Chapter 10 General semantics of calls and returns Implementing simple subroutines Call Stack Implementing subroutines with stackdynamic local variables Nested

More information

SPIM Procedure Calls

SPIM Procedure Calls SPIM Procedure Calls 22C:60 Jonathan Hall March 29, 2008 1 Motivation We would like to create procedures that are easy to use and easy to read. To this end we will discuss standard conventions as it relates

More information

UNIT-II. Part-2: CENTRAL PROCESSING UNIT

UNIT-II. Part-2: CENTRAL PROCESSING UNIT Page1 UNIT-II Part-2: CENTRAL PROCESSING UNIT Stack Organization Instruction Formats Addressing Modes Data Transfer And Manipulation Program Control Reduced Instruction Set Computer (RISC) Introduction:

More information

Ch. 11: References & the Copy-Constructor. - continued -

Ch. 11: References & the Copy-Constructor. - continued - Ch. 11: References & the Copy-Constructor - continued - const references When a reference is made const, it means that the object it refers cannot be changed through that reference - it may be changed

More information

This section provides some reminders and some terminology with which you might not be familiar.

This section provides some reminders and some terminology with which you might not be familiar. Chapter 3: Functions 3.1 Introduction The previous chapter assumed that all of your Bali code would be written inside a sole main function. But, as you have learned from previous programming courses, modularizing

More information

[2:3] Linked Lists, Stacks, Queues

[2:3] Linked Lists, Stacks, Queues [2:3] Linked Lists, Stacks, Queues Helpful Knowledge CS308 Abstract data structures vs concrete data types CS250 Memory management (stack) Pointers CS230 Modular Arithmetic !!!!! There s a lot of slides,

More information

Programming Language Concepts Scoping. Janyl Jumadinova January 31, 2017

Programming Language Concepts Scoping. Janyl Jumadinova January 31, 2017 Programming Language Concepts Scoping Janyl Jumadinova January 31, 2017 Scope Rules A scope is a program section of maximal size in which no bindings change, or at least in which no re-declarations are

More information

ECE232: Hardware Organization and Design

ECE232: Hardware Organization and Design ECE232: Hardware Organization and Design Lecture 6: Procedures Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Overview Procedures have different names in different languages Java:

More information

CSE Lecture In Class Example Handout

CSE Lecture In Class Example Handout CSE 30321 Lecture 07-09 In Class Example Handout Part A: A Simple, MIPS-based Procedure: Swap Procedure Example: Let s write the MIPS code for the following statement (and function call): if (A[i] > A

More information

Wednesday, September 6, 2017

Wednesday, September 6, 2017 Wednesday, September 6, 2017 Topics for today Arithmetic operations and status bits Logical operators Introduction to bigger bases Encoding characters Coding in general Status bits We saw last time that

More information

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305 Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n

More information

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)... Remembering numbers (and other stuff)... Let s talk about one of the most important things in any programming language. It s called a variable. Don t let the name scare you. What it does is really simple.

More information

Compilers and computer architecture: A realistic compiler to MIPS

Compilers and computer architecture: A realistic compiler to MIPS 1 / 1 Compilers and computer architecture: A realistic compiler to MIPS Martin Berger November 2017 Recall the function of compilers 2 / 1 3 / 1 Recall the structure of compilers Source program Lexical

More information

Function Calls. Tom Kelliher, CS 220. Oct. 24, SPIM programs due Wednesday. Refer to homework handout for what to turn in, and how.

Function Calls. Tom Kelliher, CS 220. Oct. 24, SPIM programs due Wednesday. Refer to homework handout for what to turn in, and how. Function Calls Tom Kelliher, CS 220 Oct. 24, 2011 1 Administrivia Announcements Assignment SPIM programs due Wednesday. Refer to homework handout for what to turn in, and how. From Last Time Outline 1.

More information