Presentation is loading. Please wait.

Presentation is loading. Please wait.

1BA3 G Lacey Lecture 51 Evaluating mathematical expressions  How do computers evaluate x + y or any mathematical expression ?  Answer : “Reverse Polish.

Similar presentations


Presentation on theme: "1BA3 G Lacey Lecture 51 Evaluating mathematical expressions  How do computers evaluate x + y or any mathematical expression ?  Answer : “Reverse Polish."— Presentation transcript:

1 1BA3 G Lacey Lecture 51 Evaluating mathematical expressions  How do computers evaluate x + y or any mathematical expression ?  Answer : “Reverse Polish Notation”  a + b - c / ( d + e ) is an infix expression a, b, c, d, and e are operands +, -, /, “(“, and “)” are operators  Computers can’t evaluate infix expressions. They must first be converted to “reverse polish notation” or postfix expressions  a b + c d e + / -is a postfix expression

2 1BA3 G Lacey Lecture 52 Push onto stack  A data structure called a “stack” is used to convert infix to postfix  A stack is like a packet of PEZ or a coin holder on the Bus i.e. “last in = first out”  Things can only be put onto the top of the stack (push)  Things can only be taken from the top of the stack (pop)  Push a, b, c, d, e onto the stack  Pop 3 items off the stack Top of Stack ab

3 1BA3 G Lacey Lecture 53 Push onto stack  A data structure called a “stack” is used to convert infix to postfix  A stack is like a packet of PEZ or a coin holder on the Bus i.e. “last in = first out”  Things can only be put onto the top of the stack (push)  Things can only be taken from the top of the stack (pop)  Push a, b, c, d, e onto the stack  Pop 3 items off the stack Top of Stack a b c

4 1BA3 G Lacey Lecture 54 Push onto stack  A data structure called a “stack” is used to convert infix to postfix  A stack is like a packet of PEZ or a coin holder on the Bus i.e. “last in = first out”  Things can only be put onto the top of the stack (push)  Things can only be taken from the top of the stack (pop)  Push a, b, c, d, e onto the stack  Pop 3 items off the stack Top of Stack a b cd

5 1BA3 G Lacey Lecture 55 Push onto stack  A data structure called a “stack” is used to convert infix to postfix  A stack is like a packet of PEZ or a coin holder on the Bus i.e. “last in = first out”  Things can only be put onto the top of the stack (push)  Things can only be taken from the top of the stack (pop)  Push a, b, c, d, e onto the stack  Pop 3 items off the stack Top of Stack a b c de

6 1BA3 G Lacey Lecture 56 Pop off stack  A data structure called a “stack” is used to convert infix to postfix  A stack is like a packet of PEZ or a coin holder on the Bus i.e. “last in = first out”  Things can only be put onto the top of the stack (push)  Things can only be taken from the top of the stack (pop)  Push a, b, c, d, e onto the stack  Pop 3 items off the stack Top of Stack a b c d e

7 1BA3 G Lacey Lecture 57 Pop off stack  A data structure called a “stack” is used to convert infix to postfix  A stack is like a packet of PEZ or a coin holder on the Bus i.e. “last in = first out”  Things can only be put onto the top of the stack (push)  Things can only be taken from the top of the stack (pop)  Push a, b, c, d, e onto the stack  Pop 3 items off the stack Top of Stack a b c d

8 1BA3 G Lacey Lecture 58 Pop off stack  A data structure called a “stack” is used to convert infix to postfix  A stack is like a packet of PEZ or a coin holder on the Bus i.e. “last in = first out”  Things can only be put onto the top of the stack (push)  Things can only be taken from the top of the stack (pop)  Push a, b, c, d, e onto the stack  Pop 3 items off the stack Top of Stack a b c

9 1BA3 G Lacey Lecture 59 Advantages of Stacks  Very simple to use  Use very little space  Only simple machine language instructions needed to implement a stack thus they can run very fast  Algorithm to convert from infix to postfix is simple  Algorithm to evaluate postfix is simple

