Machine and Assembly Language

Slides:



Advertisements
Similar presentations
Chapter 2: Data Manipulation
Advertisements

Machine cycle.
Machine & Assembly Language. Machine Language  Computer languages cannot be read directly by the computer – they are not in binary.  All commands need.
Stored Program Architecture
Dr. Ken Hoganson, © August 2014 Programming in R COURSE NOTES 2 Hoganson Language Translation.
 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 Binary Machine Modern high-level programming languages are designed to make programming easier. On the other end, the low level, all modern digital.
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)
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
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.
Overview The von Neumann Machine - the programmable digital computer Introducing the LC-3 Computer - A “toy” computer for us to learn from Computer machine.
Chapters 5 - The LC-3 LC-3 Computer Architecture Memory Map
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
The CPU The Central Presentation Unit Language Levels Fetch execute cycle Processor speed.
Computer Science 210 Computer Organization The Instruction Execution Cycle.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
An Introduction Chapter Chapter 1 Introduction2 Computer Systems  Programmable machines  Hardware + Software (program) HardwareProgram.
Levels of Architecture & Language CHAPTER 1 © copyright Bobby Hoggard / material may not be redistributed without permission.
Instruction Set Architecture
Information Representation: Machine Instructions
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.
Computer Engineering Rabie A. Ramadan Lecture 1. 2 Welcome Back.
Module : Algorithmic state machines. Machine language Machine language is built up from discrete statements or instructions. On the processing architecture,
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.
© 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.4 Representation of data in computer systems Instructions.
The von Neumann Model – Chapter 4 COMP 2620 Dr. James Money COMP
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Dale & Lewis Chapter 5 Computing components
Lecture 2: Instruction Set Architecture part 1 (Introduction) Mehran Rezaei.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Computer Operation. Binary Codes CPU operates in binary codes Representation of values in binary codes Instructions to CPU in binary codes Addresses in.
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.
1 What we want: execute High Level Language (HLL) programs What we have: computer hardware (a glorified calculator)
Computer Organization
CPU Organisation & Operation
Computer Science 210 Computer Organization
Pipelining.
von Neumann Architecture CPU
Prof. Sirer CS 316 Cornell University
Computer Science 210 Computer Organization
Hmmm Assembly Language
Figure 8.1 Architecture of a Simple Computer System.
Computer Science 210 Computer Organization
Design of the Control Unit for One-cycle Instruction Execution
Programming Language Design
Intel 8080 Processor The 8080 was an 8-bit processor
Figure 8.1 Architecture of a Simple Computer System.
von Neumann Architecture CPU
MARIE: An Introduction to a Simple Computer
Prof. Sirer CS 316 Cornell University
Principles of Programming Languages
Program Execution.
A Level Computer Science Topic 5: Computer Architecture and Assembly
Hmmm Assembly Language
Algoritmos y Programacion
Presentation transcript:

Machine and Assembly Language Author: Nathan Sprague

Machine Language The machine language for a particular computer the architecture of the CPU. For example: G4 Macs have a different machine language than Intel PC's. is tied to ● ● We will look at the machine language of a simple, simulated computer. ●

Von Neumann Architecture Memory CPU Control Registers ALU Unit

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

Von Neumann Architecture  Program and Data are both stored in memory. Fetch, Decode, Execute cycle… Memory  CPU Control Registers ALU Unit

Machine Language Example Our computer has 4 registers and 32 memory locations. Each instruction is 16 bits. ● ● Here is a machine language program computer: for our simulated ● 1000000100100101 1000000101000101 1010000100000110 1000001000000110 1111111111111111

Sample Instruction Instruction ID Register # Memory Location LOAD contents of memory location into register 100000010 RR MMMMM example: R0 = Mem[3] 100000010 00 00011

Machine Language LOAD contents of memory location into register 100000010 RR MMMMM ex: R0 = Mem[3] 100000010 00 00011 STORE contents of register into memory location 100000100 RR MMMMM ex: Mem[4] = R0 100000100 00 00100 MOVE contents of one register into another register 100100010000 RR RR ex: R0 = R1 100100010000 00 01

Machine Language ADD contents of 2 registers, store result in third. 1010000100 RR RR RR ex: R0 = R1 + R2 1010000100 00 01 10 SUBTRACT contents of 2 registers, store result into third 1010001000 RR RR RR ex: R0 = R1 – R2 1010001000 00 01 10 Halt the program 1111111111111111

Reading Machine Language In our case, first nine bits specifies the operation, last 6 ● (or 7) bits specifies the arguments: 100000010 1010000100 100000100 01 10 00 00101 Load Memory 5 ­> R1 R2 01 10 R1 + R2 ­> R0 00110 Store R0 ­> Memory 6 1111111111111111 It is very tedious to program in machine language. ●

Assembly Language 1111111111111111 HALT Assembly instructions are just shorthand for machine ● Machine Language Equivalent Assembly 1000000100100101 LOAD R1 5 1000000101000101 LOAD R2 5 1010000100000110 ADD R0 R1 R2 1000001000000110 SAVE R0 6 1111111111111111 HALT (For all assembly instructions that compute a result, the ● first argument is the destination.) Very easy to write an Assembly Language ­> Machine language translator. ●

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

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

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 R0 3 ADD R3 R2 R3 R1 1 1 SUB R0 R0 R1 R2 Number ADD R3 R2 R3 R1 1 1 SUB R0 R0 R1 R2 Number 2 BZERO 4 R3 3 BRANCH 0 4 MOVE R2 R3 5 HALT

In Matlab The same program in Matlab z = 0; x = 3; while x ~= 0 ● The same program in Matlab z = 0; x = 3; while x ~= 0 z = z + y; x = x ­ 1; y = z; would be the following: ● Or the following: y = y*3;

Problems with Assembly Why might we avoid writing in assembly? ●

High Level Languages: Compilation and Interpretation Typically, we write in a language that is (relatively) to use. A translator program converts our instructions to machine instructions for the target computer. easy ● ● – Interpreter – Translation is on­the­fly. (Matlab) Compiler – Translation happens all at once. Advantages and disadvantages... ●

Compilers, Interpreters, Assemblers Because it is not fun to program in Assembly, we have “high level” programming languages. ● – Matlab Python, C, C++, Java, Fortran, Cobol, Pascal, M, Ada, Lisp, Ruby, Smalltalk, C#, Haskell, Prolog… Compiler/Interpreter translates from the high­level language to machine language. –

Program Translation Compiler/Interpreter Assembler z = 0; x = 3; ADD R3 R2 R3 SUB R0 R0 R1 BZERO 4 BRANCH 0 MOVE R2 R3 HALT 101000010 101000100 000000100 000000010 100100010 111111111 0000100 0000000 z = 0; x = 3; while x ~= 0 z = z + y; x = x ­ 1; y = z; 1010000100000110 1010001000000110 000000100 000000010 1001000100001011 1111111111111111 Compiler/Interpreter Assembler

Mini­Lab http://www.dave­reed.com/book/source.html