How can the machine ULg01 be programmed?
|
|
- Hannah McBride
- 6 years ago
- Views:
Transcription
1 Summary How can the machine ULg01 be programmed? 1. How can writing bits be avoided with the help of an assembly language. 2. How can high level languages be implemented on the β architecture? 3. What needs to be added to the machine ULg01 for it to able to run an operating system? A Universal Assembly Language A program for the β architecture Impossible to read; impossible to write (for humans). We need something else: ADD(r3,r4,r5) ST(r5,0x24,r16) For this to be possible, we need a program that can translate from a symbolic notation to a sequence of bits: an assembler. Rather than writing an assembler specific to the β architecture, we are going to define a few general mechanisms that make it possible to handle a wide variety of assembly languages. What the assembler produces is a sequence of bytes, for example 0x80 0x64 0x28 0x00 The input language for the assembler is a sequence of constant expressions, *0x14 O A constant prefixed with 0x is interpreted an hexadecimal value; prefixed with 0b it is interpreted as a binary value; and, without a prefix as a decimal value. We will now introduce a few mechanisms that will facilitate writing sequences of expressions
2 Assembly language mechanisms Definitions of the following form are allowed identifier = expression where an identifier is a string of letters and digits of arbitrary length starting with a letter. Once defined an identifier may appear in an expression. One can then write X = 128 X X-28 2*0x14 X-X A special identifier. is used to represent the position of the next byte to be added to the sequence being generated. Initially,. has value 0 ; The value of. can be modified, for example (read column by column) X = 128. =.+ 4 X X-28 2*0x14 X-X leaves a 4 byte space following the two first generated bytes. A position can be assigned to an identifier by writing This is equivalent to writing Example : identifier : identifier =. X:. =.+4 0xA6 reserves (for example for a variable) a 4 byte space at the position represented by the identifier X A call to a macro is written A powerful mechanism: macros Macros make it possible to define a parameterized program fragment that can be reused at will. The definition of a macro has the form.macro name(p1,...,pn) body where p1,...,pn are the (formal) parameters of the macro. There can be any number of them. The body of the macro is a program (a sequence of expressions) in which the formal parameters may appear. name(v1,...,vn) and is replaced by the body of the macro in which the formal parameters are replaced by the values of the expressions v1,...,vn. Parameters are evaluated once, when the macro is called. A macro generating four consecutive values can be defined by.macro consec(n) n n+1 n+2 n+3 and thus consec(6) is assembled into
3 Macros defining the β assembler Logical and Arithmetical instructions First some general useful macros..macro WORD(x) (x)%256 (x)/256 little endian.macro LONG(x) WORD(x) WORD((x) >> 16) Instruction coding macros.macro ENC_NOLIT(OP, Ra, Rb, Rc) LONG((OP<<26)+((Rc%32)<<21) +((Ra%32)<<16)+((Rb%32)<<11)).macro ENC_LIT(OP, Ra, Rc, Lit) LONG((OP<<26)+((Rc%32)<<21) +((Ra%32)<<16)+(Lit % 0x10000)).macro ENC_ADRLIT(OP, Ra, Rc, Label) ENC_LIT(OP, Ra, Rc, (label-(.+4))>>2) Assigning identifiers to registers r0 = 0x0... r31 = Ox11111.macro ADD(Ra,Rb,Rc).macro ADDC(Ra,Lit,Rc).macro SUB(Ra,Rb,Rc).macro SUBC(Ra,Lit,Rc).macro DIV(Ra,Rb,Rc).macro DIVC(Ra,Lit,Rc).macro MUL(Ra,Rb,Rc).macro MULC(Ra,Lit,Rc).macro CMPEQ(Ra,Rb,Rc).macro CMPEQC(Ra,Lit,Rc).macro CMPLE(Ra,Rb,Rc).macro CMPLEC(Ra,Lit,Rc).macro CMPLT(Ra,Rb,Rc).macro CMPLTC(Ra,Lit,Rc) ENC_NOLIT(0b100000,Ra,Rb,Rc) ENC_LIT(0b110000,Ra,Rc,Lit) ENC_NOLIT(0b100001,Ra,Rb,Rc) ENC_LIT(0b110001,Ra,Rc,Lit) ENC_NOLIT(0b100011,Ra,Rb,Rc) ENC_LIT(0b110011,Ra,Rc,Lit) ENC_NOLIT(0b100010,Ra,Rb,Rc) ENC_LIT(0b110010,Ra,Rc,Lit) ENC_NOLIT(0b100100,Ra,Rb,Rc) ENC_LIT(0b110100,Ra,Rc,Lit) ENC_NOLIT(0b100110,Ra,Rb,Rc) ENC_LIT(0b110110,Ra,Rc,Lit) ENC_NOLIT(0b100101,Ra,Rb,Rc) ENC_LIT(0b110101,Ra,Rc,Lit) macro AND(Ra,Rb,Rc) ENC_NOLIT(0b101000,Ra,Rb,Rc) Memory access instructions.macro ANDC(Ra,Lit,Rc) ENC_LIT(0b111000,Ra,Rc,Lit).macro OR(Ra,Rb,Rc) ENC_NOLIT(0b101001,Ra,Rb,Rc).macro LD(Ra,Lit,Rc) ENC_LIT(0b011000,Ra,Rc,Lit).macro ORC(Ra,Lit,Rc) ENC_LIT(0b111001,Ra,Rc,Lit).macro LDR(label,Rc) ENC_ADRLIT(0b011111,0,Rc,label).macro XOR(Ra,Rb,Rc) ENC_NOLIT(0b101010,Ra,Rb,Rc).macro ST(Rc,Lit,Ra) ENC_LIT(0b011001,Ra,Rc,Lit).macro XORC(Ra,Lit,Rc) ENC_LIT(0b111010,Ra,Rc,Lit) Branch instructions.macro SHR(Ra,Rb,Rc) ENC_NOLIT(0b101101,Ra,Rb,Rc).macro SHRC(Ra,Lit,Rc).macro SHL(Ra,Rb,Rc).macro SHLC(Ra,Lit,Rc).macro SRA(Ra,Rb,Rc).macro SRAC(Ra,Lit,Rc) ENC_LIT(0b111101,Ra,Rc,Lit) ENC_NOLIT(0b101100,Ra,Rb,Rc) ENC_LIT(0b111100,Ra,Rc,Lit) ENC_NOLIT(0b101110,Ra,Rb,Rc) ENC_LIT(0b111110,Ra,Rc,Lit).macro BNE(Ra,label,Rc).macro BT(Ra,label,Rc).macro BEQ(Ra,label,Rc).macro BF(Ra,label,Rc).macro JMP(Ra,Rc) ENC_ADRLIT(0b011110,Ra,Rc,label) BNE(Ra,label,Rc) ENC_ADRLIT(0b011101,Ra,Rc,label) BEQ(Ra,label,Rc) ENC_LIT(0b011011,Ra,Rc,0) 46 47
4 A program written in β assembler Examples Defining new instructions with macros.include macros LDR(input,r0) BR(bitrev) input: LONG(0x12345) Loading the macros data in r0.macro MOVE(Ra,Rc) ADD(Ra,r31,Rc) R[Rc] <- R[Ra].macro CMOVE(C,Rc) ADDC(r31,C,Rc) R[Rc] <- C.macro NOP().macro BR(label) ADDC(r31,r31,r31) do nothing BEQ(r31,label,r31) bitrev: CMOVE(32,r2) CMOVE(O,r1) loop: ANDC(r0,1,r3) SHLC(r1,1,r1) OR(r3,r1,r1) SHRC(r0,1,r0) SUBC(r2,1,r2) BNE(r2,loop) 32 bits to process result register first bit to r3 transfer it to r1 prepare following bit decrement number of bits to process loop if not done The β architecture and high-level languages We will see how the concepts used in high-level languages, in particular, procedure calls, can be implemented in the β architecture. Let us look at an example. int fact(int n) { if (n>0) return n*fact(n-1); else return 1; } To handle procedures solutions to the following problems are needed: 1. passing the value of the arguments to the procedure, 2. making it possible for the procedure to use local variables, 3. allowing the procedure to return a value, 4. allowing the procedure to call other procedures, including itself (recursion). fact(4); 50 51
5 Saving the return address Managing a stack in the β architecture To save the return address, it is natural to use a register. Register r28 (Linkage Pointer, LP) will be reserved for this purpose. A stack is a very useful concept for handling procedures as well as other programming problems. A procedure can thus be called with the instruction BR(label,LP). A stack is an area of memory in which only the most recently added element can be accessed directly. And returning from a procedure is done with JMP(LP,r31). But, how can one handle arguments and recursion? We will implement a stack as a sequence of memory words and we will use a dedicated register (SP = r29) as Stack Pointer Handling procedures using a stack Adding or removing an element of the stack can thus be done with the following instructions. Arguments are placed on the stack before calling the procedure..macro PUSH(Ra).macro POP(Ra) ADDC(SP,4,SP) ST(Ra,-4,SP) LD(SP,-4,Ra) ADDC(SP,-4,SP) The procedure uses the stack area beyond the arguments for its own needs. Reserving space on the stack is done as follows..macro ALLOCATE(k) ADDC(SP,4*k,SP).macro DEALLOCATE(k) SUBC(SP,4*k,SP) The stack area used by a procedure is called its frame. It is useful to have a pointer that lets us know where this frame starts (Base of frame Pointer, BP = r27). To allow recursion, LP and BP are saved on the stack at each procedure call
6 General stack organisation Implementing procedure calls In the calling procedure BP: SP: Arguments Saved LP Saved BP Local variables Unused PUSH(argn) arguments are placed in reverse... order PUSH(arg1) BR(f,LP) DEALLOCATE(n) At the beginning of the called procedure f: PUSH(LP) PUSH(BP) MOVE(SP,BP) ALLOCATE(space) allocate local space (save other registers if needed) at the end of the called procedure Local variable arg n... arg 1 Caller s frame Called procedure s frame (restore saved registers) MOVE(val,r0) the returned value is placed in r0 MOVE(BP,SP) restore the caller s SP POP(BP) restore the caller s BP POP(LP) restore the return address JMP(LP,R31) return BP: SP: Saved LP Saved BP local var local var. n unused 58 59
7 An implementation of the factorial function Accessing local variables To access the i-th local variable, one uses LD(BP,(i-1)*4,rx) ST(rx,(i-1)*4,BP) fact: PUSH(LP) save the return address PUSH(BP) save the previous frame MOVE(SP,BP) initialise the current frame PUSH(r1) r1 will be used, save it LD(BP,-12,r1) load the argument n in r1 BNE(r1,big) compare n to 0 ADDC(r31,1,r0) n=0, return 1 BR(rtn) go to return sequence To access the j-th argument, one uses LD(BP,-4*(j+2),rx) ST(rx,-4*(j+2),BP) big: SUBC(r1,1,r1) PUSH(r1) BR(fact,LP) DEALLOCATE(1) LD(BP,-12,r1) MUL(r1,r0,r0) compute n-1 in r1 place argument on stack recursive callm free area used for arguments load n in r1 n*fact(n-1) in r Non local variables The technique used so far does not handle non local variables. rtn: POP(r1) MOVE(BP,SP) POP(BP) POP(LP) JMP(LP,r31) restore r1 restore SP restore BP restore the return address return For this, one uses static links. A static link points from the current stack frame to the stack frame of the procedure in which the current procedure was (lexically) defined. One then accesses a non local variable by going up through static links the required number of times and then accessing a local variable
Procedures & Stacks Worksheet
Procedures & Stacks Worksheet PUSH(X): Push Reg[x] onto stack ADDC(SP,4,SP) ST(Rx,-4,SP) POP(X): Pop value at top of stack into Reg[x] LD(SP,-4,RX) SUBC(SP,4,SP) ALLOCATE(k): Reserve k words of stack ADDC(SP,4*k,SP)
More informationHow Computers Work Lecture 2. Assembly Tools Calling Conventions. Review: β Model of Computation Processor State
How Computers Work Lecture 2 Assembly Tools Calling Conventions How Computers Work Lecture 2 Page 1 PC r0 r1 r2 Review: β Model of Computation Processor State Instruction Memory 32 bits (4 bytes) Fetch/Execute
More information10. Assembly Language, Models of Computation
10. Assembly Language, Models of Computation 6.004x Computation Structures Part 2 Computer Architecture Copyright 2015 MIT EECS 6.004 Computation Structures L10: Assembly Language, Models of Computation,
More information6.004 Computation Structures Spring 2009
MIT OpenCourseWare http://ocw.mit.edu 6.004 Computation Structures Spring 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Machine Language, Assemblers,
More informationM A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE
M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE 6.004 Computation Structures Lab #5B Note: This lab has two parts, 5A and 5B.
More informationStacks and procedures
Page 1 of 20 Stacks and procedures indicates problems that have been selected for discussion in section, time permitting. Problem 1. Consider the following implementation of an algorithm for finding the
More information6.004 Computation Structures Spring 2009
MIT OpenCourseWare http://ocw.mit.edu 6.004 Computation Structures Spring 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. M A S S A C H U S E T T
More information6.004 Computation Structures Spring 2009
MIT OpenCourseWare http://ocw.mit.edu 6.004 Computation Structures Spring 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. M A S S A C H U S E T T
More informationindicates problems that have been selected for discussion in section, time permitting.
Page 1 of 12 Machine language indicates problems that have been selected for discussion in section, time permitting. Problem 1. Hand-compile the following C fragments into Beta assembly language. You can
More informationFunctions 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 informationMIPS Procedure Calls. Lecture 6 CS301
MIPS Procedure Calls Lecture 6 CS301 Function Call Steps Place parameters in accessible location Transfer control to function Acquire storage for procedure variables Perform calculations in function Place
More informationCourse Administration
Fall 2018 EE 3613: Computer Organization Chapter 2: Instruction Set Architecture Introduction 4/4 Avinash Karanth Department of Electrical Engineering & Computer Science Ohio University, Athens, Ohio 45701
More informationLecture 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 informationToday. 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 informationDesigning an Instruction Set
Designing an Instruction Set Lab 4 due today NEXT TUESDAY, /22! 6.4 Fall 22 /7/ L2 Instruction Set Let s Build a Simple Computer Data path for computing N*(N-) N A SEL B SEL A LE L.E. A B LE L.E. B * -
More informationCS356: 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 informationECE260: Fundamentals of Computer Engineering
Supporting Nested Procedures James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania Based on Computer Organization and Design, 5th Edition by Patterson & Hennessy Memory Layout
More informationMemory Usage 0x7fffffff. stack. dynamic data. static data 0x Code Reserved 0x x A software convention
Subroutines Why we use subroutines more modular program (small routines, outside data passed in) more readable, easier to debug code reuse i.e. smaller code space Memory Usage A software convention stack
More information6.004 Computation Structures Spring 2009
MIT OpenCourseWare http://ocw.mit.edu 6.4 Computation Structures Spring 29 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Designing an Instruction Set
More informationCS64 Week 5 Lecture 1. Kyle Dewey
CS64 Week 5 Lecture 1 Kyle Dewey Overview More branches in MIPS Memory in MIPS MIPS Calling Convention More Branches in MIPS else_if.asm nested_if.asm nested_else_if.asm Memory in MIPS Accessing Memory
More informationInstruction Set Architecture
Computer Architecture Instruction Set Architecture Lynn Choi Korea University Machine Language Programming language High-level programming languages Procedural languages: C, PASCAL, FORTRAN Object-oriented
More informationAnnouncements. Class 7: Intro to SRC Simulator Procedure Calls HLL -> Assembly. Agenda. SRC Procedure Calls. SRC Memory Layout. High Level Program
Fall 2006 CS333: Computer Architecture University of Virginia Computer Science Michele Co Announcements Class 7: Intro to SRC Simulator Procedure Calls HLL -> Assembly Homework #2 Due next Wednesday, Sept.
More informationTopic 7: Activation Records
Topic 7: Activation Records Compiler Design Prof. Hanjun Kim CoreLab (Compiler Research Lab) POSTECH 1 Storage Organization Stack Free Memory Heap Static Code 2 ELF file format example Executable Object
More informationCS153: Compilers Lecture 8: Compiling Calls
CS153: Compilers Lecture 8: Compiling Calls Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 2 out Due Thu Oct 4 (7 days) Project 3 out Due Tuesday Oct 9 (12 days) Reminder:
More informationMIPS 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 informationData Structure Layout. In HERA/Assembly
Data Structure Layout In HERA/Assembly Today, we re going to build some data structures in HERA First, a note on memory Registers are very fast RAM is relatively slow We use a cache to sit between them
More informationSubroutines. 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 informationEN164: Design of Computing Systems Lecture 11: Processor / ISA 4
EN164: Design of Computing Systems Lecture 11: Processor / ISA 4 Professor Sherief Reda http://scale.engin.brown.edu Electrical Sciences and Computer Engineering School of Engineering Brown University
More informationRun-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 informationThe plot thickens. Some MIPS instructions you can write cannot be translated to a 32-bit number
The plot thickens Some MIPS instructions you can write cannot be translated to a 32-bit number some reasons why 1) constants are too big 2) relative addresses are too big 3) absolute addresses are outside
More informationMachine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine
Machine Language Instructions Introduction Instructions Words of a language understood by machine Instruction set Vocabulary of the machine Current goal: to relate a high level language to instruction
More informationProcedures and Stacks
Procedures and Stacks Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. March 15, 2018 L10-1 Announcements Schedule has shifted due to snow day Quiz 2 is now on Thu 4/12 (one week later)
More informationFunctions and Procedures
Functions and Procedures Function or Procedure A separate piece of code Possibly separately compiled Located at some address in the memory used for code, away from main and other functions (main is itself
More informationLectures 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 informationThe plot thickens. Some MIPS instructions you can write cannot be translated to a 32-bit number
The plot thickens Some MIPS instructions you can write cannot be translated to a 32-bit number some reasons why 1) constants are too big 2) relative addresses are too big 3) absolute addresses are outside
More informationDesigning an Instruction Set
Designing an Instruction Set Nerd Chef at work. move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer... WARD & HALSTEAD 6.004 NERD KIT Handouts: Lecture Slides, β docs L12 Instruction
More information17. Virtualizing the Processor
17. Virtualizing the Processor 6.004x Computation Structures Part 3 Computer Organization Copyright 2016 MIT EECS 6.004 Computation Structures L17: Virtualizing the Processor, Slide #1 Recap: Virtual Memory
More informationLecture V Toy Hardware and Operating System
2. THE Machine Lecture V Page 1 Lecture V Toy Hardware and Operating System 1. Introduction For use in our OS projects, we introduce THE Machine where THE is an acronym 1 for Toy HardwarE. We also introduce
More informationCOMP 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 informationindicates problems that have been selected for discussion in section, time permitting.
Page 1 of 11 Building the Beta indicates problems that have been selected for discussion in section, time permitting. Problem 1. Beta quickies: A. In an unpipelined Beta implementation, when is the signal
More informationCompiling Code, Procedures and Stacks
Compiling Code, Procedures and Stacks L03-1 RISC-V Recap Computational Instructions executed by ALU Register-Register: op dest, src1, src2 Register-Immediate: op dest, src1, const Control flow instructions
More informationProblem with Scanning an Infix Expression
Operator Notation Consider the infix expression (X Y) + (W U), with parentheses added to make the evaluation order perfectly obvious. This is an arithmetic expression written in standard form, called infix
More informationProgramming the ARM. Computer Design 2002, Lecture 4. Robert Mullins
Programming the ARM Computer Design 2002, Lecture 4 Robert Mullins 2 Quick Recap The Control Flow Model Ordered list of instructions, fetch/execute, PC Instruction Set Architectures Types of internal storage
More informationImplementing 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 informationInstruction 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 informationCSE Lecture In Class Example Handout
CSE 30321 Lecture 07-08 In Class Example Handout Part A: J-Type Example: If you look in your book at the syntax for j (an unconditional jump instruction), you see something like: e.g. j addr would seemingly
More informationCode Generation. The Main Idea of Today s Lecture. We can emit stack-machine-style code for expressions via recursion. Lecture Outline.
The Main Idea of Today s Lecture Code Generation We can emit stack-machine-style code for expressions via recursion (We will use MIPS assembly as our target language) 2 Lecture Outline What are stack machines?
More informationWe can emit stack-machine-style code for expressions via recursion
Code Generation The Main Idea of Today s Lecture We can emit stack-machine-style code for expressions via recursion (We will use MIPS assembly as our target language) 2 Lecture Outline What are stack machines?
More informationMIPS Functions and Instruction Formats
MIPS Functions and Instruction Formats 1 The Contract: The MIPS Calling Convention You write functions, your compiler writes functions, other compilers write functions And all your functions call other
More informationProgramming Languages
Programming Languages Tevfik Koşar Lecture - VIII February 9 th, 2006 1 Roadmap Allocation techniques Static Allocation Stack-based Allocation Heap-based Allocation Scope Rules Static Scopes Dynamic Scopes
More informationProcedure Calls Main Procedure. MIPS Calling Convention. MIPS-specific info. Procedure Calls. MIPS-specific info who cares? Chapter 2.7 Appendix A.
MIPS Calling Convention Chapter 2.7 Appendix A.6 Procedure Calls Main Procedure Call Procedure Call Procedure Procedure Calls Procedure must from any call Procedure uses that main was using We need a convention
More informationImplementing 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 informationIMPORTANT QUESTIONS IN C FOR THE INTERVIEW
IMPORTANT QUESTIONS IN C FOR THE INTERVIEW 1. What is a header file? Header file is a simple text file which contains prototypes of all in-built functions, predefined variables and symbolic constants.
More informationLecture 5: Procedure Calls
Lecture 5: Procedure Calls Today s topics: Memory layout, numbers, control instructions Procedure calls 1 Memory Organization The space allocated on stack by a procedure is termed the activation record
More informationMark Redekopp, All rights reserved. EE 352 Unit 6. Stack Frames Recursive Routines
EE 352 Unit 6 Stack Frames Recursive Routines Arguments and Return Values MIPS convention is to use certain registers for this task $a0 - $a3 used to pass up to 4 arguments. If more arguments, use the
More informationECE 473 Computer Architecture and Organization Lab 4: MIPS Assembly Programming Due: Wednesday, Oct. 19, 2011 (30 points)
ECE 473 Computer Architecture and Organization Lab 4: MIPS Assembly Programming Due: Wednesday, Oct. 19, 2011 (30 points) Objectives: Get familiar with MIPS instructions Assemble, execute and debug MIPS
More informationManaging the memory used by a process
Virtual memory 99 Managing the memory used by a process A process needs memory for The executable code, The stack, If needed, other large amounts of data. The amount of memory needed by a process is not
More informationCPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e
CPSC 213 Introduction to Computer Systems Unit 1e Procedures and the Stack Readings for Next 3 Lectures Textbook Procedures - 3.7 Out-of-Bounds Memory References and Buffer Overflow - 3.12 Local Variables
More informationCalling Conventions. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See P&H 2.8 and 2.12
Calling Conventions Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H 2.8 and 2.12 Goals for Today Calling Convention for Procedure Calls Enable code to be reused by allowing
More information2. ADDRESSING METHODS
2 Addressing Methods STUDY MATERIALS ON COMPUTER ORGANIZATION (As per the curriculum of Third semester BSc Electronics of Mahatma Gandh Uniiversity) Compiled by Sam Kollannore U Lecturer in Electronics
More informationCPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e Feb 11, 13, 15, and 25. Winter Session 2018, Term 2
CPSC 213 Introduction to Computer Systems Winter Session 2018, Term 2 Unit 1e Feb 11, 13, 15, and 25 Procedures and the Stack Overview Reading Companion: 2.8 Textbook: 3.7, 3.12 Learning Goals explain
More informationCS 2630 Computer Organization. Meeting 10/11: data structures in MIPS Brandon Myers University of Iowa
CS 2630 Computer Organization Meeting 10/11: data structures in MIPS Brandon Myers University of Iowa Where we are going Compiler Instruction set architecture (e.g., MIPS) translating source code (C or
More informationStacks and Procedures
Stacks and Procedures I forgot, am I the Caller or Callee? Don t know. But, if you PUSH again I m gonna POP you. Support for High-Level Language constructs are an integral part of modern computer organization.
More informationCA Compiler Construction
CA4003 - Compiler Construction David Sinclair When procedure A calls procedure B, we name procedure A the caller and procedure B the callee. A Runtime Environment, also called an Activation Record, is
More informationDeclaring Pointers. Declaration of pointers <type> *variable <type> *variable = initial-value Examples:
1 Programming in C Pointer Variable A variable that stores a memory address Allows C programs to simulate call-by-reference Allows a programmer to create and manipulate dynamic data structures Must be
More informationData Transfer Instructions
Data Transfer Instructions (Credit: Hui Wu/COMP2121 Lecture Notes) Load Direct (ld): ld Rd, v Rd {r0, r1,..., r31} and v {x, x+, -x, y, y+, -y, z, z+, -z} (remember the X, Y, Z pointers) Load Program Memory
More informationEE 3170 Microcontroller Applications
EE 3170 Microcontroller Applications Lecture 12: Advanced Assembly Language Programming Part II- Stacks Calling Conventions & Base Pointer Usage & Subroutine Examples - Miller 5.5-5.7 Based on slides for
More informationCOMP26120: Pointers in C (2018/19) Lucas Cordeiro
COMP26120: Pointers in C (2018/19) Lucas Cordeiro lucas.cordeiro@manchester.ac.uk Organisation Lucas Cordeiro (Senior Lecturer, FM Group) lucas.cordeiro@manchester.ac.uk Office: 2.44 Office hours: 10-11
More informationLAB A Translating Data to Binary
LAB A Translating Data to Binary Create a directory for this lab and perform in it the following groups of tasks: LabA1.java 1. Write the Java app LabA1 that takes an int via a command-line argument args[0]
More informationFunctional Programming. Pure Functional Programming
Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).
More informationDo-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 informationCSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:
Expression evaluation CSE 504 Order of evaluation For the abstract syntax tree + + 5 Expression Evaluation, Runtime Environments + + x 3 2 4 the equivalent expression is (x + 3) + (2 + 4) + 5 1 2 (. Contd
More informationStacks and Procedures
Stacks and Procedures I forgot, am I the Caller or Callee? Don t know. But, if you PUSH again I m gonna POP you. Support for High-Level Language constructs are an integral part of modern computer organization.
More informationComputer Architecture. Chapter 2-2. Instructions: Language of the Computer
Computer Architecture Chapter 2-2 Instructions: Language of the Computer 1 Procedures A major program structuring mechanism Calling & returning from a procedure requires a protocol. The protocol is a sequence
More informationFORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):
FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): 1. If a function has default arguments, they can be located anywhere
More informationCSc 520 Principles of Programming Languages. Questions. rocedures as Control Abstractions... 30: Procedures Introduction
Procedures as Control Abstractions CSc 520 Principles of Programming Languages 30: Procedures Introduction Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona
More informationProf. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University. See P&H 2.8 and 2.12, and A.
Prof. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University See P&H 2.8 and 2.12, and A.5 6 compute jump/branch targets memory PC +4 new pc Instruction Fetch
More informationChapter 10. Implementing Subprograms ISBN
Chapter 10 Implementing Subprograms ISBN 0-321-33025-0 Chapter 10 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack-Dynamic Local Variables
More informationImplementing Subprograms
1 Implementing Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University CS315 Programming Languages Pinar Duygulu The General Semantics of Calls and Returns 2 The subprogram call and return
More informationAssembly Programming (III)
Assembly Programming (III) Lecturer: Annie Guo S2, 2006 COMP9032 Week6 1 Lecture Overview Stack and stack operations Functions and function calls Calling conventions S2, 2006 COMP9032 Week6 2 What is stack?
More informationChapter 2A Instructions: Language of the Computer
Chapter 2A Instructions: Language of the Computer Copyright 2009 Elsevier, Inc. All rights reserved. Instruction Set The repertoire of instructions of a computer Different computers have different instruction
More information1. Number Conversions [8 marks]
1. Number Conversions [8 marks] a. convert the decimal number 42 to a 16-bit signed integer in binary 0b0000 0000 0010 1010 b. convert the 8-bit number 0x42 to a 16-bit signed integer in binary 0b0000
More informationAssembly Programming (III) Lecturer: Sri Parameswaran Notes by: Annie Guo Dr. Hui Wu
Assembly Programming (III) Lecturer: Sri Parameswaran Notes by: Annie Guo Dr. Hui Wu 1 Lecture overview Stack and stack operations Functions and function calls Calling conventions 2 Stack What is stack?
More informationReview of Activation Frames. FP of caller Y X Return value A B C
Review of Activation Frames In general, activation frames are organized like this: HI LO Bookkeeping/preserved registers I/O parameters Locals and temps RA of caller FP of caller Y X Return value A B C
More informationBinary Representation. Decimal Representation. Hexadecimal Representation. Binary to Hexadecimal
Decimal Representation Binary Representation Can interpret decimal number 4705 as: 4 10 3 + 7 10 2 + 0 10 1 + 5 10 0 The base or radix is 10 Digits 0 9 Place values: 1000 100 10 1 10 3 10 2 10 1 10 0 Write
More informationDecimal Representation
Decimal Representation Can interpret decimal number 4705 as: 4 10 3 + 7 10 2 + 0 10 1 + 5 10 0 The base or radix is 10 Digits 0 9 Place values: 1000 100 10 1 10 3 10 2 10 1 10 0 Write number as 4705 10
More informationCENG 450: Instruction Set (16-bit)
CENG 450: Instruction Set (16-bit) In this lab, you will design and implement a pipelined 16-bit processor on FPGA. The instructions set of the processor is as follows: Instructions Set We use a RISC-like
More informationSubprograms, 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 informationTopic 3-a. Calling Convention 2/29/2008 1
Topic 3-a Calling Convention 2/29/2008 1 Calling Convention Calling convention is a standardized method for a program to pass parameters to a procedure and receive result values back from it. 2/29/2008
More informationCPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e
CPSC 213 Introduction to Computer Systems Unit 1e Procedures and the Stack 1 Readings for Next 3 Lectures Textbook Procedures - 3.7 Out-of-Bounds Memory References and Buffer Overflow - 3.12 2 Local Variables
More informationCS 61c: Great Ideas in Computer Architecture
MIPS Instruction Formats July 2, 2014 Review New registers: $a0-$a3, $v0-$v1, $ra, $sp New instructions: slt, la, li, jal, jr Saved registers: $s0-$s7, $sp, $ra Volatile registers: $t0-$t9, $v0-$v1, $a0-$a3
More informationInformatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Puntatori Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 5, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction to C October
More informationWe cover recursion in 150. Why do it again in 151?
Recursion We cover recursion in 150. Why do it again in 151? First, good solutions to problems are often recursive. Here is a quick way to sort a list of objects: split the list in half, recursively sort
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a
More informationControl Abstraction. Hwansoo Han
Control Abstraction Hwansoo Han Review of Static Allocation Static allocation strategies Code Global variables Own variables (live within an encapsulation - static in C) Explicit constants (including strings,
More informationMIPS Functions and the Runtime Stack
MIPS Functions and the Runtime Stack COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals Presentation Outline
More informationMechanisms in Procedures. CS429: Computer Organization and Architecture. x86-64 Stack. x86-64 Stack Pushing
CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: February 28, 2018 at 06:32 Mechanisms in Procedures Passing Control
More informationCPS311 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 informationProblem maximum score 1 35pts 2 22pts 3 23pts 4 15pts Total 95pts
University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Sciences CS61c Summer 2001 Woojin Yu Midterm Exam This is a closed-book exam. No calculators
More informationCSE 504: Compiler Design. Runtime Environments
Runtime Environments Pradipta De pradipta.de@sunykorea.ac.kr Current Topic Procedure Abstractions Mechanisms to manage procedures and procedure calls from compiler s perspective Runtime Environment Choices
More information