Translating high level language into machine code

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

The LC-3 – Chapter 6 COMP 2620 Dr. James Money COMP
Chapter 10- Instruction set architectures
 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
2.3) Example of program execution 1. instruction  B25 8 Op-code B means to change the value of the program counter if the contents of the indicated register.
CARDIAC A cardboard illustrative aid to computation illustrates the operation of a computer demos basic units of a simple computer –input –memory –accumulator.
LC-3 Computer LC-3 Instructions
Intoduction First we’ll talk in general about Visual X-Toy Then we’ll input and run a program using switches Then we’ll look at the more advanced editor.
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.
CSCE 212 Quiz 8 – 3/23/11 1.What type of element is the ALU (combinational or state) and what does it mean for an element to be that type? 2.What is the.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
Classifying Instruction Set Architectures
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Stored Program Concept: The Hardware View
Classifying Instruction Set Architectures
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
1 CS Programming Languages Random Access Machines Jeremy R. Johnson.
Assembly & Machine Languages
Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
1 Programming in Machine Language SCSC 311 Spring 2011.
Cosc 2150: Computer Organization
1 Pipelining Reconsider the data path we just did Each instruction takes from 3 to 5 clock cycles However, there are parts of hardware that are idle many.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
Execution of an instruction
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Assembly Language CS 333 Sam Houston State University Dr. Tim McGuire.
1 Ethics of Computing MONT 113G, Spring 2012 Session 7 Computer Architecture The Internet.
A summary of TOY. 4 Main Components Data Processor Control Processor Memory Input/Output Device.
CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
Lecture 11: 10/1/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Small constants are used quite frequently (50% of operands) e.g., A = A + 5; B = B + 1; C = C - 18; Solutions? Why not? put 'typical constants' in memory.
Assembly Language Friday, Week 5 Monday, Week 6. Assembly Language  Set of mnemonic names for the instructions in a particular computer's machine language.
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.
1 The Instruction Set Architecture September 27 th, 2007 By: Corbin Johnson CS 146.
More on Pipelining 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Arrays and Strings in Assembly
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Assembly Language CS 333 Sam Houston State University Dr. Tim McGuire.
Simple ALU How to perform this C language integer operation in the computer C=A+B; ? The arithmetic/logic unit (ALU) of a processor performs integer arithmetic.
More on Pipelining 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Elements of Datapath for the fetch and increment The first element we need: a memory unit to store the instructions of a program and supply instructions.
Computer Organization Instructions Language of The Computer (MIPS) 2.
1 Basic Processor Architecture. 2 Building Blocks of Processor Systems CPU.
Introduction to Computing Systems and Programming The LC-2.
Program to multiply 2 numbers 500-Input x 291-Store acc. as x 500-Input y 292-Store acc. as y 193-Load y in to acc. (0 on 1 st parse) 391-Add x to acc.
Recap – Our First Computer WR System Bus 8 ALU Carry output A B S C OUT F 8 8 To registers’ read/write and clock inputs Sequence of control signal combinations.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Instruction Memory value Description ADD1xx Add the value stored at memory address xx to the value in the accumulator register SUB2xx Subtract the value.
Machine and Assembly Language
William Stallings Computer Organization and Architecture 8th Edition
Chapter 5 The LC-3.
The Processor and Machine Language
6.001 SICP Stacks and recursion
LC-3 Details and Examples
Computer Programming Machine and Assembly.
Systems Architecture I (CS ) Lecture 1: Random Access Machines
CSCE Fall 2013 Prof. Jennifer L. Welch.
Computer Science 210 Computer Organization
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers.
Sequencing, Selection, and Loops in Machine Language
Suppose I want to add all the even integers from 1 to 100 (inclusive)
CSCE Fall 2012 Prof. Jennifer L. Welch.
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers.
MIPS assembly.
Systems Architecture I (CS ) Lecture 1: Random Access Machines
Presentation transcript:

Translating high level language into machine code XToy Programming Translating high level language into machine code

1) int a = 8; 2) int b = 5; 3) int c = a + b; program Add // Input: Stored in memory location 00 and 01 // Output: Sum of two integers 5 + 8 = D // saved in memory location 02 Machine code High level language 00: 0008 8 01: 0005 5 02: 0000 0 10: 8A00 R[A] <- mem[00] 11: 8B01 R[B] <- mem[01] 12: 1CAB R[C] <- R[A] + R[B] 13: 9C02 mem[02] <- R[C] 14: 0000 halt 1) int a = 8; 2) int b = 5; 3) int c = a + b; 0) 8 has to be in memory 0) 5 has to be in memory 1) put contents of memory location 00 into register A 2) put contents of memory location 01 into register B 3) put results of addition into register C 0) save contents of register C into memory location 2

// Input: Sequence of non-zero integers, followed by 0000 program Sum // Input: Sequence of non-zero integers, followed by 0000 // Output: The sum of all the integers High level language Machine code 1) sum = 0 ; 2) while (true) 3) { 4) read a ; 5) if (a == 0) break ; 6) sum = sum + a ; 7) } 8) write sum ; 10: 7C00 RC <- 0000 11: 8AFF read RA 12: CA15 if (RA == 0) pc <- 15 13: 1CCA RC <- RC + RA 14: C011 pc <- 11 15: 9CFF write RC 16: 0000 halt 1) We could store 0 in a register (e.g. C) 2) Its an infinite loop so we must come back here when line 7 is executed 4) Read in a value from stdin and save in register A 5) If the value we read in is zero .. then finish .. ie jump to line 8 6) Add contents of register A to the current value in register C 7) Jump back to line 2 8) When we do finish we print out answer to user

Now we can see the benefits of “pseudo-code”. 10: 8A0A RA <- mem[0A] 11: 8B0B RB <- mem[0B] 12: 8C0D RC <- mem[0D] 13: 810E R1 <- mem[0E] 14: CA18 if (RA == 0) pc goto 18 15: 1CCB RC <- RC + RB 16: 2AA1 RA <- RA - R1 17: C014 pc <- 14 18: 9C0C mem[0C] <- RC 19: 0000 halt

TOY idioms Register-to-register transfer. Suppose you want to make register 2 have the same value as register 1. There is no built-in instruction to do this. Relying on the fact that register 0 always contains 0000, we can use the addition instruction to sum up R0 and R1 and put the result in R2. 10: 1201 R[2] <- R[0] + R[1]

TOY idioms No-op In a structured programming language like Java inserting extra code is easy. But in an unstructured language like TOY (where there are line numbers and goto statements), you must be careful about inserting code. A branch statement hardwires in the memory address to jump to; if you insert code, the line numbers of your program may change. To avoid some of this awkwardness, machine language programmers often find it convenient to fill in the program with "useless" statements to act as placeholders. Such statements are called no-ops because they perform no operation. The instruction 1000 is ideal for this purpose since register 0 is always 0 anyway. (The instruction 10xy would also be a no-op for any values of x and y because register 0 always contains 0, regardless of how you might try to change it.

TOY idioms Goto There is no instruction that directly changes the program counter to the particular address. Like a GOTO statement However, it is easy to use the “branch if zero” instruction with register 0 to achieve the same effect. For example, the instruction C0F0 changes the program counter to F0 since register 0 is always 0. So its like saying GOTO FO

Arrays Arrays are not directly built into the TOY language, but it is possible to achieve the same functionality using the load address, load indirect, and store indirect instructions. We consider a program that reads in a sequence of integers and prints them in reverse order.

Reads in a sequence of integers and prints them in reverse order.