CompSci 001 23.1 Today’s topics Machine Architecture The basic machine Basic programming Assembler programming Upcoming Language Translation Reading Great.

Slides:



Advertisements
Similar presentations
Computer Architecture and the Fetch-Execute Cycle
Advertisements

Chapter 10- Instruction set architectures
Chapter 2 Machine Language.
 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
Computer Organization and Architecture
CompSci A Peek at the Lower Levels  It is good to have a sense of what happens at the hardware level  Not required for this course  It may.
The Little man computer
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
Snick  snack A Working Computer Slides based on work by Bob Woodham and others.
Room: E-3-31 Phone: Dr Masri Ayob TK 2123 COMPUTER ORGANISATION & ARCHITECTURE Lecture 5: CPU and Memory.
Processor Technology and Architecture
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Stored Program Concept: The Hardware View
Chapter 7 Low-Level Programming Languages. 2 Chapter Goals List the operations that a computer can perform Discuss the relationship between levels of.
Chapter 4 Processor Technology and Architecture. Chapter goals Describe CPU instruction and execution cycles Explain how primitive CPU instructions are.
Recap – Our First Computer WR System Bus 8 ALU Carry output A B S C OUT F 8 8 To registers’ input/output and clock inputs Sequence of control signal combinations.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
Processor Structure & Operations of an Accumulator Machine
Instruction Sets and Pipelining Cover basics of instruction set types and fundamental ideas of pipelining Later in the course we will go into more depth.
An Introduction Chapter Chapter 1 Introduction2 Computer Systems  Programmable machines  Hardware + Software (program) HardwareProgram.
Topics Introduction Hardware and Software How Computers Store Data
1 Machine Language Alex Ostrovsky. 2 Introduction Hierarchy of computer languages: 1. Application-Specific Language (Matlab compiler) 2. High-Level Programming.
CS 1308 Computer Literacy and the Internet Computer Systems Organization.
Levels of Architecture & Language CHAPTER 1 © copyright Bobby Hoggard / material may not be redistributed without permission.
COMP2011 Assembly Language Programming and Introduction to WRAMP.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Chapter 5: Computer Systems Organization Invitation to Computer Science, Java Version, Third Edition.
Cosc 2150: Computer Organization
Computer Systems Organization CS 1428 Foundations of Computer Science.
CPS Today’s topics Machine Architecture More Low-level Programming Upcoming Language Translation ( G.I. Chapter 9) Reading Great Ideas, Chapters.
Computer Architecture and the Fetch-Execute Cycle
Microcode Source: Digital Computer Electronics (Malvino and Brown)
Computer Architecture And Organization UNIT-II Structured Organization.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
Cis303a_chapt04.ppt Chapter 4 Processor Technology and Architecture Internal Components CPU Operation (internal components) Control Unit Move data and.
The Central Processing Unit (CPU) and the Machine Cycle.
Execution of an instruction
Lecture 14 Today’s topics MARIE Architecture Registers Buses
PHY 201 (Blum)1 Microcode Source: Digital Computer Electronics (Malvino and Brown)
1 Ethics of Computing MONT 113G, Spring 2012 Session 7 Computer Architecture The Internet.
Computer Architecture Memory, Math and Logic. Basic Building Blocks Seen: – Memory – Logic & Math.
1 Text Reference: Warford. 2 Computer Architecture: The design of those aspects of a computer which are visible to the programmer. Architecture Organization.
Computer Architecture 2 nd year (computer and Information Sc.)
© GCSE Computing Candidates should be able to:  describe the characteristics of an assembler Slide 1.
1.4 Representation of data in computer systems Instructions.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
1 The Instruction Set Architecture September 27 th, 2007 By: Corbin Johnson CS 146.
CMSC 104, Lecture 061 Stored Programs A look at how programs are executed.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
F453 Module 8: Low Level Languages 8.1: Use of Computer Architecture.
The Little man computer
Topics Introduction Hardware and Software How Computers Store Data
Control Unit Lecture 6.
Computer Architecture
Introduction to Assembly Language
CSCE Fall 2013 Prof. Jennifer L. Welch.
Topics Introduction Hardware and Software How Computers Store Data
MARIE: An Introduction to a Simple Computer
MARIE: An Introduction to a Simple Computer
CSCE Fall 2012 Prof. Jennifer L. Welch.
A Level Computer Science Topic 5: Computer Architecture and Assembly
Objectives Describe common CPU components and their function: ALU Arithmetic Logic Unit), CU (Control Unit), Cache Explain the function of the CPU as.
Presentation transcript:

CompSci Today’s topics Machine Architecture The basic machine Basic programming Assembler programming Upcoming Language Translation Reading Great Ideas, Chapters 9

CompSci Computer Architecture  Definition of computer architecture  The programmer’s view of the computer hardware  Hardware – Software Boundary  Not well defined  Much hardware is programmed  Some hardware instantiates programming steps  An imbedded program that cannot be changed could be called hardware  Firmware  Sometimes used to describe programming that is seldom changed  Typically stored in read-only memory (cannot change)

CompSci Basic Computer  Extremely Primitive  Cannot understand any Java or English-like commands  There is no command to carry out the while statement  Make up in speed what it gives up in complexity  Use a translator to transform program to machine’s native language  Called compiler  High-level language like Java called the source language  Target language is called machine language  Machine language is what the hardware responds to

CompSci Machine Language  Machine language is the most primitive  Everything represented by numbers  At hardware level, numbers are in binary  Numbers represent instructions (code)  AND Numbers represent data  Context of use decides whether number is data or instruction  In practice, seldom program in machine language  Use a language, very close to machine language called Assembler Language  Symbolic in nature (as opposed to numeric)  Each instruction number has a mnemonic  E.g., 12 is ADD  Locations also given names (sometimes variable name)

