Accumulator machine We will use the accumulator machine architecture to demonstate pass1 and pass2. The accumulator machine has one processor register:

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

Goal: Write Programs in Assembly
Lecture 5: MIPS Instruction Set
MIPS assembly. Review  Lat lecture, we learnt  addi,  and, andi, or, ori, xor, xori, nor,  beq, j, bne  An array is stored sequentially in the memory.
Branches Two branch instructions:
Control Structures in ARM Implementation of Decisions Similar to accumulator instructions One instruction sets the flags, followed by another instruction.
Comp Sci Control structures 1 Ch. 5 Control Structures.
The Little man computer
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
19-1 Programming… The Pencil and Paper Computer The Pencil & Paper Instruction Set: (table on p148) The Operand specifies a memory location.
CS 61C L09 Introduction to MIPS: Data Transfer & Decisions I (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Assembly Language Programming. CPU The CPU contains a Control Unit, Arithmetic Logic Unit (ALU) and a small number of memory locations called Registers.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
MIPS Instruction Set Advantages
9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.
CEG 320/520: Computer Organization and Assembly Language ProgrammingFlow Control 1 Flow Control.
Machine Instruction Characteristics
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Cosc 2150: Computer Organization
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
Computer Science 101 How the Assembler Works. Assembly Language Programming.
Lecture 15 Today’s lecture MARIE programming Assembler
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Lecture 4: MIPS Instruction Set
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
Chapter 2 Decision-Making Instructions (Instructions: Language of the Computer Part V)
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Our programmer needs to do this !
The Assembly Process Computer Organization and Assembly Language: Module 10.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Ch2a- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Taking orders A computer does what you tell it to do Not necessarily what.
Question 21 - Exercise 1 List any improvements for the following code segment: load(length) sub(fifty) bgt0(false) load(four) store(height) ba(done) label(false)
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Computer Science 210 Computer Organization Machine Language Instructions: Control.
ARM Instructions ARM instructions are written as an operation code (opcode), followed by zero or more operands Operands may be constants (8-bit value),
Computer Architecture. Instruction Set “The collection of different instructions that the processor can execute it”. Usually represented by assembly codes,
The Little man computer
MIPS Instruction Set Advantages
CS2100 Computer Organisation
Assembly Language Assembly Language
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
Decision Making.
Processor Instructions set. Learning Objectives
The Processor and Machine Language
Instructions for Making Decisions
Pick up the handout on your way in!!
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Computer Science 210 Computer Organization
CSC 3210 Computer Organization and Programming
MIPS Instruction Encoding
MIPS Instruction Encoding
Programmer’s View of the EAGLE
The University of Adelaide, School of Computer Science
Sequencing, Selection, and Loops in Machine Language
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
Chapter 6 Programming the basic computer
MIPS assembly.
CS501 Advanced Computer Architecture
9/27: Lecture Topics Memory Data transfer instructions
Conditional Control Structure
MIPS instructions.
Conditional Branching (beq)
Presentation transcript:

Accumulator machine We will use the accumulator machine architecture to demonstate 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 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; /* assume values for x, y, and one */ exit x == 0? y = 1 (false) (true) x == 0 C Source Code Ineffficient Assembly Efficient Assembly int x; int y; if(x == 0) y = 1; load(x) beq0 then ba false label(true) load(one) store(y) label(false) . . . bne0 false 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*/ load(x) add(b) sub(z) ble0(false) comment(` branch to false’) add(y) store(x) label(false) exit x+y > z? x += y (false) (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) add(h) label(done) store(f) exit i == j? f=g+h f=g-h (false) i != j (true) 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 for loop for ( x = 1; x <= y; x++ ) load(one) { store(x) z *= x; label(loop) } sub(y) bgt0(done) load(z) rewritten as while loop 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) 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) comment(` sum = 0 ACC <- memory[zero] ') store(sum) comment(` memory[sum] <- ACC ') load(ten) comment(` i = 10 ') store(i) label(loop) load(i) comment(` branch to done if i <= 0 ') ble0(done)

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)