Wednesday, February 15, 2017

Size: px
Start display at page:

Download "Wednesday, February 15, 2017"

Transcription

1 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 C bits Macro assemblers Many real assemblers allow users to declare macro instructions (macros). Here is an example.macro SWAP x,y Load r1 %x Move %y, %x Store r1 %x.mend Now the user can use SWAP as if it were a built-in instruction SWAP P,Q Implementation Processing of macros can be incorporated into Pass 1, however it is simpler to have macro definition and expansion handled separately by a Pass 0 thus Source Source Pass 0 - definitions Pass 1 etc. + expansions Macro definition table Pass 0 uses a table to store the macro definitions. Pass 0 outputs a copy of the source code from which macro definitions have been removed and into which macro calls have been expanded. Comp 162 Notes Page 1 of 13 February 15, 2017

2 Macros can be defined for IF, ENDIF, FOR, WHILE and so on, to give the assembly language a high-level flavor. After assembly: linking Source1 Assembler Object1 Source2 Assembler Object2 Linker Object Source3 Assembler Object3 Library, e.g. subroutines The linker program resolves external references, that is, references to symbols defined in another module 1. It may also adjust addresses to that the final object program is a single contiguous block. So far Warford has Chapter 6 (a) (b) introduced a high-level language (C). shown how the Pep/9 machine works (Chapter 4) and introduced an assembly language for programming it (Chapter 5). In Chapter 6 he brings the two threads together and shows how high-level language elements can be translated into assembly language. He covers both data structures (arrays and "structures") and control structures (if statements, while loops and function calls). Chapter 6 is a large one, containing much detailed information. Here is a top-level view 6.1 The run-time stack. Stack addressing mode. How the stack is used to implement local variables 6.2 Control Structures - 1: if and while 6.3 Control Structures - 2: function calls 6.4 Data structures - 1: arrays (also the switch statement) 6.5 Data structures - 2: "structures", pointers, dynamic memory 1 In C, for example, it is likely to be the linker that detects that you have misspelled the name of a library routine. Comp 162 Notes Page 2 of 13 February 15, 2017

3 We will skip consideration of the stack for the moment and look at how to implement programs with branches. Branching (Section 6.2) The unconditional branch instruction BR transfers control to the specified location. We have seen this informally when we branch round declarations at the beginning of a program as in br main A:.block 2 B:.block 2 main: deci A,d etc In general we also need conditional branch instructions that test some state of the machine to decide whether or not to branch. In Pep/9 many instructions (see Figure 5.2) set one or more of the status bits (NZVC) as a sideeffect of their operation. For example DECI sets N if input is negative, Z if it is zero and V if user enters a number too big for 16 bits LDWr sets N if a negative number is loaded and Z if zero is loaded CPWr The only purpose of the CPWr (Compare Words) instruction is to set status bits. It has no effect on any register or memory location. It sets status bits according to the value of the expression (register - operand). The conditional branch instructions test (but do not change) the status bits when deciding whether or not to branch. The 8 conditional branch instructions are Comp 162 Notes Page 3 of 13 February 15, 2017

4 opcode branch if branch if brle Less than or equal to N=1 or Z=1 brlt Less than N=1 breq Equal to Z=1 brne Not equal to Z=0 brge Greater than or equal to N=0 brgt Greater than N=0 and Z=0 brv Overflow V=1 brc Carry C=1 Pictorially DECI, LDWr, CPWr etc set N Z V C Status bits test BRGT, BREQ, BRV etc Suppose we need a program that reads N followed by N integers then outputs the sum of the N integers. The following partial implementation in Pep/9 assembly code illustrates use of branch instructions (some for error checking) how registers can be used in place of variables to speed up the program Comp 162 Notes Page 4 of 13 February 15, 2017

