1 CS 550 - Programming Languages Random Access Machines Jeremy R. Johnson.

Slides:



Advertisements
Similar presentations
Chapter 10- Instruction set architectures
Advertisements

The Little man computer
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
LC-3 Computer LC-3 Instructions
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Some thoughts: If it is too good to be true, it isn’t. Success is temporary. It is hard work to make it simple. Knowing you did it right is enough reward.
Chapter 5 The LC-3 LC-3 Computer Architecture Memory Map
Translating high level language into machine code
Chapter 6 Programming in Machine Language The LC-3 Simulator
Chapter 4 H1 Assembly Language: Part 2. Direct instruction Contains the absolute address of the memory location it accesses. ld instruction:
Dale & Lewis Chapter 5 Computing components. Let’s design a computer Generic CPU with registers −Program counter (PC) – 5 bits (size of addresses) −Instruction.
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
MIPS Instruction Set Advantages
Lecture 18 Last Lecture Today’s Topic Instruction formats
Computer Architecture and the Fetch-Execute Cycle
June 18, 2001Systems Architecture II1 Systems Architecture II Systems Architecture I Review * Jeremy R. Johnson June 18, 2001 * Most figures from Computer.
Lec 1Systems Architecture1 Systems Architecture Lecture 1: Random Access Machines Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some material.
Lecture 1 Introduction to Computing Machinery. Colossus Joseph Marie Jacquard Charles Babbage Augusta Ada Countess of Lovelace.
Chapter 5 The LC Instruction Set Architecture ISA = All of the programmer-visible components and operations of the computer memory organization.
Model Computer CPU Arithmetic Logic Unit Control Unit Memory Unit
Execution of an instruction
1 Ethics of Computing MONT 113G, Spring 2012 Session 7 Computer Architecture The Internet.
Kirk Scott Computer Science The University of Alaska Anchorage 1.
Program Design. The design process How do you go about writing a program? –It’s like many other things in life Understand the problem to be solved Develop.
Assembly Language Friday, Week 5 Monday, Week 6. Assembly Language  Set of mnemonic names for the instructions in a particular computer's machine language.
September 26, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 2: Implementation of a Simplified Computer Jeremy R. Johnson Wednesday,
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
© GCSE Computing Candidates should be able to:  describe the characteristics of an assembler Slide 1.
COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent.
Computer Systems Organization
Dale & Lewis Chapter 5 Computing components
Fundamentals of Informatics Lecture 4 From Turing Machines to Algorithms Bas Luttik.
Assembly Language Programming of 8085 BY Prof. U. V. THETE Dept. of Computer Science YMA.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Jeremy R. Johnson William M. Mongan
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Mastering LMC Coding Part #1 Introduction to Low Level Languages Introduction to Little Man computer Simple examples (demos) with video tutorials included.
F453 Module 8: Low Level Languages 8.1: Use of Computer Architecture.
Computer Science 210 Computer Organization Machine Language Instructions: Control.
PROGRAMMING THE BASIC COMPUTER
The Little man computer
Unit 1 Instruction set M.Brindha AP/EIE
PROGRAMMING THE BASIC COMPUTER
CS 270: Mathematical Foundations of Computer Science
Overview of Instruction Set Architectures
MIPS Instruction Set Advantages
Assembly Language Programming of 8085
Microprocessor T. Y. B. Sc..
PROGRAMMING THE BASIC COMPUTER
3.Instruction Set of 8085 Consists of 74 operation codes, e.g. MOV
1. Introduction A microprocessor executes instructions given by the user Instructions should be in a language known to the microprocessor Microprocessor.
A Closer Look at Instruction Set Architectures: Expanding Opcodes
CS-401 Assembly Language Programming
Chapter 5 The LC-3.
The Processor and Machine Language
Programming Languages (CS 550) Mini Language Compiler
Systems Architecture I (CS ) Lecture 1: Random Access Machines
PROGRAMMING THE BASIC COMPUTER
Computer Science 210 Computer Organization
Systems Architecture I (CS ) Lecture 2: A Simplified Computer
ECEG-3202 Computer Architecture and Organization
Computer Architecture
PROGRAMMING THE BASIC COMPUTER
University of Gujrat Department of Computer Science
Program Execution.
Chapter 6 Programming the basic computer
Systems Architecture I (CS ) Lecture 1: Random Access Machines
CPSC 171 Introduction to Computer Science
Programming Languages (CS 360) Mini Language Compiler
Little Man Computer.
Presentation transcript:

