Machine & Assembly Language. Machine Language  Computer languages cannot be read directly by the computer – they are not in binary.  All commands need.

Slides:



Advertisements
Similar presentations
RAM (cont.) 220 bytes of RAM (1 Mega-byte) 20 bits of address Address
Advertisements

Chapter 2: Data Manipulation
Computer Science Education
Machine cycle.
The “Little Man Computer” Version
Slides created by: Professor Ian G. Harris Efficient C Code  Your C program is not exactly what is executed  Machine code is specific to each ucontroller.
Stored Program Architecture
CPU performance CPU power consumption
ITEC 352 Lecture 13 ISA(4).
University of Central Florida
DAP teaching computer architecture at Berkeley since 1977
 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
CSE115: Introduction to Computer Science I
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 1.
The Analytical Engine Module 6 Program Translation.
Midterm Wednesday Chapter 1-3: Number /character representation and conversion Number arithmetic Combinational logic elements and design (DeMorgan’s Law)
Computing Components 01/26/11. Announcements & Reminders Programs 1 due Friday, 9/2/11 What is my late policy? Proxy Codes for Labs  You should be able.
Stored Program Concept: The Hardware View
Choice for the rest of the semester New Plan –assembler and machine language –Operating systems Process scheduling Memory management File system Optimization.
Chapters 5 - The LC-3 LC-3 Computer Architecture Memory Map
Computer Science 210 Computer Organization The Instruction Execution Cycle.
1 Chapter-01 Introduction to Computers and C++ Programming.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Levels of Architecture & Language CHAPTER 1 © copyright Bobby Hoggard / material may not be redistributed without permission.
Instruction Set Architecture
Information Representation: Machine Instructions
Computer Science 210 Computer Organization The von Neumann Architecture.
Programming History. Who was the first programmer?
What have mr aldred’s dirty clothes got to do with the cpu
Chap. 0 Introd. to Computer1 0. Introduction to Computer 0.1 Binary Number System
The Central Processing Unit (CPU) and the Machine Cycle.
Model Computer CPU Arithmetic Logic Unit Control Unit Memory Unit
Important Concepts  Parts of the CPU  Arithmetic/Logic Unit  Control Unit  Registers  Program Counter  Instruction Register  Fetch/Decode/Execute.
1 Text Reference: Warford. 2 Computer Architecture: The design of those aspects of a computer which are visible to the programmer. Architecture Organization.
CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.
Chapter 7 Low-Level Programming Languages (slides modified by Erin Chambers)
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.
Represents different voltage levels High: 5 Volts Low: 0 Volts At this raw level a digital computer is instructed to carry out instructions.
1.4 Representation of data in computer systems Instructions.
Dale & Lewis Chapter 5 Computing components
1 The Instruction Set Architecture September 27 th, 2007 By: Corbin Johnson CS 146.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Representation of Data - Instructions Start of the lesson: Open this PowerPoint from the A451 page – Representation of Data/ Instructions How confident.
Software Engineering Algorithms, Compilers, & Lifecycle.
Machine Language Computer languages cannot be directly interpreted by the computer – they are not in binary. All commands need to be translated into binary.
1 What we want: execute High Level Language (HLL) programs What we have: computer hardware (a glorified calculator)
Machine and Assembly Language
CPU Organisation & Operation
Computer Science 210 Computer Organization
Prof. Sirer CS 316 Cornell University
Computer Science 210 Computer Organization
The Processor and Machine Language
Figure 8.1 Architecture of a Simple Computer System.
Computer Science 210 Computer Organization
Intro to Architecture & Organization
Programming Language Design
Figure 8.1 Architecture of a Simple Computer System.
von Neumann Architecture CPU
Computer Architecture
MARIE: An Introduction to a Simple Computer
Prof. Sirer CS 316 Cornell University
Program Execution.
A Level Computer Science Topic 5: Computer Architecture and Assembly
Hmmm Assembly Language
Instruction execution and ALU
Algoritmos y Programacion
Little Man Computer.
Presentation transcript:

Machine & Assembly Language

Machine Language  Computer languages cannot be read directly by the computer – they are not in binary.  All commands need to be translated into binary instructions called machine language.  Each type of CPU has its own machine language.

Von Neumann Architecture CPU Control Unit ALU Registers Memory

Slightly More Complete Picture CPU Control Unit ALU Registers Memory Secondary Storage