5 ldwa 0,i deci N,d brv error1 brlt error2 breq done ldwx N,d Register A holds total initially zero the number of numbers branch if N is out of range branch if user entered a negative count! branch if zero numbers to be read so just print total register X holds count of numbers still to be read top: deci Number,d input number to be summed use scratch location brv error3 branch if number out of range adda Number,d otherwise add it to the running total in register A brv error4 branch if sum is now out of range subx 1,i reduce count of numbers to be read brgt top branch if the count is still greater than zero done: stwa Total,d store the total in memory and deco Total,d output it stop N:.block 2 the number of numbers Number:.block 2 Total:.block 2.end one of the numbers the total of the numbers (for printing) IF statements Here are four pseudocode "if" statements and their translation to Pep/9 assembly code. If: Example 1 if (N<0) output (t) Generally, testing against 0 is easy. In Pep/9 this is simply ldwa N,d status bits set according to the value of N brge skip branch past the output if N >= 0 deco t,d skip: nop0 Note the use of the NOP instruction. A label must be attached to something. Comp 162 Notes Page 5 of 13 February 15, 2017

6 If: Example 2 if (count >= 39) output(1) else output(2) We need a CPW instruction in this case to compare count and 39. Note how we skip round the else part. ldwa count,d cpwa 39,i sets bits according to count-39 brlt else branch if count < 39 deco 1,i br endif skip round else code else: deco 2,i endif:nop0 If: Example 3 if (A>B) output(a) else output(b) We can put either the then or the else part first. The label else is never referenced, it is used to increase program readability. ldwa A,d cpwa B,d status bits depend on value of A-B brgt thenpart branch if A>B (A-B >0) else: deco B,d this is else part br skip remember to skip over the then part thenpart: deco A,d skip: nop0 If: Example 4 if (A>=14 && B<3 C!= 50) output (x) We can start with the simple second part of the OR ldwa C,d cpwa 50,i brne output ldwa A,d cpwa 14,i brlt skip ldwa B,d cpwa 3,i brge skip output: deco x,d skip: nop0 if C ne 50 condition is true so output otherwise test first part of condition first part of AND is false so no output second part of AND is false so skip output Comp 162 Notes Page 6 of 13 February 15, 2017

7 WHILE statements The implementation of conditional expressions in "while" statements is similar to their implementation in if statements. Here are three pseudocode examples translated into Pep/9 assemble code. While: Example 1 Our first example has a simple condition. input(n) while (N < 99) { output(n) input(n) } In Pep/9 this might be deci N,d top: ldwa N,d cpwa 99,i set bits according to N-99 brge skip skip loop if N >= 99 deco N,d deci N,d get next value for N br top back to test loop condition skip: nop0 While: Example 2 Our second example has two relational and one logical operator. In Pep/9 this might be input(n) while (N > 6 && N <= 10) { sum += N input(n) } top: deci N,d ldwa N,d sets bits according to value of N cpwa 6,i check first part of condition brle skip branch if N <= 6 no need to check N<=10 cpwa 10,i note - no need to reload N brgt skip skip the loop if N > 10 adda sum,d stwa sum,d sum += N br top skip: nop0 Comp 162 Notes Page 7 of 13 February 15, 2017

8 While: Example 3 Another example (this time with an or connector) is while (A > 2 B < 7) { input(a,b) output(a+b) } In Pep/9 this might be top: ldwa A,d cpwa 2,i brgt loop ldwa B,d cpwa 7,i brge skip loop: deci A,d get two numbers deci B,d ldwa A,d adda B,d skip: stwa -2,s deco -2,s br top nop0 first clause is true so don t need to check second first was false so check second if second clause is also false, don t do loop use stack for scratch space (see later) output sum of inputs Nested loops are of course possible. Label names and program text layout can help program clarity. To print a 3 by 5 table of stars * * * * * * * * * * * * * * * For (i=0 i<3, i++) { For (j=0 j<5 j++) Output( * ) Output( \n ) } In Pep/9 might be something like the following Comp 162 Notes Page 8 of 13 February 15, 2017

9 nested loops to print 3 by 5 stars ldwa 0,i stwa i,d outer: ldwa 0,i stwa j,d inner: ldbx '*',i stbx charout,d ldwa j,d adda 1,i stwa j,d j++ cpwa 5,i brlt inner branch if more to print on current line stop i:.block 2 j:.block 2.end ldbx '\n',i stbx charout,d ldwa i,d adda 1,i stwa i,d cpwa 3,i brlt outer i++ branch if more lines to print Structured programming theorem Warford refers to the "structured programming theorem" 2 which says that "if" and "while" are sufficient (along with sequence) to implement any algorithm. Thus, it must be possible to translate other constructs in C such as "do-while statements and "for" loops into if and while loops. E.g. and for (ABC) {action} is A while(b) { action C } do { action } while (C) is action while(c) {action} One strategy for developing assembly language programs is to write the algorithm first in a high-level notation using "if" and "while" then translate it. This avoids the temptation to use "branch" statements in an unstructured way (see Fig 6.16 for an example of unstructured branching). 2 Comp 162 Notes Page 9 of 13 February 15, 2017

