We will use the accumulator machine architecture to demonstrate pass1 and pass2.



Similar documents
An Introduction to Assembly Programming with the ARM 32-bit Processor Family

Notes on Assembly Language

1 Classical Universal Computer 3

EC 362 Problem Set #2

Summary of the MARIE Assembly Language

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

Translating C code to MIPS

Here is a diagram of a simple computer system: (this diagram will be the one needed for exams) CPU. cache

The previous chapter provided a definition of the semantics of a programming

The Little Man Computer

Reduced Instruction Set Computer (RISC)

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings:

Central Processing Unit (CPU)

Chapter 2 Topics. 2.1 Classification of Computers & Instructions 2.2 Classes of Instruction Sets 2.3 Informal Description of Simple RISC Computer, SRC

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8

1 Description of The Simpletron

Instruction Set Design

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Typy danych. Data types: Literals:

Instruction Set Architecture (ISA)

M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE

Computer organization

What to do when I have a load/store instruction?

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

Administrative Issues

Instruction Set Architecture

PROBLEMS #20,R0,R1 #$3A,R2,R4

Lecture 3 Addressing Modes, Instruction Samples, Machine Code, Instruction Execution Cycle

HC12 Assembly Language Programming

High level code and machine code

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Systems I: Computer Organization and Architecture

Object Oriented Software Design

Chapter 7D The Java Virtual Machine

OAMulator. Online One Address Machine emulator and OAMPL compiler.

Lecture Outline. Stack machines The MIPS assembly language. Code Generation (I)

Microprocessor/Microcontroller. Introduction

MIPS Assembly Code Layout

6. Control Structures

How To Write An Array In A Microsoft Zil

CPU Organization and Assembly Language

Lecture 2 Notes: Flow of Control

MIPS Assembler and Simulator

Flowchart Techniques

PROBLEMS (Cap. 4 - Istruzioni macchina)

Compilers I - Chapter 4: Generating Better Code

Instruction Set Reference

Central Processing Unit Simulation Version v2.5 (July 2005) Charles André University Nice-Sophia Antipolis

EECS 427 RISC PROCESSOR

THUMB Instruction Set

In this Chapter you ll learn:

Computer Architecture Lecture 2: Instruction Set Principles (Appendix A) Chih Wei Liu 劉 志 尉 National Chiao Tung University

Informatica e Sistemi in Tempo Reale

Chapter 7 Assembly Language

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Computer Organization and Architecture

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

MICROPROCESSOR AND MICROCOMPUTER BASICS

PIC 10A. Lecture 7: Graphics II and intro to the if statement

CSE 141L Computer Architecture Lab Fall Lecture 2

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

BASIC COMPUTER ORGANIZATION AND DESIGN

Assembly Language Programming

MACHINE ARCHITECTURE & LANGUAGE

CS101 Lecture 26: Low Level Programming. John Magee 30 July 2013 Some material copyright Jones and Bartlett. Overview/Questions

LC-3 Assembly Language

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

M6800. Assembly Language Programming

Computer Systems Architecture

2) Write in detail the issues in the design of code generator.

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

The 104 Duke_ACC Machine

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

CPU Organisation and Operation

Microprocessor & Assembly Language

Introduction to the Altera Nios II Soft Processor. 1 Introduction. For Quartus II 11.1

The WIMP51: A Simple Processor and Visualization Tool to Introduce Undergraduates to Computer Organization

CHAPTER 7: The CPU and Memory

Object Oriented Software Design

Moving from CS 61A Scheme to CS 61B Java

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall

Fall 2006 CS/ECE 333 Lab 1 Programming in SRC Assembly

ASSEMBLY LANGUAGE PROGRAMMING (6800) (R. Horvath, Introduction to Microprocessors, Chapter 6)

While Loop. 6. Iteration

Z80 Instruction Set. Z80 Assembly Language

8085 INSTRUCTION SET

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Visual Logic Instructions and Assignments

X86-64 Architecture Guide

A SystemC Transaction Level Model for the MIPS R3000 Processor

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

The Java Virtual Machine (JVM) Pat Morin COMP 3002

(Refer Slide Time: 00:01:16 min)

Addressing The problem. When & Where do we encounter Data? The concept of addressing data' in computations. The implications for our machine design(s)

4 Machine Language. Make everything as simple as possible, but not simpler. Albert Einstein ( )

EE282 Computer Architecture and Organization Midterm Exam February 13, (Total Time = 120 minutes, Total Points = 100)

Transcription:

Accumulator machine We will use the accumulator machine architecture to demonstrate pass1 and pass2. The accumulator machine - has one processor register: the accumulator - all other operands are in memory, and expressions require a sequence of load/operate/store instructions.

accumulator machine instruction set opcode address operation name machine action halt ---- halt stop execution div addr divide acc = acc/memory[addr] mul addr multiply acc = acc*memory[addr] sub addr subtract acc = acc-memory[addr] add addr add acc = acc+memory[addr] load addr load acc = memory[addr] store addr store memory[addr] = acc ba addr branch always pc = addr blt0 addr branch on less than if acc<0 then pc = addr ble0 addr branch on less than or equal if acc<=0 then pc = addr beq0 addr branch on equal if acc==0 then pc = addr bne0 addr branch on not equal if acc/=0 then pc = addr bge0 addr branch on greater than or equal if acc>=0 then pc = addr bgt0 addr branch on greater than if acc>0 then pc = addr print addr print display contents of memory[addr]

assembly language pseudo-ops name arg1 arg2 meaning comment text allows for comments within program end symbol defines starting address of program (should appear once, as the last line of the program) label symbol defines a symbolic address within the program word symbol value defines a symbol address and allocates a data word at that address with the given value