CompSci Architectural Features  Memory  Central Processing Unit (CPU) seen as set of Registers IP: Instruction pointer IR: Instruction Register AX: Arithmetic Register/Accumulator CF: Condition Flag

CompSci Simple Program  Show in assembler rather than machine language copyax, x addax, y copyz, ax  Implements z = x + y;  Remember, really ALL NUMBERS  Could be:  If copy -into = 20, add = 12, and copy -out = 21 and x is stored in 101, y in 102, and z in 103

CompSci Fetch - Execute Cycle  Clock systematically leads machine cycle thru steps  FETCH  Get instruction from memory o IP register (also called program counter or PC) says where from  Increment IP (to point to next instruction)  EXECUTE  Decode instruction o Figure out what is wanted (add?, copy? …) o Extract memory address from instruction o If needed, get info from memory  Carry out instruction o I.e., add info to Accumulator (AX)

CompSci More Instructions  copy and add  Implicit right to left movement  Most instructions involve accumulator (AX)  in and out  Like getInt and setInt in Java  in goes from keyboard to AX  out goes from AX to screen  Go through another example -- program to perform: { x = a.getInt(); y = b.getInt(); z = (x + y); c.setInt(z); }

CompSci sum.as 0 in ax 1 copy x, ax 2 in ax 3 copy y, ax 4 copy ax, x 5 add ax, y 6 copy z, ax 7copy ax, z 8 out ax 20x 0 21y 0 23z 0 Sample I/O: <23 <16 >39

CompSci More Instructions  Need to handle Java if and while instructions  Use cmp instruction  Compares values in AX and memory location  Sets carry flag (CF) to oB below (AX less than memory) or oNB not below (AX greater or equal to memory)  Use jump instructions to take advantage of this new info  jnb instruction jumps to new location if CF set to NB  jb instruction jump to new location if CF set to B  jmp always jumps, regardless of CF state  Can now implement code involving if

CompSci largest.as Program to write out the larger of two numbers read in: in ax copy r, ax in ax copy s, ax copy ax, s cmp ax, r jnb there copy ax, r out ax jmp quit there copy ax, s out ax quit halt r 0 s 0 Sample I/O: 44

CompSci Tracing  Tracing is often the only way to figure out assembler programs  Number your statements (for reference) o Can also use actual memory addresses if known  Set up column heading for variables (memory) expected to change  Step through the program o You play to role of computer o Use notes and/or extra columns to keep track of  Input and output  State of the Condition Flags (CF)  Trace with test data o Until done or o Until program is understood

CompSci Programming Loops  Now use new instructions to do the equivalent of while  We noted that syntax for if and while were same  Assembler code surprisingly similar for these two  Major addition is the update  Also need to jump back to beginning of loop  Demonstrate with code equivalent to: { limit = 0; sum = 0; x = a.getInt(); while (limit < x) { sum = (sum + x); x = a.getInt(); } b.setInt(sum); }

CompSci summer.as 0 copy ax, #C0 1 copy limit, ax 2 copy ax, #C0 3 copy sum, ax 4 in ax 5 copy x, ax 6 #L0 copy ax, limit 7 cmp ax, x 8 jnb #L1 9 copy ax, sum 10 add ax, x 11 copy sum, ax 12 in ax 13 copy x, ax 14 jmp #L0 15 #L1 copy ax, sum 16 out ax 40 limit 0 41 #C sum 0 43 x 0 Notes: #L0=6 #L1=15

CompSci Another looping example  Calculate N! (N factorial) but do it with a loop this time  Code is equivalent to the following Java: { n = a.getInt(); i = 1; fact = 1; while (i < n+1) { fact = (fact * i); i = (i + 1); } b.setInt(fact); }

CompSci fact.as 1 in ax 2 copy n, ax 3 copy ax, #C1 4 copy i, ax 5 copy fact, ax 6 #L0 copy ax, n 7 add ax, #C1 8 copy E0, ax 9 copy ax, i 10 cmp ax, E0 11 jnb #L1 12 copy ax, fact 13 mult ax, i 14 copy fact, ax 15 copy ax, i 16 add ax, #c1 17 copy i, ax 18 jmp #L0 19 #L1 copy ax, fact 20 out ax 21 halt 40 n 0 41 i 0 42 #C fact 0 44 E0 0 Notes: #L0=6 #L1=19

CompSci Assembler Programming Notes  Note that previous program added the mul instruction  Most hardware has standard arithmetic support  Historically not the case  The best way to follow such a program is by tracing  See trace for fact.as program on web page  Writing assembler programs from scratch  Not that hard  Can get quite used to working at this level  Was done for efficiency reasons o Could do better than automatic translation (e.g., compiler)  However, remember 15 lines of code a day o This figure is language independent! o Compilers have gotten better than the average programmer

CompSci Handling List or Arrays  Need extra hardware to do this well  Have registers that point to the list/array  Increment these registers to step through list/array  Can be done with our limited hardware  Involves having the program modify itself  Not hard to write  Errors in such self-modifying code very hard to find!  Additional Features Desired (minimal upgrade)  Need for more registers  Handling function/method calls o Need to “remember” where you came from o Jump to statement after that when done

CompSci Modern Hardware  Memory Size  PC’s often have gigabyte of memory now  What does this do to the size of the instruction?  Lots of Registers  It is not unusual to have 32 accumulators  What does this do to the size of the instruction?  Memory Hierarchy 1. Registers 2. Cache Memory 3. Main Memory 4. Disk (virtual memory) 5. Offline storage (tapes, CDROMs, DVDs, etc.)