10 The V and C bits. The V and C bits are tested by the brv and brc instructions respectively. The V bit The V bit is set on overflow and is useful for checking user input and arithmetic operations as in the earlier example program that summed N integers. The C bit The C bit is set by a carry out from arithmetic operations such as add and shift. The following code divides N by 2 (integer divide) and reports the result of the true division. For example if N is 13, it is replaced by 6 and the program outputs 6.5. ldwa N,d asra rightmost bit goes into C stwa N,d N/2 deco N,d brc halfout if C set, we need to output.5 br skip halfout: ldbx.,i stbx charout,d ldbx 5,i stbx charout,d skip: nop0 We can perform multilength arithmetic by allocating multiple storage locations to a variable then augmenting the arithmetic operations. For example, in Pep/9 we can use two words to hold a 32- bit number one holds the most significant half, the other the least significant half. We make use of the brc instruction in the code that adds two such 32-bit numbers and stores the result in a third. Our two numbers to be added are in variables A1, A2 and B1, B2. The result goes in C1 and C2. Pictorially: A1 B1 A2 B2 C1 C2 Comp 162 Notes Page 10 of 13 February 15, 2017

11 ldwa A2,d adda B2,d may set carry bit stwa C2,d ldwa A1,d brc carry branch if carry set in addition of least significant halves br nocarry carry: adda 1,i the extra 1 added to the addition of most significant halves nocarry: adda B1,d stwa C1,d Reading Read section 6.2 for material on ifs and whiles. Comp 162 Notes Page 11 of 13 February 15, 2017

12 Review Questions Consider the following Pep/9 program ldwx 0x0008,i L: stro S,d asrx shift X right arithmetically brne L stop S:.ascii Hello\n\x00.end 1. Predict the number of times that the program outputs the string before it stops. 2. What other constant(s) in the first line would result in the same number of strings being output? 3. What constant would we use in the first line if we want the program to output 10 strings? 4. What is the largest number of strings that we can have the program output in this way and then stop? 5. If the constant in the first line is changed to 0x8000 does it print strings and then stop? If so, how many strings? If not, why does it not stop? 6. If we change the third line in the original program above to aslx, predict the number of strings that it outputs before stopping. Comp 162 Notes Page 12 of 13 February 15, 2017

13 Review Answers 1. It prints a string then halves the number (truncated division). It will print 4 strings before the number reaches zero: 8, 4, 2, 1, 0 2. Any number that has the leftmost 1 in the same position as 8 so 9..F. 3. We could use 0x0200 or any number that has the leftmost 1 in the same position E.g., if the constant is 0x It does not stop because 0x8000 is a negative number and the right shift keeps the leftmost bit equal to 1 so the number never reaches zero. ( -1/2 = -1) 6. It stops after printing 13 strings when the sole 1 bit in the number is shifted out and the result is zero. Comp 162 Notes Page 13 of 13 February 15, 2017

Monday, March 27, 2017

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

More information

Wednesday, February 7, 2018

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

More information

Wednesday, September 27, 2017

Wednesday, 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 information

Wednesday, March 12, 2014

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

More information

Monday, March 13, 2017

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

More information

Wednesday, February 28, 2018

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

More information

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

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

More information

Wednesday, March 14, 2018

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

More information

Wednesday, September 20, 2017

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

More information

Monday, February 16, 2015

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

More information

A rubric for programming assignments

A 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 information

Monday, March 9, 2015

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

More information

Monday, October 17, 2016

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

More information

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

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

More information

Wednesday, October 17, 2012

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

More information

Monday, February 11, 2013

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

More information

Monday, October 26, 2015

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

More information

Wednesday, September 21, 2016

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