Von Neumann Architecture  Program and Data are both stored in memory.  Fetch, Decode, Execute cycle…

Machine Language  We will look at a simulated CPU provided by the author of our book…  This machine language has only 12 different instructions  Each instruction is 16 bits long.  Data values are also limited to 16 bits.

Sample Instruction LOAD contents of memory location into register RR MMMMM example: R0 = Mem[3] Instruction IDRegister #Memory Location

Machine Language LOAD contents of memory location into register RR MMMMM ex: R0 = Mem[3] STORE contents of register into memory location RR MMMMM ex: Mem[4] = R MOVE contents of one register into another register RR RR ex: R0 = R

Machine Language ADD contents of 2 registers, store result in third RR RR RR ex: R0 = R1 + R SUBTRACT contents of 2 registers, store result into third RR RR RR ex: R0 = R1 – R Halt the program

Sample Machine Language Program Add the contents of register 1 to the contents of register 2 and store it in register 0:

Sample Machine Language Program Add the contents of memory location 1 to the contents of register 2 and store it in register 0:

Assembly Language  Set of mnemonic names for the instructions in a particular computer's machine language.  Works on registers and memory locations in the computer.  Translated into binary instructions.

Assembly Language Load contents of memory location into register LOAD [REG] [MEM] ex: R0 = Mem[3] LOAD R0 3 Store contents of register into memory location STORE [REG] [MEM] ex: Mem[4] = R0 STORE 4 R0 Move contents of second register into first register MOVE [REG1] [REG2] ie: R1 = R2 MOVE R1 R2

Assembly Language Add contents of 2 registers, store result in third. ADD [REG] [REG] [REG] ex: R0 = R1 + R2 ADD R0 R1 R2 Subtract contents of 2 registers, store result into third SUB [REG] [REG] [REG] ex: R0 = R1 – R2 SUB R0 R1 R2 Halt the programHALT

Sample Assembly Language Add the contents of register 1 to the contents of register 2 and store it in register 0: ADD R0 R1 R2 HALT

Sample Machine Language Add the contents of memory location 1 to the contents of register 2 and store it in register 0: LOAD R1 1 ADD R0 R1 R2 HALT

Sample Program LOAD R2 5 ADD R2 R2 R2 LOAD R1 3 ADD R3 R1 R2 HALT What does this program do?

Exercise  What would be the assembly instructions to swap the contents of registers 1 & 2?  STORE [MEM] [REG]  LOAD [REG] [MEM]  MOVE [REG] [REG]  ADD [REG] [REG] [REG]  SUB [REG] [REG] [REG]  HALT

Exercise Solution STORE 1 R1 MOVE R1 R2 LOAD R2 1 HALT

Exercise  What would be the assembly instructions to do the following computation: R0 = Mem[7] + R2 - R3  STORE [MEM] [REG]  LOAD [REG] [MEM]  MOVE [REG] [REG]  ADD [REG] [REG] [REG]  SUB [REG] [REG] [REG]  HALT

Exercise Solution SUB R2 R2 R3 LOAD R1 7 ADD R0 R1 R2 HALT (we want R0 = Mem[7] + R2 - R3)

Some More Instructions…  We are missing some crucial functionality…  ??

Some More Instructions…  We are missing some crucial functionality…  Loops! Branch to a location in memory BRANCH [MEM] Branch if the ALU result is zero. BZERO [MEM] Branch if the ALU result is negative. BNEG [MEM]

A More Complex Example 0ADD R3 R2 R3 1SUB R0 R0 R1 2BZERO 4 3BRANCH 0 4MOVE R2 R3 5HALT R03 R11 R2Number R30

In Python  The same program in Python would be the following: z = 0 x = 3 while x != 0: z += y x = x -1 y = z  Or the following: y = y*3

Compilers, Interpreters, Assemblers  Because it is not fun to program in Assembly, we have “high level” programming languages. Python Alice C, C++, Java, Fortran, Cobol, Pascal, C++, M, Ada, lisp, Ruby, Smalltalk, C#, … Compiler/Interpreter translates from the high- level language to machine language.

Program Translation z = 0 x = 3 while x != 0: z += y x = x -1 y = z ADD R3 R2 R3 SUB R0 R0 R1 BZERO 4 BRANCH 0 MOVE R2 R3 HALT CompilerAssembler