10 1BA3 G Lacey Lecture 510 Convert a + b - c / ( d + e ) to Postfix  Algorithm : Place parentheses around the expression ( a + b - c / ( d - e ) ) moving left to right until the end of the infix expression  if the item is a number put into the post fix expression  if the item is an open brace push it onto the stack  if the item is an operator pop all operators of lower and equal precedence off of the stack and place them in the postfix expression, then push the operator onto the stack  If the operator is a close brace pop all operators off the stack until an open brace, then delete POSTFIX EXPRESSION = ()( a

11 1BA3 G Lacey Lecture 511 Convert a + b - c / ( d + e ) to Postfix  Algorithm : Place parentheses around the expression ( a + b - c / ( d - e ) ) moving left to right until the end of the infix expression  if the item is a number put into the post fix expression  if the item is an open brace push it onto the stack  if the item is an operator pop all operators of lower and equal precedence off of the stack and place them in the postfix expression, then push the operator onto the stack  If the operator is a close brace pop all operators off the stack until an open brace, then delete POSTFIX EXPRESSION = ()( a ( +

12 1BA3 G Lacey Lecture 512 Convert a + b - c / ( d + e ) to Postfix  Algorithm : Place parentheses around the expression ( a + b - c / ( d - e ) ) moving left to right until the end of the infix expression  if the item is a number put into the post fix expression  if the item is an open brace push it onto the stack  if the item is an operator pop all operators of lower and equal precedence off of the stack and place them in the postfix expression, then push the operator onto the stack  If the operator is a close brace pop all operators off the stack until an open brace, then delete POSTFIX EXPRESSION = ()( a ( + b -

13 1BA3 G Lacey Lecture 513  Algorithm : Place parentheses around the expression ( a + b - c / ( d - e ) ) moving left to right until the end of the infix expression  if the item is a number put into the post fix expression  if the item is an open brace push it onto the stack  if the item is an operator pop all operators of lower and equal precedence off of the stack and place them in the postfix expression, then push the operator onto the stack  If the operator is a close brace pop all operators off the stack until an open brace, then delete Convert a + b - c / ( d + e ) to Postfix POSTFIX EXPRESSION = ()( a ( + b - c/

14 1BA3 G Lacey Lecture 514  Algorithm : Place parentheses around the expression ( a + b - c / ( d - e ) ) moving left to right until the end of the infix expression  if the item is a number put into the post fix expression  if the item is an open brace push it onto the stack  if the item is an operator pop all operators of lower and equal precedence off of the stack and place them in the postfix expression, then push the operator onto the stack  If the operator is a close brace pop all operators off the stack until an open brace, then delete Convert a + b - c / ( d + e ) to Postfix POSTFIX EXPRESSION = ()( ab+c- ( ( / d

15 1BA3 G Lacey Lecture 515  Algorithm : Place parentheses around the expression ( a + b - c / ( d - e ) ) moving left to right until the end of the infix expression  if the item is a number put into the post fix expression  if the item is an open brace push it onto the stack  if the item is an operator pop all operators of lower and equal precedence off of the stack and place them in the postfix expression, then push the operator onto the stack  If the operator is a close brace pop all operators off the stack until an open brace, then delete Convert a + b - c / ( d + e ) to Postfix POSTFIX EXPRESSION = ()( ab+c-d ( ( / +e

16 1BA3 G Lacey Lecture 516  Algorithm : Place parentheses around the expression ( a + b - c / ( d - e ) ) moving left to right until the end of the infix expression  if the item is a number put into the post fix expression  if the item is an open brace push it onto the stack  if the item is an operator pop all operators of lower and equal precedence off of the stack and place them in the postfix expression, then push the operator onto the stack  If the operator is a close brace pop all operators off the stack until an open brace, then delete Convert a + b - c / ( d + e ) to Postfix POSTFIX EXPRESSION = ()( ab+c-de ( ( /

17 1BA3 G Lacey Lecture 517  Algorithm : Place parentheses around the expression ( a + b - c / ( d - e ) ) moving left to right until the end of the infix expression  if the item is a number put into the post fix expression  if the item is an open brace push it onto the stack  if the item is an operator pop all operators of lower and equal precedence off of the stack and place them in the postfix expression, then push the operator onto the stack  If the operator is a close brace pop all operators off the stack until an open brace, then delete Convert a + b - c / ( d + e ) to Postfix POSTFIX EXPRESSION = ()( ab+c-de/ ( (

18 1BA3 G Lacey Lecture 518 Evaluate3 2 + 4 3 1 + / * Algorithm : Moving left to right along the post fix expression if the item is a number push it onto the stack if the item is an operator pop two numbers from the stack, execute the operator and push the result back onto the stack when no more items in the postfix string pop the answer off the stack ! + + / * 2 3 1 3 4 5 4 4 5 1 5 5

19 1BA3 G Lacey Lecture 519 Summary of Simple to SML  Concept High Level Language (HLL) translated into Machine Language by a compiler  Production rules translate Simple statements into SML  Code and Data space must be allocated  Maths equations need a more complex rule A sequence of rules – an algorithm The “Stack” data structure is used by the algorithm to convert infix maths expressions into postfix  A stack is also used to evaluate maths expressions  We will return to stacks later in the course

20 20 From Simpletron to 68332

21 1BA3 G Lacey Lecture 521 Basic Computer Architecture

22 1BA3 G Lacey Lecture 522 Simple Overview of the MC6800 The MC6800/MC68332 CPU has: 8 x 32-bit Data Register, D1 to D7 8 x 32-bit Address Register, A1 to A7 1 x 32-bit Program Counter, PC 1 x 16-bit Instruction Register, IR 1 x 16-bit Status Register, SR During one memory access the CPU can access 1 word (16-bit Data Bus). The Program Counter is 32 bits wide, but only 24 bits are used on the Robot (24-bit Address Bus).

23 1BA3 G Lacey Lecture 523 The MC6800 CPU

24 1BA3 G Lacey Lecture 524 The Unit of Memory The fundamental unit of memory is the BIT (Binary Digit) Each bit can take on the value Logic-1 or Logic-0 Accessing these bits individually is not of great use Each value can only be a Logic-1 or Logic-0 (not very useful for storing large numbers!)

25 1BA3 G Lacey Lecture 525 Group BITs Together View memory as a list of larger elements: 4 bits = 1 NYBBLE 8 bits = 1 BYTE 16 bits = 1 WORD 32 bits = 1 LONGWORD When reading data/writing data to/from memory (using the MC68332), we can do so in units of bytes, words or longwords only

26 1BA3 G Lacey Lecture 526 Data Bus The number of bits that can be read at any given time is determent by the BUS SIZE. BUS SIZE = Number of wires (data) connecting the CPU to the Memory

27 1BA3 G Lacey Lecture 527 Memory Capacity Memory size is expressed in terms of bytes: 1024 Bytes = 1 KILOBYTE (Kb.) 1024 Kilobytes = 1 MEGABYTE (Mb.) 1024 Megabyte = 1 GIGABYTE (Gb.) Individual bytes in memory (memory locations) are numbered sequentially.

28 1BA3 G Lacey Lecture 528 Types of Memory: CPU allowed to read and write contents of memory. Commonly known as Random Access Memory [RAM], 2 flavours: Volatile: contents lost when power is switched off. Non-Volatile: holds contents when power is switched off on computer Read Only Memory [ROM]: memory contents are physically etched onto the chip during manufacture. Contents can only be read, and are not lost on power-off.

29 1BA3 G Lacey Lecture 529 More Memory Types Programmable ROM [PROM]: can write contents into it ONCE only (using a device called a PROM Programmer). Henceforth, it acts like ROM. Erasable PROM [EPROM]: a PROM chip that may be written a number of times using an EPROM programmer Electrically Erasable PROM [EEPROM] sometimes called FLASH The robot has: 64Kb RAM 64Kb EPROM

30 1BA3 G Lacey Lecture 530 Memory Location The number of a memory location is it’s address E.g.: The contents of memory location 3 is 67.

31 1BA3 G Lacey Lecture 531 Bit Group Encoding Bit 3Bit 2Bit 1 0 0 0 0 = 0 0 0 0 1 = 1 0 0 1 0 = 2 0 0 1 1 = 3 0 1 0 0 = 4 0 1 0 1 = 5 0 1 1 0 = 6 0 1 1 1 = 7 1 0 0 0 = 8 1 0 0 1 = 9 1 0 1 0 = 10 1 0 1 1 = 11 1 1 0 0 = 12 1 1 0 1 = 13 1 1 1 0 = 14 1 1 1 1 = 15 2 nd Lecture, 1BA3, M. Manzke, Page: 31

32 1BA3 G Lacey Lecture 532 Memory - Address - Bit Address: 3,Bit: 7,6,5,4,3,2,1,0 012 3 45678etc.

33 1BA3 G Lacey Lecture 533 Operating Systems  A computer without software cannot: Load and run programs from disk Perform I/O (Input/Output) Handle situations where the software to run requires more memory than is physically available on the computer  An Operating System = A Program which insulates the user from the technical detail of the machine.

34 1BA3 G Lacey Lecture 534 The MONITOR Michael Manzke, Page: 34 A MONITOR is the simplest form of operating system. It is designed with a minimal specification and allows execution of low level assembly language programs. The monitor is a program (written in assembly language) which provides an interface to the CPU. Using knowledge from this course, you will write your own monitor in second year for a computer system (similar to the Robot) that you will design and build.

35 1BA3 G Lacey Lecture 535 Monitor provides functions to allow:  Writing and editing assembly language code  Assembling of code to machine language  Execution of software  Reading/Writing memory and CPU registers  Connecting to external computer systems for saving and loading of code  Debugging

36 1BA3 G Lacey Lecture 536 Robot Development System Michael Manzke, Page: 36  The RDS contains an Editor: used for writing and saving assembly code Assembler Downloader: loads code onto robot Debugger Terminal emulator: communicates with robot for I/O

37 1BA3 G Lacey Lecture 537 Robot Development System  All software is written/saved on the PC.  Programs are downloaded and executed on the Robot.  The Robot monitor does not allow editing/assembling or saving/printing.  The monitor is saved in ROM  monitor remains even if the power is off.  User programs saved in RAM  program lost when power off.

38 1BA3 G Lacey Lecture 538 Terminal Emulator The TE handles direct communication with the Robot. Every key hit in the TE is sent to the robot. Robot responds with messages which are printed in the TE window.

39 1BA3 G Lacey Lecture 539 Development System Software

40 1BA3 G Lacey Lecture 540 Development Cycle

41 1BA3 G Lacey Lecture 541 How can the monitor and my program run at the same time?  Answer: they don’t. Only one program can run at any given time on the CPU Monitor stops when user program is run. Monitor starts again when user program terminates (hopefully!).

42 1BA3 G Lacey Lecture 542 Program Execution  How does the CPU execute code? The program will exist as numbers in memory The CPU must be told which program to execute (i.e. where code exists in memory - > memory location)


Download ppt "1BA3 G Lacey Lecture 51 Evaluating mathematical expressions  How do computers evaluate x + y or any mathematical expression ?  Answer : “Reverse Polish."

Similar presentations


Ads by Google