More information

Monday, October 24, 2016

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

More information

Wednesday, February 19, 2014

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

More information

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

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

More information

Monday, September 28, 2015

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

More information

CSC 221: Computer Organization, Spring 2009

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

More information

n NOPn Unary no operation trap U aaa NOP Nonunary no operation trap i

n 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 information

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

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

More information

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

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

More information

Wednesday, September 13, Chapter 4

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

More information

Wednesday, April 16, 2014

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

More information

Low-level software. Components Circuits Gates Transistors

Low-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 information

Wednesday, February 4, Chapter 4

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

More information

Wednesday, April 19, 2017

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

More information

Wednesday, April 22, 2015

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

More information

Wednesday, November 15, 2017

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

More information

LOW-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 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 information

Chapter. Assembly Language

Chapter. 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 information

Monday, November 7, Structures and dynamic memory

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

More information

Monday, April 9, 2018

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

More information

APPLICATION LEVEL HIGH-ORDER LANGUAGE LEVEL ASSEMBLY LEVEL OPERATING SYSTEM LEVEL INSTRUCTION SET ARCHITECTURE LEVEL MICROCODE LEVEL LOGIC GATE LEVEL

APPLICATION LEVEL HIGH-ORDER LANGUAGE LEVEL ASSEMBLY LEVEL OPERATING SYSTEM LEVEL INSTRUCTION SET ARCHITECTURE LEVEL MICROCODE LEVEL LOGIC GATE LEVEL Operating System APPLICATION LEVEL HIGH-ORDER LANGUAGE LEVEL ASSEMBLY LEVEL OPERATING SYSTEM LEVEL 4 INSTRUCTION SET ARCHITECTURE LEVEL MICROCODE LEVEL LOGIC GATE LEVEL Three types of operating systems

More information

Chapter 8. Process Management

Chapter 8. Process Management Chapter 8 Process Management Operating System APPLICATION LEVEL HIGH-ORDER LANGUAGE LEVEL ASSEMBLY LEVEL OPERATING SYSTEM LEVEL 4 INSTRUCTION SET ARCHITECTURE LEVEL MICROCODE LEVEL LOGIC GATE LEVEL Three

More information

Wednesday, November 8, 2017

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

More information

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo 1 Lecture Overview AVR ISA AVR Instructions & Programming (I) Basic construct implementation 2 Atmel AVR 8-bit RISC architecture

More information

Low-Level Programming Languages and Pseudocode

Low-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 information

Extra-credit QUIZ Pipelining -due next time-

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

More information

AVR ISA & AVR Programming (I)

AVR ISA & AVR Programming (I) AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo Week 1 1 Lecture Overview AVR ISA AVR Instructions & Programming (I) Basic construct implementation Week 1 2 1 Atmel AVR 8-bit

More information

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo 1 Lecture Overview AVR ISA AVR Instructions & Programming (I) Basic construct implementation 2 Atmel AVR 8-bit RISC architecture

More information

Wednesday, April

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

More information

Wednesday, September 6, 2017

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

More information

Chapter 6. Compiling to the Assembly Level

Chapter 6. Compiling to the Assembly Level Chapter 6 Compiling to the Assembly Level Direct addressing Oprnd = Mem[OprndSpec] Asmb5 letter: d The operand specifier is the address in memory of the operand. Immediate addressing Oprnd = OprndSpec

More information

COMP2121: Microprocessors and Interfacing

COMP2121: Microprocessors and Interfacing Interfacing Lecture 9: Program Control Instructions http://www.cse.unsw.edu.au/~cs2121 Lecturer: Hui Wu Session 1, 2006 Program control instructions in AVR Stacks Overview Sample AVR assembly programs

More information

Chapter 4. Operations on Data

Chapter 4. Operations on Data Chapter 4 Operations on Data 1 OBJECTIVES After reading this chapter, the reader should be able to: List the three categories of operations performed on data. Perform unary and binary logic operations

More information

Unified Engineering Fall 2004

Unified Engineering Fall 2004 Massachusetts Institute of Technology Department of Aeronautics and Astronautics Cambridge, MA 02139 Unified Engineering Fall 2004 Problem Set #3 Solutions C&P PSET 3 Solutions 1. 12