Accumulator machine program - example 1 comment(` first example accumulator machine program ') comment(` ') comment(` data section for program -- word(label,value) ') word(a, 0) word(b, 3) word(c, 48) word(d, 9) comment(`code that implements the expression a = b + c - d;') label(start) load(b) comment(` ACC <- memory[b] ') add(c) comment(` ACC <- ACC + memory[c] ') sub(d) comment(` ACC <- ACC - memory[d] ') store(a) comment(` memory[a] <- ACC ') halt comment(` start execution at label start ') end(start)

Accumulator machine executable is in numeric format -- example assembly (numbers are in decimal rather than binary) the assembler has a location counter variable called "loc" that it uses in the first pass to assign addresses

accumulator machine instruction table (built into assembler) name opcode args loc increment add 40 $1 2 <- add is defined as two words sub 30 $1 2 * first word is opcode 40 load 50 $1 2 * second word is address of arg store 60 $1 2 * loc should be incremented by 2 halt 00 1

accumulator machine Pass 1 first pass input -- symbol table after first pass assembly stmts label addr==loc word(a,0) a 00 <- a is defined as location 00 word(b,3) b 01 <- b is defined as location 01 word(c,48) c 02 <- c is defined as location 02 word(d,9) d 03 <- d is defined as location 03 label(start) start 04 <- start defined as location 04... << no other statements define labels >>...

accumulator machine Pass 2 second pass input "executable" after second pass (loc:) assembly language addr: machine code or data (00:) word(a,0) 00: 0 <- value in location a (01:) word(b,3) 01: 3 <- value in location b (02:) word(c,48) 02: 48 <- value in location c (03:) word(d,9) 03: 9 <- value in location d label(start) (04:) load(b) 04: 50 <- opcode for load 05: 01 <- address of b (06:) add(c) 06: 40 <- opcode for add 07: 02 <- address of c (08:) sub(d) 08: 30 <- opcode for sub 09: 03 <- address of d (10:) store(a) 10: 60 <- opcode for store 11: 00 <- address of a (12:) halt 12: 00 <- opcode for halt (13:) end(start) 13: 04 <- starting address

Control structures in assembly language int x; int y; if(x == 0) y = 1; (false) x == 0? y = 1 (true) x == 0 /* assume values for x, y, and one */ exit C Source Code Ineffficient Assembly Efficient Assembly int x; int y; if(x == 0) y = 1; load(x) beq0 true ba false label(true) load(one) store(y) label(false)... load(x) bne0 else label(true) load(one) store(y) label(false)...

C if statement in accumulator machine code if((x+b)>z) x+=y; Accumulator machine code: /* assume x, b, y, z have values*/ (false) x+y > z? load(x) exit add(b) sub(z) ble0(false) comment(` branch to false ) load(x) add(y) store(x) label(false) x += y (true) (x+y)>z

C if-else statement in accumulator machine code if(i == j) f=g+h; else f=g-h; Accumulator code: /* assume values for f, i, j, g, and h */ load(i) sub(j) beq0(true) load(g) sub(h) ba(done) label(true) load(g) add(h) label(done) store(f) (true) i == j f=g+h i == j? exit f=g-h (false) i!= j

Loops Implementing Loops All for loops, while loops, and do-while loops have an implicit branch from the bottom to the top of the loop. This branch instruction becomes explicit when translated into assembly. while ( x <= 10 )... { load(x) x = x + y; label(loop) } sub(ten) bgt0(done) load(x) add(y) store(x) ba(loop) label(done) test condition; exit loop if false body of loop; also updates the lcv

Loops Alternate implementation: (eliminates one of the branch instructions in the loop) while ( x <= 10 )... { load(x) x = x + y; sub(ten) } bgt0(done) label(loop) load(x) add(y) store(x) sub(ten) ble0(loop) label(done) test condition; skip loop if false body of loop; also updates the lcv test condition; loop again if true

Loops in C/Assembly (accumulator machine code) for loop for ( x = 1; x <= y; x++ ) load(one) { store(x) z *= x; label(loop) } sub(y) bgt0(done) rewritten as while loop load(z) mul(x) x = 1; store(z) while ( x <= y ) load(x) { add(one) z *= x; store(x) x++; ba(loop) } label(done) test condition; exit loop if false loop body update lcv

Loops in C/Assembly (accumulator machine code) for loop - alternate implementation (eliminates one of the branches in the loop) for ( x = 1; x <= y; x++ ) load(one) { store(x) z *= x; sub(y) } bgt0(done) label(loop) load(z) rewritten as while loop mul(x) x = 1; store(z) while ( x <= y ) load(x) { add(one) z *= x; store(x) x++; ble0(loop) } label(done) test condition; skip loop if false loop body update lcv test condition; loop again if true

accumulator machine program example 2 comment(` second example accumulator machine program ) comment(` code that implements the loop ') comment(` sum = 0; ') comment(` for( i = 10; i > 0; i-- ){ ') comment(` sum = sum + i; ') comment(` } ') label(begin) load(zero) store(sum) load(ten) store(i) label(loop) load(i) ble0(done) comment(` sum = 0 ACC <- memory[zero] ') comment(` memory[sum] <- ACC ') comment(` i = 10 ') comment(` branch to done if i <= 0 ')

accumulator machine program example 2 (cont d) load(sum) comment(` sum = sum + i ') add(i) store(sum) load(i) comment(` i = i - 1 ') sub(one) store(i) ba(loop) comment(` unconditionally go back to loop ') label(done) halt comment(` data section for program - can be at bottom ') word(sum,0) word(i,0) word(zero,0) word(one,1) word(ten,10) comment(` start execution at label begin ') end(begin)