Monday, October 17, 2016
|
|
- Brian Ray
- 6 years ago
- Views:
Transcription
1 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 (Section 6.3) Passing parameters by reference: see Warford pp So far we have passed parameters by value, that is we have copied the current value of a parameter (either a constant or a variable, a local or a global) onto the stack. Many languages support "pass by reference" where the address of the actual parameter is put on the stack. (It follows that actual parameters passed by reference can only be the addresses of variables; constants and expressions are not allowed.) When a parameter is passed by reference, the subprogram is able to update the value in the parameter. Consider the C function increment void increment (int V, int *N) /* adds V to location pointed to by N */ *N += V; and a call increment (Quantity, &Total) The parameter Quantity is passed by value - we can use but cannot change it. The parameter Total is passed by reference - we are able to change the value in this variable. We can perhaps picture increment as follows V N increment We can read V. We can both read and write N. Comp 162 Notes Page 1 of 12 October 17, 2016
2 In the Pep/8 calling environment, the difference in the way the two parameters are passed is small and subtle. Here is a translation of the call increment(quantity, &Total) subsp 4,i lda Quantity,d ; the value in Quantity sta 0,s ; is one parameter lda Total,i ; the address of Total - note the addressing mode! sta 2,s ; is the other call increment On entry to the subroutine, the stack looks like Return address Value of Quantity Address of Total Total Question: Answer: If the stack contains the address of a variable, how do we access the contents of that variable either to read from it or to write to it? We use a new addressing mode stack relative deferred (symbol,sf) When we use mode,s the operand is Mem[SP+operand] When we use mode,sf the operand is Mem[Mem[SP+operand]] Note that, in theory, when the program runs, an instruction that uses the sf mode will take more time than an instruction that uses the s mode because an additional memory read is required. Here is a possible implementation of the "increment" function increment: lda 4,sf ; load A from the variable N to be updated adda 2,s ; increment by the value of V sta 4,sf ; store back the new value of N ret0 We could also use our new mode to implement a function that exchanges the contents of two variables passed by reference. It might be used as part of a sorting routine. In high-level language Comp 162 Notes Page 2 of 12 October 17, 2016
3 void exchange (int* P, int* Q) int temp; temp = *P; *P = *Q; *Q = temp; A call exchange(&x, &Y) swaps the values in variables X and Y. Here is an implementation of the exchange function in Pep/8: exchange: subsp 2,i ; for the local variable lda 4,sf ; first value sta 0,s ; is stored in local lda 6,sf ; second value sta 4,sf ; is copied to first lda 0,s ; now the value in local sta 6,sf ; is copied to second ret2 ; deallocate local and return Pictorially local Return address Local variables passed by reference: see Warford pp Warford's example (Fig 6.27) shows how to handle the case where parameters are already on the stack as a result of another call as in order (&X, &Y).. exchange(&x, &Y) we just copy the addresses from appropriate stack locations. Comp 162 Notes Page 3 of 12 October 17, 2016
4 But what happens when the variables (actual parameters) to be passed by reference are not global variables but are local variables in the calling environment as in int main() int N,P,Q,R;.. exchange(&p,&q); When we call exchange, the two values we pass to it are addresses of locations on the stack itself. So in setting up the call we need to establish pointers as in the following diagram N P Q R But we don't know where the stack is in memory! Luckily, in Pep/8 there is an instruction that makes setting up such pointers possible. The instruction MOVSPA copies the value in the stack pointer (i.e., the address of the top of the stack) to register A. Now we can figure out the addresses of the actual parameters and put pointers to those locations onto the stack using Register A to do the arithmetic. Figure 6.29 shows one example of this. Here is another. Assume our routine exchange defined above, consider the following Comp 162 Notes Page 4 of 12 October 17, 2016
5 int main() int A, B, C, D; input(b); input (C); exchange(&b,&c); output(b); output(c); In Pep/8 main is: main: subsp 8,i ; space for the 4 locals: A, B, C and D movspa ; remember address of top of stack (address of local A) deci 2,s ; input(b) deci 4,s ; input(c) subsp 4,i ; make room for the two parameters of exchange adda 2,i ; Register A now contains the address of B. sta 0,s ; this is the first parameter of exchange adda 2,i ; Register A now contains address of C sta 2,s ; this is the second parameter call exchange addsp 4,i ; get rid of exchange parameter space deco 2,s ; output B deco 4,s ; output C ret0 Pictorially, on entry to exchange the stack is Retn Address A B C D And the subroutine will exchange the values in locals B and C. Comp 162 Notes Page 5 of 12 October 17, 2016
6 More reverse Engineering: Pep/8 to C Here is another example of a subroutine to convert into C, this time with a parameter passed by reference. Line 1 unknown: lda 2,s 2 breq zercase 3 brgt poscase 4 lda 4,s 5 nega 6 sta 6,sf 7 br ret1 8 poscase: lda 4,s 9 sta 6,sf 10 ret1: lda 1,i 11 sta 8,s 12 ret0 13 zercase: sta 8,s 14 ret0 Again, we start with a skeleton of the C function?? unknown ( ) There are no local variables in this subroutine. The return address is therefore at 0,s. There are references to several stack locations below the return address (e.g.,. Lines 4, 9, and 11). The lowest of these on the stack (8,s) has a word stored in it before the function exits. This suggests a return value and that unknown is therefore an integer function: int unknown ( ) We assume that the three remaining locations (2,s 4,s and 6,s) are parameters. Two are read from (2,s and 4,s) and one is written to (6,sf). The addressing modes used to access the locations indicate that two are values and one is an address int unknown (int A, int B, int *C) There are no loops, only forward branches, so we can fill out the action of the subroutine Comp 162 Notes Page 6 of 12 October 17, 2016
7 int unknown (int A, int B, int *C) if (A==0) return 0; if (A >0) *C = B; return 1; *C = -B; return 1; which we can simplify to int unknown (int A, int B, int *C) if (A == 0) return 0; if (A > 0) *C = B; else *C = -B; return 1; Representation of Booleans: Warford p. 281 The last topic in section 6.3 is the representation and manipulation of Booleans. Q: how much space do we allocate for each bool? A: in theory only one bit is needed but manipulating individual bits is time-consuming and even a byte for each bool is slow because of the limited set of byte instructions that Pep/8 has so we will use a word for each bool. Q: what values to use for true and false? A: there are many possibilities including the five in the following table (i) (ii) (iii) (iv) (v) True Non-zero Negative Odd 1 FFFF16 False Zero Non-negative Even Option (i) is what C uses. Suppose variable A is type bool. Consider the translation into Pep/8 of the assignment A =!(A); /* invert A */ Comp 162 Notes Page 7 of 12 October 17, 2016
8 That is, we wish to change the value in A. For implementation methods (ii), (iii) and (v) the code is lda A,d nota sta A,d If we implement Booleans using method (iv) the code might be lda 1,i suba A,d sta A,d It turns out that the most complicated code is required if we choose implementation method (i) (the one that C uses). Here is a possible translation lda A,d breq iszero lda -1,i ; so that next lines makes it zero iszero: adda 1,i store: sta A,d To finish our look at Booleans we will see short circuit evaluation might be useful. Short-circuit evaluation Consider the following two fragments of if statements (i) if (A && B && C) action; (ii) if (P Q R) action; In the case of (i) a compiler could generate code that first checks A and if it is false, doesn't even evaluate B or C. Similarly in (ii) rather than figure out the whole Boolean expression then check it, the compiler could generate code that looks first at P and if it is true, does not even evaluate Q or R. This is short-circuit evaluation 1. (i) is if (A) if (B) if (C) action; (ii) is if (P) action else if (Q) action else if (R) action; 1 The default in C Comp 162 Notes Page 8 of 12 October 17, 2016
9 Short-circuit evaluation can be useful Example 1: a loop that scans N-element array AR looking for the first non-zero element i = 0; while (i<n && AR[i]==0) i++; If there are no non-zero elements than the value of i will reach N. However, if i is N then the first clause will be false and we will not try to access the non-existent element AR[N] and thus avoid a run-time error. Example 2: a check to see if the character pointed to by ptr is the newline character. if ( (ptr!=0 ) && ( *ptr == \n )) To avoid error that occurs when following a null (zero) pointer, check for that in the first clause. Example 3: similar to Example 2, this time to avoid a division by zero if ( count!=0 && sum/count > oldaverage). While short circuit code may be faster in some cases, in general it may take up more space and, on average, may be slower than full evaluation. Compare the following two implementations of if (A B C D)... assuming we use zero for false and non-zero for true. Regular lda A,d ora B,d ora C,d ora D,d brne true false:... Short-Circuit lda A,d brne true ora B,d brne true ora C,d brne true ora D,d brne true false:... Space: Regular uses 5 instructions and short-circuit uses 8. Run-time: Consider the number of instructions we execute in each case for various values of A, B, C, D. Comp 162 Notes Page 9 of 12 October 17, 2016
10 A B C D Regular Short-Circuit True 5 2 False True 5 4 False False True 5 6 False False False 5 8 So, because short circuit code may take up more space and run slower than regular code using the short-circuit approach should be a compiler option rather than imposed on a user. Reading We have reached the end of section 6.3. The next section looks at arrays and includes global arrays local arrays arrays used as parameters of subroutines. Each of these three uses of an array requires its own addressing mode. Review questions 1. If the MOVSPA instruction were not available, is there another way to find out the value in the SP register? 2. If in subroutine X the following are the only references to the stack below the Return Address, what is a plausible C-style prototype for X? ldbytea 4,sf ora 6,s sta 2,sf sta 8,s 3. If function ABC has prototype Void ABC (int X, int* Y, char* Z) Which of the following are valid calls of ABC (N and T are type int, C is type char) ABC ( 3+N, &N, & ) ABC ( N, N, * ) ABC (3, 26, C) ABC (40-N, &T, &C) Comp 162 Notes Page 10 of 12 October 17, 2016
11 4. If we used a single bit for each element of the array bool T[100] How could we determine the value of T[i]? 5. We are searching 1000-element array M for the last value equal to 99. Write a loop that does this assuming short-circuit evaluation to avoid an index-out-of-bounds error. Comp 162 Notes Page 11 of 12 October 17, 2016
12 Review answers 1. No. 2. int X ( int*, char*, int) 3. ABC (40-N, &T, &C) 4. T would occupy 13 bytes (half the last one is unused). The byte number we need is i/8. We could get that byte and isolate the bit of interest using an AND 5. i=999; while (i>0 and M[i]!=99) i--; Comp 162 Notes Page 12 of 12 October 17, 2016
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 informationMonday, 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 informationWednesday, 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 informationMonday, 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 informationMonday, 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 informationWednesday, 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 informationWednesday, 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 informationWednesday, 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 informationWednesday, September 27, 2017
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
More informationWednesday, 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 informationCSC 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 informationWednesday, 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 informationWednesday, 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 informationMonday, 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 informationMonday, 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 informationMonday, 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 informationMonday, 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 informationMonday, 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 informationWednesday, 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 informationWednesday, 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 informationWednesday, 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 informationWednesday, 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 informationMonday, 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 informationWednesday, 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 informationWednesday, 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 informationMonday, 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 informationWednesday, 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 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 informationWednesday, 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 informationLow-level software. Components Circuits Gates Transistors
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 informationn NOPn Unary no operation trap U aaa NOP Nonunary no operation trap i
Instruction set Instruction Mnemonic Instruction Addressing Status Specifier Mode Bits 0000 0000 STOP Stop execution U 0000 0001 RET Return from CALL U 0000 0010 RETTR Return from trap U 0000 0011 MOVSPA
More informationMonday, November 9, 2015
Monday, November 9, 2015 Topics for today Grammars and Languages (Chapter 7) Finite State Machines Semantic actions Code generation - Overview nalysis lgorithm 1: evaluation of postfix lgorithm 2: infix
More informationQUIZ. 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 informationMonday, April 14, 2014
Monday, April 14, 2014 Topics for today Grammars and Languages (Chapter 7) Finite State Machines Semantic actions Code generation - Overview Analysis Algorithm 1: evaluation of postfix Algorithm 2: infix
More informationQUIZ. 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 informationLecture 7: Examples, MARS, Arithmetic
Lecture 7: Examples, MARS, Arithmetic Today s topics: More examples MARS intro Numerical representations 1 Dealing with Characters Instructions are also provided to deal with byte-sized and half-word quantities:
More informationAlgorithms & Data Structures
GATE- 2016-17 Postal Correspondence 1 Algorithms & Data Structures Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key
More informationCS107 Handout 08 Spring 2007 April 9, 2007 The Ins and Outs of C Arrays
CS107 Handout 08 Spring 2007 April 9, 2007 The Ins and Outs of C Arrays C Arrays This handout was written by Nick Parlante and Julie Zelenski. As you recall, a C array is formed by laying out all the elements
More informationLecture 6: Assembly Programs
Lecture 6: Assembly Programs Today s topics: Procedures Examples Large constants The compilation process A full example 1 Procedures Local variables, AR, $fp, $sp Scratchpad and saves/restores, $fp Arguments
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationNumbers: positional notation. CS61C Machine Structures. Faux Midterm Review Jaein Jeong Cheng Tien Ee. www-inst.eecs.berkeley.
CS 61C Faux Midterm Review (1) CS61C Machine Structures Faux Midterm Review 2002-09-29 Jaein Jeong Cheng Tien Ee www-inst.eecs.berkeley.edu/~cs61c/ Numbers: positional notation Number Base B B symbols
More informationINITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS
INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS Pages 792 to 800 Anna Rakitianskaia, University of Pretoria INITIALISING POINTER VARIABLES Pointer variables are declared by putting
More informationLOW-LEVEL PROGRAMMING LANAGUAGES AND PSEUDOCODE. Introduction to Computer Engineering 2015 Spring by Euiseong Seo
LOW-LEVEL PROGRAMMING LANAGUAGES AND PSEUDOCODE Introduction to Computer Engineering 2015 Spring by Euiseong Seo Where are we? Chapter 1: The Big Picture Chapter 2: Binary Values and Number Systems Chapter
More informationC Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,
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 informationIn Java we have the keyword null, which is the value of an uninitialized reference type
+ More on Pointers + Null pointers In Java we have the keyword null, which is the value of an uninitialized reference type In C we sometimes use NULL, but its just a macro for the integer 0 Pointers are
More informationMonday, 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 informationBASIC ELEMENTS OF A COMPUTER PROGRAM
BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators
More informationPointers, Dynamic Data, and Reference Types
Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple
More informationPOINTERS - Pointer is a variable that holds a memory address of another variable of same type. - It supports dynamic allocation routines. - It can improve the efficiency of certain routines. C++ Memory
More informationA rubric for programming assignments
Fall 2012 Comp 162 Peter Smith A rubric for programming assignments Generally, half the points for a program assignment are for the Correctness of the program with respect to the specification. The other
More informationExtra-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 informationLecture Overview Code generation in milestone 2 o Code generation for array indexing o Some rational implementation Over Express Over o Creating
1 ecture Overview Code generation in milestone 2 o Code generation for array indexing o Some rational implementation Over Express Over o Creating records for arrays o Short-circuiting Or o If statement
More informationUnderstanding Pointers
Division of Mathematics and Computer Science Maryville College Pointers and Addresses Memory is organized into a big array. Every data item occupies one or more cells. A pointer stores an address. A pointer
More informationLecture 4: Outline. Arrays. I. Pointers II. III. Pointer arithmetic IV. Strings
Lecture 4: Outline I. Pointers A. Accessing data objects using pointers B. Type casting with pointers C. Difference with Java references D. Pointer pitfalls E. Use case II. Arrays A. Representation in
More informationUnder the Hood: Data Representations, Memory and Bit Operations. Computer Science 104 Lecture 3
Under the Hood: Data Representations, Memory and Bit Operations Computer Science 104 Lecture 3 Homework #1 Due Feb 6 Reading TAs Finish Chapter 1 Start Chapter 2 Admin +1 UTA: Michael Zhou Lindsay is Head
More informationChapter 3: Operators, Expressions and Type Conversion
101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To
More informationLecture Notes on Memory Layout
Lecture Notes on Memory Layout 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 11 1 Introduction In order to understand how programs work, we can consider the functions,
More informationCS261: HOMEWORK 2 Due 04/13/2012, at 2pm
CS261: HOMEWORK 2 Due 04/13/2012, at 2pm Submit six *.c files via the TEACH website: https://secure.engr.oregonstate.edu:8000/teach.php?type=want_auth 1. Introduction The purpose of HW2 is to help you
More informationOperators in C. Staff Incharge: S.Sasirekha
Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C
More informationWednesday, 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 informationBasic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition
Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.
More informationPointer Basics. Lecture 13 COP 3014 Spring March 28, 2018
Pointer Basics Lecture 13 COP 3014 Spring 2018 March 28, 2018 What is a Pointer? A pointer is a variable that stores a memory address. Pointers are used to store the addresses of other variables or memory
More informationECE 15B COMPUTER ORGANIZATION
ECE 15B COMPUTER ORGANIZATION Lecture 13 Strings, Lists & Stacks Announcements HW #3 Due next Friday, May 15 at 5:00 PM in HFH Project #2 Due May 29 at 5:00 PM Project #3 Assigned next Thursday, May 19
More informationreply 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 informationMemory Management: The process by which memory is shared, allocated, and released. Not applicable to cache memory.
Memory Management Page 1 Memory Management Wednesday, October 27, 2004 4:54 AM Memory Management: The process by which memory is shared, allocated, and released. Not applicable to cache memory. Two kinds
More informationLectures 13 & 14. memory management
Lectures 13 & 14 Linked lists and memory management Courtesy of Prof. Garcia (UCB) CS61C L05 Introduction to C (pt 3) (1) Review Pointers and arrays are virtually same C knows how to increment pointers
More informationmalloc(), calloc(), realloc(), and free()
1 next CITS2002 CITS2002 schedule Dynamic data structures Initially, we focused on scalar and array variables, whose size is known at compile-time. More recently, we've focused on arrays of values, whose
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 informationECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture
ECE468 Computer Organization & Architecture MIPS Instruction Set Architecture ECE468 Lec4.1 MIPS R2000 / R3000 Registers 32-bit machine --> Programmable storage 2^32 x bytes 31 x 32-bit GPRs (R0 = 0) 32
More informationCS201 Some Important Definitions
CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data
More informationPrinciples of Compiler Design
Principles of Compiler Design Code Generation Compiler Lexical Analysis Syntax Analysis Semantic Analysis Source Program Token stream Abstract Syntax tree Intermediate Code Code Generation Target Program
More information2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)
2.1 Unit 2 Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting) 2.2 Skills & Outcomes You should know and be able to apply the following skills with confidence Perform addition & subtraction
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting
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 informationJAVA OPERATORS GENERAL
JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators
More informationActually, C provides another type of variable which allows us to do just that. These are called dynamic variables.
When a program is run, memory space is immediately reserved for the variables defined in the program. This memory space is kept by the variables until the program terminates. These variables are called
More informationCS113: Lecture 5. Topics: Pointers. Pointers and Activation Records
CS113: Lecture 5 Topics: Pointers Pointers and Activation Records 1 From Last Time: A Useless Function #include void get_age( int age ); int age; get_age( age ); printf( "Your age is: %d\n",
More informationDECLARAING AND INITIALIZING POINTERS
DECLARAING AND INITIALIZING POINTERS Passing arguments Call by Address Introduction to Pointers Within the computer s memory, every stored data item occupies one or more contiguous memory cells (i.e.,
More informationSYSC 2006 C Winter 2012
SYSC 2006 C Winter 2012 Pointers and Arrays Copyright D. Bailey, Systems and Computer Engineering, Carleton University updated Sept. 21, 2011, Oct.18, 2011,Oct. 28, 2011, Feb. 25, 2011 Memory Organization
More informationCS61C : Machine Structures
inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #4 C Memory Management 2007-06-28 Scott Beamer, Instructor iphone Comes out Tomorrow CS61C L4 C Memory Management (1) www.apple.com/iphone
More informationIntroduction to Computer Science Midterm 3 Fall, Points
Introduction to Computer Science Fall, 2001 100 Points Notes 1. Tear off this sheet and use it to keep your answers covered at all times. 2. Turn the exam over and write your name next to the staple. Do
More informationCS201- Introduction to Programming Current Quizzes
CS201- Introduction to Programming Current Quizzes Q.1 char name [] = Hello World ; In the above statement, a memory of characters will be allocated 13 11 12 (Ans) Q.2 A function is a block of statements
More informationChapter. Assembly Language
Chapter 5 Assembly Language Mappings The mapping from Asmb5 to ISA3 is one-toone The mapping from HOL6 to Asmb5 is oneto-many Symbols Defined by an identifier followed by a colon at the start of a statement
More informationEE 361 University of Hawaii Fall
C functions Road Map Computation flow Implementation using MIPS instructions Useful new instructions Addressing modes Stack data structure 1 EE 361 University of Hawaii Implementation of C functions and
More informationLecture 8: Pointer Arithmetic (review) Endianness Functions and pointers
CSE 30: Computer Organization and Systems Programming Lecture 8: Pointer Arithmetic (review) Endianness Functions and pointers Diba Mirza University of California, San Diego 1 Q: Which of the assignment
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationLab 3. Pointers Programming Lab (Using C) XU Silei
Lab 3. Pointers Programming Lab (Using C) XU Silei slxu@cse.cuhk.edu.hk Outline What is Pointer Memory Address & Pointers How to use Pointers Pointers Assignments Call-by-Value & Call-by-Address Functions
More informationCOMP Primitive and Class Types. Yi Hong May 14, 2015
COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to
More informationTopic 2: C++ Programming fundamentals
Topic 2: C++ Programming fundamentals Learning Outcomes Upon successful completion of this topic you will be able to: describe basic elements of C++ programming language compile a program identify and
More informationCA31-1K DIS. Pointers. TA: You Lu
CA31-1K DIS Pointers TA: You Lu Pointers Recall that while we think of variables by their names like: int numbers; Computer likes to think of variables by their memory address: 0012FED4 A pointer is a
More informationLow-Level Programming Languages and Pseudocode
Chapter 6 Low-Level Programming Languages and Pseudocode Chapter Goals List the operations that a computer can perform Describe the important features of the Pep/8 virtual machine Distinguish between immediate
More informationToday s topics. MIPS operations and operands. MIPS arithmetic. CS/COE1541: Introduction to Computer Architecture. A Review of MIPS ISA.
Today s topics CS/COE1541: Introduction to Computer Architecture MIPS operations and operands MIPS registers Memory view Instruction encoding A Review of MIPS ISA Sangyeun Cho Arithmetic operations Logic
More informationPart 5,Assembly Language Questions
Part,Assembly Language Questions This study guide is provided as an aid in helping you to study for the ECE Department s 18-4, Fundamentals of Computer Engineering. The guide is a collection of previous
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationArrays, Pointers and Memory Management
Arrays, Pointers and Memory Management EECS 2031 Summer 2014 Przemyslaw Pawluk May 20, 2014 Answer to the question from last week strct->field Returns the value of field in the structure pointed to by
More informationEC 413 Computer Organization
EC 413 Computer Organization Program Compilation Process Prof. Michel A. Kinsy The Full View System Applica2ons So)ware Hardware Systems So)ware The Full View System Processor Applica2ons Compiler Firmware
More informationCS 61c: Great Ideas in Computer Architecture
Arrays, Strings, and Some More Pointers June 24, 2014 Review of Last Lecture C Basics Variables, functioss, control flow, types, structs Only 0 and NULL evaluate to false Pointers hold addresses Address
More informationC++ ARRAYS POINTERS POINTER ARITHMETIC. Problem Solving with Computers-I
C++ ARRAYS POINTERS POINTER ARITHMETIC Problem Solving with Computers-I General model of memory Sequence of adjacent cells Each cell has 1-byte stored in it Each cell has an address (memory location) Memory
More informationData Structure Series
Data Structure Series This series is actually something I started back when I was part of the Sweet.Oblivion staff, but then some things happened and I was no longer able to complete it. So now, after
More information