More information

Module 2: Computer Arithmetic

Module 2: Computer Arithmetic Module 2: Computer Arithmetic 1 B O O K : C O M P U T E R O R G A N I Z A T I O N A N D D E S I G N, 3 E D, D A V I D L. P A T T E R S O N A N D J O H N L. H A N N E S S Y, M O R G A N K A U F M A N N

More information

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */ Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,

More information

C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5

C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5 C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5 1. Pointers As Kernighan and Ritchie state, a pointer is a variable that contains the address of a variable. They have been

More information

Computer Systems. Fifth edition Documentation for Exam Handouts. J. Stanley Warford

Computer Systems. Fifth edition Documentation for Exam Handouts. J. Stanley Warford Computer Systems Fifth edition Documentation for Exam Handouts J. Stanley Warford March 22, 2016 Instruction set Instruction Mnemonic Instruction ddressing Status Specifier Mode Bits 0000 0000 STOP Stop

More information

MODEL ANSWERS COMP36512, May 2016

MODEL ANSWERS COMP36512, May 2016 MODEL ANSWERS COMP36512, May 2016 QUESTION 1: a) Clearly: 1-g, 2-d, 3-h, 4-e, 5-i, 6-a, 7-b, 8-c, 9-f. 0.5 marks for each correct answer rounded up as no halves are used. b) i) It has been mentioned in

More information

Fixed-Point Math and Other Optimizations

Fixed-Point Math and Other Optimizations Fixed-Point Math and Other Optimizations Embedded Systems 8-1 Fixed Point Math Why and How Floating point is too slow and integers truncate the data Floating point subroutines: slower than native, overhead

More information

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan Lecture 08-1 Programming in C++ PART 1 By Assistant Professor Dr. Ali Kattan 1 The Conditional Operator The conditional operator is similar to the if..else statement but has a shorter format. This is useful

More information

Instruction-set Design Issues: what is the ML instruction format(s) ML instruction Opcode Dest. Operand Source Operand 1...

Instruction-set Design Issues: what is the ML instruction format(s) ML instruction Opcode Dest. Operand Source Operand 1... Instruction-set Design Issues: what is the format(s) Opcode Dest. Operand Source Operand 1... 1) Which instructions to include: How many? Complexity - simple ADD R1, R2, R3 complex e.g., VAX MATCHC substrlength,

More information

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

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

More information

Machine 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 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 information

EE 3170 Microcontroller Applications

EE 3170 Microcontroller Applications Lecture Overview EE 3170 Microcontroller Applications Lecture 7 : Instruction Subset & Machine Language: Conditions & Branches in Motorola 68HC11 - Miller 2.2 & 2.3 & 2.4 Based on slides for ECE3170 by

More information

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J. CS61C Negative Numbers and Logical Operations cs 61C L7 Number.1 Lecture 7 February 10, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson) www-inst.eecs.berkeley.edu/~cs61c/schedule.html Review 1/2

More information

Lecture 7: Examples, MARS, Arithmetic

Lecture 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 information

UNIT-IV: MACRO PROCESSOR

UNIT-IV: MACRO PROCESSOR UNIT-IV: MACRO PROCESSOR A Macro represents a commonly used group of statements in the source programming language. A macro instruction (macro) is a notational convenience for the programmer o It allows

More information

UNIT-II. Part-2: CENTRAL PROCESSING UNIT

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

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

CS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014

CS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014 B CS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014 DUE : March 3, 2014 READ : - Related sections of Chapter 2 - Related sections of Chapter 3 - Related sections of Appendix A - Related sections

More information

6. Control Statements II

6. Control Statements II Visibility Declaration in a block is not visible outside of the block. 6. Control Statements II Visibility, Local Variables, While Statement, Do Statement, Jump Statements main block int main () int i

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Instructions: Assembly Language

Instructions: Assembly Language Chapter 2 Instructions: Assembly Language Reading: The corresponding chapter in the 2nd edition is Chapter 3, in the 3rd edition it is Chapter 2 and Appendix A and in the 4th edition it is Chapter 2 and

More information

Topics. 6.1 Number Systems and Radix Conversion 6.2 Fixed-Point Arithmetic 6.3 Seminumeric Aspects of ALU Design 6.4 Floating-Point Arithmetic

