Wednesday, October 17, 2012
|
|
- Magdalene Foster
- 6 years ago
- Views:
Transcription
1 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 of functions We need to be able to translate functions that have arrays as parameters. This is not such a big leap because we already know how to pass scalars by reference and we can think of a scalar as being an array of size 1. When we pass an array as parameter we pass its address on the stack. Separately, we typically have to pass its size (or at least the number of elements we need to process). This is what we have to do in most high-level languages also. For example, here is a C function for adding up the first N elements of an array. int sum (int V[], int N) { int j,temp = 0; for (j=0; j<n; j++) temp += V[j]; } return temp; If we have int T[320]; global array then the following are typical calls of sum total = sum(t,60); // address of array and number of elements to process all = sum(t,320); first = sum(t,1); Comp 162 Notes Page 1 of 14 October 17, 2012
2 Here is the call sum(t,60) in Pep/8 subsp 2,i ; for returned value subsp 4,i ; for parameters; lda T,i ; address of array sta 0,s ; is the first parameter lda 60,i ; count of elements sta 2,s ; is the second parameter call sum After sum creates space for local variables j and temp, the stack looks like j temp Return Address For return value To access the elements of the array parameter combines two ideas we have already seen - deferred addressing (we saw this when looking at "pass by reference") and indexing (we saw this when accessing global arrays). The body of our function is for (j=0; j<n; j++) temp += V[j]; The assignment to temp translates to ldx 0,s ; the local variable j in index register lda 2,s ; temp in Reg. A aslx ; index converted to byte offset adda 6,sxf ; add V[j] sta 2,s ; update temp The new mode (,sxf) is stack-indexed deferred. The operand is memory[ memory [operand + SP] + register X ] Comp 162 Notes Page 2 of 14 October 17, 2012
3 It is used when the stack contains a pointer to an array. The operand indicates how far down the stack the pointer to the array is. The contents of Register X are used (as usual) to index within the array. Thus in the case of adda 6,sxf We are accessing the array that is pointed to from the word 6 bytes down from the top of the stack (below the local variables and return address) and using register X to select a particular element within the array, that is memory[ memory [6 + SP] + register X ] As far as our function sum is concerned it makes no difference whether the array being passed is global or local as long as the stack contains a pointer to the place where the array is stored. In the former case the array is stored in the global area in the latter case it is stored on the stack but in each case we are just passing an address. More on arrays as parameters Here is an example of a call where the parameter is a local array void A() { int numbers[10]; int X,Y,Z; } X = sum(numbers,10); The only difference between this and the previous example is the calling environment and how the pointer to the array is figured out. Here is this call of sum in Pep/8 movspa ; save address of top of stack subsp 2,i ; for returned value subsp 4,i ; for parameters adda 6,i ; address of array numbers is 6 greater than old top of ; stack i.e. beyond space for X, Y and Z sta 0,s ; array parameter lda 10,i sta 2,s ; size parameter call sum Comp 162 Notes Page 3 of 14 October 17, 2012
4 Pictorially: Pointer to numbers (2 bytes) 10 (2 bytes) 00 0A Space for returned value (2 bytes) Z (2 bytes) Saved SP value Y (2 bytes) X (2 bytes) Array numbers (not all shown) (20 bytes) Finally, here are two examples of C array-processing functions translated into Pep/8. Example 1: copies N elements from one array to another. C void copy (int ar[1], int ar2[], int N) { int i; for (i=0; i<n; i++) ar2[i] = ar1[i]; } Comp 162 Notes Page 4 of 14 October 17, 2012
5 Pep/8 Local: i Ret. Addr.... N... The same value of register X is used to access both arrays so the Pep/8 is relatively straightforward copy: subsp 2,i ; for i ldx 0,i stx 0,s ; initialized to 0 top: cpx 8,s ; i<n? brge done ; no, we are finished aslx ; convert to byte offset lda 4,sxf ; ar1[i] sta 6,sxf ; ar2[i] = ar1[i] asrx ; convert back to index addx 1,i br top done: ret2 Example 2: partial sort of an N-element array. The function partsort makes a pass through the array exchanging out-of-order neighbors. C void partsort(int ar[], int N) { int i,temp; } for (i=0; i<n-1; i++) if (ar[i]>ar[i+1]) { temp = ar[i]; ar[i]=ar[i+1]; ar[i+1]=temp; } Comp 162 Notes Page 5 of 14 October 17, 2012
6 Pep/8 Version 1 Local: temp Local: i Ret. Addr N... The relevant part of our example is the if statement which, given the stack above, translates to ldx 2,s aslx lda 6,sxf addx 2,i cpa 6,sxf brle skip sta 0,s lda 6,sxf subx 2,i sta 6,sxf lda 0,s addx 2,i sta 6,sxf skip: ; i ; as byte offset ; ar[i] ; compare with ar[i+1] ; skip if no swap ; temp = ar[i] ; ar[i+1] ; ar[i] = ar[i+1] ; temp ; ar[i+1] = temp Note that three instructions just change the value in Register X. (This is a consequence of Pep/8 having only a single index register.) One way to eliminate these changes (and thus make the program run faster) is to have a second pointer to the array. The pointer is stored in the scratch space above the top of the stack and points not to the first element of the array but to the second thus: Comp 162 Notes Page 6 of 14 October 17, 2012
7 Pep/8 Version 2 Local: temp.local: i Ret. Addr N... Setting up the pointer is straightforward: lda 6,s adda 2,i sta -2,s Now the code for the if statement is shorter skip: ldx 2,s ; i aslx ; as byte offset lda 6,sxf ; ar[i] cpa -2,sxf ; compare with ar[i+1] brle skip ; skip if no swap sta 0,s ; temp = ar[i] lda -2,sxf ; ar[i+1] sta 6,sxf ; ar[i] = ar[i+1] lda 0,s ; temp sta -2,sxf ; ar[i+1] = temp We have added three instructions at the top of the subroutine to set up the pointer but shorted the then part of the if statement by three instructions. So the space required by this version of the subroutine is the same as the earlier one. However, if the array is large and many swaps are made we would expect our new version to run faster. Comp 162 Notes Page 7 of 14 October 17, 2012
8 Storage and manipulation of multi-dimensional arrays We need multi-dimensional arrays for representing matrices, chessboards, spreadsheets, timetables and so on. There are two main ways in which we can organize their storage. There is somewhat of a trade-off between space and time Option A: single contiguous block Store the array elements systematically in a single block either row-by-row or column-by-column. Suppose our array is declared as follows Values: array[1..3, 2..5] of integer; [ Some languages, e.g., Pascal, let us have non-zero lower bounds.] The contents are Row-by-row it is stored Column-by-column it is stored What is the address of element Values[i,j] (given that both i and j are in bounds)? For our example: Row-by-row mapping: the element is found at Values + 2 * ( (i-1) * 4 + (j-2)) [ In general at : Base-address + element-size * ((row_number row_lower_bound) * row_size + column_number - column_lower_bound) ] Column-by-column mapping: the element is found at Values + 2 * ((j-2) * 3 + (i-1)) For example, Values[3,4] is at M+20 in a row-by-row mapping and at M+16 in a column-bycolumn mapping. Comp 162 Notes Page 8 of 14 October 17, 2012
9 Many systems will store and access multi-dimensional arrays in this way because a MULTIPLY instruction is usually available to compute element addresses. But MULTIPLY is often a timeconsuming operation and some machines (e.g. Pep/8) may not have a multiply instruction so we need to look at another way to store and access multi-dimensional arrays. Option B: using Iliffe vectors We can devise a storage scheme that uses pointers instead of multiplication. Access may be faster than the multiply method although requiring more space (another example of trading time for space). Assume we store the array row by row (ideas are similar if it is stored column by column). Our method works by using an array of pointers to the array. This array of pointers is called an Iliffe vector (after J. K. Iliffe who proposed its use). Each pointer in the Iliffe vector points to the beginning of a row of the actual array. We label the Iliffe vector with the name of the array. In the following depiction of our array Values stored in this way we assume that the actual array starts at location 600 and the Iliffe vector starts at location 300. Note that there is no requirement for the rows to be adjacent in memory or even the same size. Values Comp 162 Notes Page 9 of 14 October 17, 2012
10 Now the Pep/8 code to implement is K = Values[Row,Col] ldx Row,d ; the row number sbx 1,i ; the row lower bound aslx ; make a byte offset ldx Values,x ; get element from array of pointers and put in Reg. X ; this is pointer to row Row addx Col,d ; add 2 times addx Col,d ; Col subx 4,i ; and subtract 2* column lower bound ; so reg X now has address of element we need lda 0,x ; get the element sta K,d ; and assign to K Here is a trace of Register X values for Row=3, Col=4 Reg. X 3 ldx Row,d ; the row number 2 sbx 1,i ; the row lower bound 4 aslx ; as byte offset 616 ldx Values,x ; get element from array of pointers and put in Reg. X ; this is pointer to row Row 620 addx Col,d ; add 2 times 624 addx Col,d ; Col 620 subx 4,i ; and subtract 2* column lower bound ; so reg X now has address of element we need 30 ldx 0,x ; get the element stx K,d ; and assign to K C uses this method to store arrays. Advantages of the pointer method compared with the multiplication method include: (1) may be faster (2) storage for different rows of the actual array need not be adjacent (3) rows need not be the same length! Can have triangular and irregular arrays. We can extend the technique to higher number of dimensions with additional Iliffe vectors. Comp 162 Notes Page 10 of 14 October 17, 2012
11 Array bound checking Adding bound checking to either the multiplication method or the pointer-based method typically adds three or more instructions per dimension for each array access. The Option B code with checking added in bold is ldx Row,d ; the row number cpx MinRow ; the row lower bound brlt Error cpx MaxRow ; the row upper bound brgt Error sbx 1,i ; the row lower bound aslx ; as byte offset ldx M,x ; get element from array of pointers and put in Reg. X ; this is pointer to row Row lda Col,d cpa MinCol ; column lower bound brlt Error ; if Col < lower bound cpa MaxCol brgt Error ; if Col > upper bound addx Col,d ; add 2 times addx Col,d ; subx 4,i ; subtract twice lower bound ; so reg X now has address of element we need lda 0,x ; get the element sta K,d ; and assign to K Because it makes the program larger and slower, perhaps bound checking should be a compiler option. Indexed branching It turns out that arrays are useful in translating other language constructs, the case/switch statement for example. Note that when we write BR LAB we mean BR LAB,i (the assembler lets us omit the,i for readability). From the table of Pep/8 instructions (e.g., inside front cover) we see that it is also possible to write branches using indexing as in BR tab,x Q: What it the effect and why is it useful? A: The effect is to jump to whatever address is stored in Mem[tab+register X]. This means we can set up a table of addresses then branch quickly to any one of them based on the Comp 162 Notes Page 11 of 14 October 17, 2012
12 value in Register X. This is one way to implement a multi-way branch, e.g. a switch/case statement. Warford has an example of a switch statement translation (Fig. 6.40)), here is a more general one: switch(w) { case 13: case 16: < action 1 > break; case 14: < action 2 > break; case 11: < action 3 > break; default: < action 4 > } The implementation of a switch statement in Pep/8 has three components (1) implementations of the actions, with labels. Each action should end with a branch to take program control to whatever statement follows the end of the switch statement. (2) A table containing the labels of the action sections. Table[k] contains the label of the action we should take when the switch variable has value k or, more generally, k+constant. (3) A driver section to implement the branch. Here is an implementation of the example above. Part 1 - the actions action1:... ; code for whatever action 1 does goes here... br endsw ; this branch to stop us falling into action 2 action2:... ; other actions are similar... br endsw action3: br endsw action4: br endsw Comp 162 Notes Page 12 of 14 October 17, 2012
13 Part 2 - the table The.addrss directive in Pep/8 is similar to.word. Both have the effect of initializing a two-byte location with a value known at assembly time. Since we are storing addresses, we choose to use.addrss. In our example, if the switch variable has value 12 or 15 we go to the default case. swtab:.addrss action3 ; case 11.addrss action4 ; case 12.addrss action1 ; case 13.addrss action2 ; case 14.addrss action4 ; case 15.addrss action1 ; case 16 Part 3 - the driver section ldx w,d ; the switch variable cpx 11,i ; less than the lowest switch case? brlt action4 ; yes do the default case cpx 16,i ; greater then the highest switch case? brgt action4 ; yes do the default case subx 11,i ; to get X in range of array indexes: 0.. aslx ; to make into offset for table of (2-byte) addresses br swtab,x ; jump to one of the actions endsw:... ; go here after each case Clearly this approach would not be a good one in all instances. What if the switch statement were switch(w) { case 1: < action 1 > case 100: < action 2 > case 1000: < action 3 > default: < action 4 > } The array in this case would be very large and almost all the entries would point to the default case. In this instance it would be better to implement the switch statement as a sequence of test-andbranch statements. A compiler will apply some internal check to the case labels to decide which implementation to use. Comp 162 Notes Page 13 of 14 October 17, 2012
14 Indexed subroutine calls Note that CALL tab,x is also legal so we can set up a table of subroutine addresses and jump to one depending on the value on register X then return to the instruction following the CALL. This might be a good way to implement a menu-driven program. Something like the following perhaps main: stro prompt,d ; output a prompt deci choice,d ; get user selection brne act ; assume entering zero means stop stop ; act: ldx choice,d ; action number aslx ; subroutine addresses are 2 bytes call options,x ; use table of subroutine addresses br main ; then get next choice ; options:.word 0 ; never executed corresponds to option 0 = stop.address sub1 ; sub1 to be called if user enters 1.address sub2 ; sub2 to be called if user enters 2 and so on Reading We have reached p We will look at section 6.5 and implementation of structures next.. Comp 162 Notes Page 14 of 14 October 17, 2012
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 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 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, 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 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, 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 informationMonday, 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, 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 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 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, 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 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 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, 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, 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 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 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 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 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 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, 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 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 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 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 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 informationWednesday, 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 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, 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 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 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 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 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 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 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 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 informationComputer System Architecture
CSC 203 1.5 Computer System Architecture Department of Statistics and Computer Science University of Sri Jayewardenepura Addressing 2 Addressing Subject of specifying where the operands (addresses) are
More informationLecture #2 January 30, 2004 The 6502 Architecture
Lecture #2 January 30, 2004 The 6502 Architecture In order to understand the more modern computer architectures, it is helpful to examine an older but quite successful processor architecture, the MOS-6502.
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 informationby Pearson Education, Inc. All Rights Reserved.
Let s improve the bubble sort program of Fig. 6.15 to use two functions bubblesort and swap. Function bubblesort sorts the array. It calls function swap (line 51) to exchange the array elements array[j]
More informationAr r ays and Pointer s
Ar r ays and Pointer s Using Bloodshed Dev-C++ Heejin Park Hanyang University 2 Introduction Arrays Multidimensional Arrays Pointers and Arrays Functions, Arrays, and Pointers Pointer Operations Protecting
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 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 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 informationMODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE
MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE 1 ARCHITECTURE MODEL The basic instruction set of a computer is comprised of sequences of REGISTER TRANSFERS. Example: Add A, B, C Register B # A
More information1. The Mac Environment in SIE 1222
Friday, September 1, 2017 Lab Notes Topics for today The Mac Environment C (and Unix) Notes on C Part 1 Program 1 1. The Mac Environment in SIE 1222 a. Turning on the Mac If the Mac is in sleep mode you
More informationWilliam Stallings Computer Organization and Architecture 8 th Edition. Chapter 11 Instruction Sets: Addressing Modes and Formats
William Stallings Computer Organization and Architecture 8 th Edition Chapter 11 Instruction Sets: Addressing Modes and Formats Addressing Modes Immediate Direct Indirect Register Register Indirect Displacement
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 informationAssembly Language. Operand Size. The internal registers. Computers operate on chunks of data composed of a particular number of bits.
1 2 Chapter 6 Assembly Language Operand Size 8 bits 16 bits Computers operate on chunks of data composed of a particular number of bits. The 68K has a 32-bit architecture and a 16-bit organization. Internal
More informationAn array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type.
Data Structures Introduction An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Representation of a large number of homogeneous
More informationComputer Programming: C++
The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming: C++ Experiment #7 Arrays Part II Passing Array to a Function
More informationWednesday, 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 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 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 information(Refer Slide Time: 1:40)
Computer Architecture Prof. Anshul Kumar Department of Computer Science and Engineering, Indian Institute of Technology, Delhi Lecture - 3 Instruction Set Architecture - 1 Today I will start discussion
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 information1. The Mac Environment in Sierra Hall 1242
Wednesday, August 26, 2015 Lab Notes Topics for today The Mac Environment C (and Unix) Notes on C Part 1 Program 1 1. The Mac Environment in Sierra Hall 1242 a. Turning on the Mac If the Mac is in sleep
More informationInstruction Set II. COMP 212 Computer Organization & Architecture. COMP 212 Fall Lecture 7. Instruction Set. Quiz. What is an Instruction Set?
COMP 212 Computer Organization & Architecture Quiz COMP 212 Fall 2008 Lecture 7 Fill in your student number only, do NOT write down your name Open book, but NO calculator, NO discussions, Relax and have
More informationCOS 140: Foundations of Computer Science
COS 140: Foundations of Computer Science Variables and Primitive Data Types Fall 2017 Introduction 3 What is a variable?......................................................... 3 Variable attributes..........................................................
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 informationComp 11 Lectures. Mike Shah. June 26, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures June 26, / 57
Comp 11 Lectures Mike Shah Tufts University June 26, 2017 Mike Shah (Tufts University) Comp 11 Lectures June 26, 2017 1 / 57 Please do not distribute or host these slides without prior permission. Mike
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 informationHow to declare an array in C?
Introduction An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Representation of a large number of homogeneous values.
More informationMaltepe University Computer Engineering Department. BİL 133 Algoritma ve Programlama. Chapter 8: Arrays and pointers
Maltepe University Computer Engineering Department BİL 133 Algoritma ve Programlama Chapter 8: Arrays and pointers Basics int * ptr1, * ptr2; int a[10]; ptr1 = &a[2]; ptr2 = a; // equivalent to ptr2 =
More informationComputer Organization and Structure. Bing-Yu Chen National Taiwan University
Computer Organization and Structure Bing-Yu Chen National Taiwan University Instructions: Language of the Computer Operations and Operands of the Computer Hardware Signed and Unsigned Numbers Representing
More informationUNIT-1. Chapter 1(Introduction and overview) 1. Asymptotic Notations 2. One Dimensional array 3. Multi Dimensional array 4. Pointer arrays.
UNIT-1 Chapter 1(Introduction and overview) 1. Asymptotic Notations 2. One Dimensional array 3. Multi Dimensional array 4. Pointer arrays. Chapter 2 (Linked lists) 1. Definition 2. Single linked list 3.
More informationCSE 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 informationCISC220 Lab 2: Due Wed, Sep 26 at Midnight (110 pts)
CISC220 Lab 2: Due Wed, Sep 26 at Midnight (110 pts) For this lab you may work with a partner, or you may choose to work alone. If you choose to work with a partner, you are still responsible for the lab
More informationComputer Architecture and Organization. Instruction Sets: Addressing Modes and Formats
Computer Architecture and Organization Instruction Sets: Addressing Modes and Formats Addressing Modes Immediate Direct Indirect Register Register Indirect Displacement (Indexed) Stack Immediate Addressing
More informationWhen an instruction is initially read from memory it goes to the Instruction register.
CS 320 Ch. 12 Instruction Sets Computer instructions are written in mnemonics. Mnemonics typically have a 1 to 1 correspondence between a mnemonic and the machine code. Mnemonics are the assembly language
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 informationPrinciple of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore
Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Lecture - 20 Intermediate code generation Part-4 Run-time environments
More informationUNIT II ASSEMBLERS www.noyesengine.com www.technoscriptz.com 1 1. BASIC ASSEMBLER FUNCTIONS 2. A SIMPLE SIC ASSEMBLER 3. ASSEMBLER ALGORITHM AND DATA STRUCTURES 4. MACHINE DEPENDENT ASSEMBLER FEATURES
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 informationCOSC 243. Assembly Language Techniques. Lecture 9. COSC 243 (Computer Architecture)
COSC 243 Assembly Language Techniques 1 Overview This Lecture Source Handouts Next Lectures Memory and Storage Systems 2 Parameter Passing In a high level language we don t worry about the number of parameters
More informationUniversity of California at Santa Barbara. ECE 154A Introduction to Computer Architecture. Quiz #1. October 30 th, Name (Last, First)
University of California at Santa Barbara ECE 154A Introduction to Computer Architecture Quiz #1 October 30 th, 2012 Name (Last, First) All grades will be posted on the website as a single spreadsheet
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 informationLecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)
Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays) In this lecture, you will: Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of
More informationinstruction 1 Fri Oct 13 13:05:
instruction Fri Oct :0:0. Introduction SECTION INSTRUCTION SET This section describes the aressing modes and instruction types.. Aressing Modes The CPU uses eight aressing modes for flexibility in accessing
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 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 informationStored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands
Stored Program Concept Instructions: Instructions are bits Programs are stored in memory to be read or written just like data Processor Memory memory for data, programs, compilers, editors, etc. Fetch
More informationSupplement for MIPS (Section 4.14 of the textbook)
Supplement for MIPS (Section 44 of the textbook) Section 44 does a good job emphasizing that MARIE is a toy architecture that lacks key feature of real-world computer architectures Most noticable, MARIE
More informationIntroduction to Scientific Computing
Introduction to Scientific Computing Dr Hanno Rein Last updated: October 12, 2018 1 Computers A computer is a machine which can perform a set of calculations. The purpose of this course is to give you
More informationGrading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.
Department of Electrical and Computer Engineering University of Wisconsin Madison ECE 552 Introductions to Computer Architecture Homework #2 (Suggested Solution) 1. (10 points) MIPS and C program translations
More informationCOS 140: Foundations of Computer Science
COS 140: Foundations of Variables and Primitive Data Types Fall 2017 Copyright c 2002 2017 UMaine School of Computing and Information S 1 / 29 Homework Reading: Chapter 16 Homework: Exercises at end of
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 informationRun Time Environment. Activation Records Procedure Linkage Name Translation and Variable Access
Run Time Environment Activation Records Procedure Linkage Name Translation and Variable Access Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University
More informationContents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides
Slide Set 1 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section
More informationLecture 15: Caches and Optimization Computer Architecture and Systems Programming ( )
Systems Group Department of Computer Science ETH Zürich Lecture 15: Caches and Optimization Computer Architecture and Systems Programming (252-0061-00) Timothy Roscoe Herbstsemester 2012 Last time Program
More informationTo declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows
Unti 4: C Arrays Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type An array is used to store a collection of data, but it is often more useful
More informationELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)
ELEC 5200-001/6200-001 Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2) Victor P. Nelson, Professor & Asst. Chair Vishwani D. Agrawal, James J. Danaher Professor Department
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 informationCS2422 Assembly Language & System Programming
CS2422 Assembly Language & System Programming November 30, 2006 Today s Topic Assembler: Basic Functions Section 2.1 of Beck s System Software book. Reading Assignment: pages 43-52. Role of Assembler Source
More informationCode Generation. Lecture 12
Code Generation Lecture 12 1 Lecture Outline Topic 1: Basic Code Generation The MIPS assembly language A simple source language Stack-machine implementation of the simple language Topic 2: Code Generation
More informationArrays and Pointers (part 1)
Arrays and Pointers (part 1) CSE 2031 Fall 2012 Arrays Grouping of data of the same type. Loops commonly used for manipulation. Programmers set array sizes explicitly. Arrays: Example Syntax type name[size];
More informationWe briefly explain an instruction cycle now, before proceeding with the details of addressing modes.
Addressing Modes This is an important feature of computers. We start with the known fact that many instructions have to include addresses; the instructions should be short, but addresses tend to be long.
More informationPointer Arithmetic. Lecture 4 Chapter 10. Robb T. Koether. Hampden-Sydney College. Wed, Jan 25, 2017
Pointer Arithmetic Lecture 4 Chapter 10 Robb T. Koether Hampden-Sydney College Wed, Jan 25, 2017 Robb T. Koether (Hampden-Sydney College) Pointer Arithmetic Wed, Jan 25, 2017 1 / 36 1 Pointer Arithmetic
More informationTopic Notes: MIPS Instruction Set Architecture
Computer Science 220 Assembly Language & Comp. Architecture Siena College Fall 2011 Topic Notes: MIPS Instruction Set Architecture vonneumann Architecture Modern computers use the vonneumann architecture.
More informationModule 8: Atmega32 Stack & Subroutine. Stack Pointer Subroutine Call function
Module 8: Atmega32 Stack & Subroutine Stack Pointer Subroutine Call function Stack Stack o Stack is a section of RAM used by the CPU to store information temporarily (i.e. data or address). o The CPU needs
More information