1 CS Programming Languages Random Access Machines Jeremy R. Johnson

2 Introduction  Objective: To introduce a simple model of a computer that will be used to operationally define the semantics of the Mini Language. In the following lecture, a compiler will be constructed that translates Mini Language Programs to equivalent programs that execute on a RAM using RAM assembly language (RAL).  A Random Access Machine (RAM) is an abstract model of computation that resembles a simple idealized computer. It is equivalent in computational power to a Turing machine (can perform any computation). Despite its simplicity it provides some intuition as to how a program executes on a computer. In practice the size of the memory is bounded.

3 Definition of a RAM  Defined by a set of instructions and a model of execution.  A program for a RAM is a sequence of instructions.  A RAM has an infinite memory. Instructions can read and write to memory. Items from memory are loaded into registers, where arithmetic can be performed.  The state of a computation: program counter (to keep track of instruction to execute), registers, and memory.

4 A Random Access Machine Control Unit AC Program Memory AC = accumulator register

5 Instruction Set  LDA X; Load the AC with the contents of memory address X  LDI X; Load the AC indirectly with the contents of address X  STA X; Store the contents of the AC at memory address X  STI X; Store the contents of the AC indirectly at address X  ADD X; Add the contents of address X to the contents of the AC  SUB X; Subtract the contents of address X from the AC  JMP X; Jump to the instruction labeled X  JMZ X; Jump to the instruction labeled X if the AC contains 0  JMN X; Jump to the instruction labeled X if the contents of the AC ; is negative  HLT ; Halt execution

6 Sample Program STOR ; algorithm to detect duplicates in an array A of size n. for i  1 to n do if B(A(i))  0 then output A(i); exit else B(A(i)) = 1

7 Sample RAM Program 1. LDI 3; get ith entry from A 2. ADD 4; add offset to compute index j 3. STA 5; store index j 4. LDI 5; get jth entry from B 5. JMZ 9; if entry 0, go to 9 6. LDA 3; if entry 1, get index i 7. STA 2; and store it at HLT ; stop execution 9. LDA 1; get constant STI 5; and store it in B 11. LDA 3; get index i 12. SUB 4; subtract limit 13. JMZ 8; if i = limit, stop 14. LDA 3; get index i again 15. ADD 1; increment i 16. STA 3; store new value of i 17. JMP 1; AC 1 Memory 1 constant 2 0answer 3 6Index i 4 9 Limit of A 5 0Index j A B

8 Exercises  Modify STOR so that when a computation finishes and the input sequence contained a duplicate integer, we know what that integer was.  Modify STOR so that it uses array indexing when accessing the array A instead of pointer arithmetic (i.e. the index into A should be an array index, starting with 1, rather than an address of a location in the array).  Write a RAL program which takes two input integers at addresses 1 and 2 and multiplies them storing the result at address 4.

9 Sample Solution compute x*y, x,y >= 0 1. LDA 1; load x 2. JMZ 10; check if x = 0 3. LDA 4; load partial result 4. ADD 2; add y to partial result 5. STA 4; store partial result 6. LDA 1; load x 7. SUB 3; and decrement 8. STA 1; store decremented x 9. JMP 2; next iteration 10. HLT ; AC 1 Memory x value of x 2 yValue of y 3 1Constant result The program still works with y < 0; however, if x < 0, it will go into an infinite loop (x will never = 0). To allow x < 0, first check to see if x is negative with JMN, and if so we want to increment x rather than decrement it.