Topics. 6.1 Number Systems and Radix Conversion 6.2 Fixed-Point Arithmetic 6.3 Seminumeric Aspects of ALU Design 6.4 Floating-Point Arithmetic 6-1 Chapter 6 Computer Arithmetic and the Arithmetic Unit Chapter 6: Computer Arithmetic and the Arithmetic Unit Topics 6.1 Number Systems and Radix Conversion 6.2 Fixed-Point Arithmetic 6.3 Seminumeric

More information

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C Final Review CS304 Introduction to C Why C? Difference between Python and C C compiler stages Basic syntax in C Pointers What is a pointer? declaration, &, dereference... Pointer & dynamic memory allocation

More information

Assembly language Simple, regular instructions building blocks of C, Java & other languages Typically one-to-one mapping to machine language

Assembly language Simple, regular instructions building blocks of C, Java & other languages Typically one-to-one mapping to machine language Assembly Language Readings: 2.1-2.7, 2.9-2.10, 2.14 Green reference card Assembly language Simple, regular instructions building blocks of C, Java & other languages Typically one-to-one mapping to machine

More information

Concepts Introduced in Chapter 3

Concepts Introduced in Chapter 3 Concepts Introduced in Chapter 3 basic instruction set design principles subset of the MIPS assembly language correspondence between high-level language constructs and MIPS assembly code how MIPS assembly

More information

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE

MODULE 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 information

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR UNIT I Digital Systems: Binary Numbers, Octal, Hexa Decimal and other base numbers, Number base conversions, complements, signed binary numbers, Floating point number representation, binary codes, error

More information

TABLES AND HASHING. Chapter 13

TABLES AND HASHING. Chapter 13 Data Structures Dr Ahmed Rafat Abas Computer Science Dept, Faculty of Computer and Information, Zagazig University arabas@zu.edu.eg http://www.arsaliem.faculty.zu.edu.eg/ TABLES AND HASHING Chapter 13

More information

Lecture 20: AVR Programming, Continued. AVR Program Visible State (ones we care about for now)

Lecture 20: AVR Programming, Continued. AVR Program Visible State (ones we care about for now) 18 100 Lecture 20: AVR Programming, Continued S 15 L20 1 James C. Hoe Dept of ECE, CMU April 2, 2015 Today s Goal: You will all be ace AVR hackers! Announcements: Midterm 2 can be picked up in lab and

More information

(Refer Slide Time: 1:40)

(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 information

PACKED DECIMAL ARITHMETIC

PACKED DECIMAL ARITHMETIC PACKED DECIMAL ARITHMETIC Packed decimal is a convenient format for doing many arithmetic calculations in assembly language for several reasons: 1) All computations occur in integer arithmetic (no decimals,

More information

CN310 Microprocessor Systems Design

CN310 Microprocessor Systems Design CN310 Microprocessor Systems Design Instruction Set (AVR) Nawin Somyat Department of Electrical and Computer Engineering Thammasat University Outline Course Contents 1 Introduction 2 Simple Computer 3

More information

Decision Making -Branching. Class Incharge: S. Sasirekha

Decision Making -Branching. Class Incharge: S. Sasirekha Decision Making -Branching Class Incharge: S. Sasirekha Branching The C language programs presented until now follows a sequential form of execution of statements. Many times it is required to alter the

More information

Chapter 2A Instructions: Language of the Computer

Chapter 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 information

AVR Control Transfer -AVR Branching

AVR Control Transfer -AVR Branching 1 P a g e AVR Control Transfer -AVR Branching Reading The AVR Microcontroller and Embedded Systems using Assembly and C) by Muhammad Ali Mazidi, Sarmad Naimi, and Sepehr Naimi Chapter 3: Branch, Call,

More information

Instruction-set Design Issues: what is the ML instruction format(s) ML instruction Opcode Dest. Operand Source Operand 1...

Instruction-set Design Issues: what is the ML instruction format(s) ML instruction Opcode Dest. Operand Source Operand 1... Instruction-set Design Issues: what is the format(s) Opcode Dest. Operand Source Operand 1... 1) Which instructions to include: How many? Complexity - simple ADD R1, R2, R3 complex e.g., VAX MATCHC substrlength,

More information

CPE300: Digital System Architecture and Design

CPE300: Digital System Architecture and Design CPE300: Digital System Architecture and Design Fall 2011 MW 17:30-18:45 CBC C316 Arithmetic Unit 10122011 http://www.egr.unlv.edu/~b1morris/cpe300/ 2 Outline Recap Fixed Point Arithmetic Addition/Subtraction

More information

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 CS 64 Lecture 2 Data Representation Reading: FLD 1.2-1.4 Decimal Numbers: Base 10 Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Example: 3271 = (3x10 3 ) + (2x10 2 ) + (7x10 1 ) + (1x10 0 ) 1010 10?= 1010 2?= 1

More information

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One

More information

SOURCE LANGUAGE DESCRIPTION

SOURCE LANGUAGE DESCRIPTION 1. Simple Integer Language (SIL) SOURCE LANGUAGE DESCRIPTION The language specification given here is informal and gives a lot of flexibility for the designer to write the grammatical specifications to

More information

Microsoft Visual Basic 2005: Reloaded

Microsoft Visual Basic 2005: Reloaded Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program Objectives After studying this chapter, you should be able to: Include the selection structure in pseudocode

More information

Overview. EE 4504 Computer Organization. Much of the computer s architecture / organization is hidden from a HLL programmer

Overview. EE 4504 Computer Organization. Much of the computer s architecture / organization is hidden from a HLL programmer Overview EE 4504 Computer Organization Section 7 The Instruction Set Much of the computer s architecture / organization is hidden from a HLL programmer In the abstract sense, the programmer should not

More information

2. Define Instruction Set Architecture. What are its two main characteristics? Be precise!

2. Define Instruction Set Architecture. What are its two main characteristics? Be precise! Chapter 1: Computer Abstractions and Technology 1. Assume two processors, a CISC processor and a RISC processor. In order to run a particular program, the CISC processor must execute 10 million instructions

More information

ECE 3610 MICROPROCESSING SYSTEMS

ECE 3610 MICROPROCESSING SYSTEMS 24.361 Lab. 4 31 ECE 3610 MICROPROCESSING SYSTEMS Laboratory 4 LAB 4: ASSEMBLER DIRECTIVES, THE STACK, SUBROUTINES, AND BUBBLE SORTING 1 INTRODUCTION This lab deals with the use of the stack and subroutines

More information

Instruction Sets: Characteristics and Functions Addressing Modes

Instruction Sets: Characteristics and Functions Addressing Modes Instruction Sets: Characteristics and Functions Addressing Modes Chapters 10 and 11, William Stallings Computer Organization and Architecture 7 th Edition What is an Instruction Set? The complete collection

More information

Subroutine Linkage Wheeler Jump control program

Subroutine Linkage Wheeler Jump control program Subroutine Linkage We now begin discussion of subroutine linkages for simple subroutines without large argument blocks. With the mechanisms discussed in this lecture, one can use either global variables

More information

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 Name :. Roll No. :..... Invigilator s Signature :.. 2011 INTRODUCTION TO PROGRAMMING Time Allotted : 3 Hours Full Marks : 70 The figures in the margin indicate full marks. Candidates are required to give

More information

Advanced Computer Architecture-CS501

Advanced Computer Architecture-CS501 Advanced Computer Architecture Lecture No. 34 Reading Material Vincent P. Heuring & Harry F. Jordan Chapter 6 Computer Systems Design and Architecture 6.1, 6.2 Summary Introduction to ALSU Radix Conversion

More information

NAN propagation versus fault trapping in floating point code

NAN propagation versus fault trapping in floating point code NAN propagation versus fault trapping in floating point code By Agner Fog. Technical University of Denmark. Copyright 2018. Last updated 2018-05-24. Contents 1 Introduction... 1 2 Fault trapping... 1 3

More information

4.2 Machine-Independent Macro Processor Features

4.2 Machine-Independent Macro Processor Features 4.2 Machine-Independent Macro Processor Features Extensions to the basic macro processor functions Concatenation of Macro Parameters Generation of Unique Labels Conditional Macro Expansion Keyword Macro

More information