Machine - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Machine

Description:

Sample Machine Language Program ... Compiler/Interpreter translates from the high-level language to machine language. Program Translation. int z = 0; ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 28
Provided by: WillFit6
Category:
Tags: machine

less

Transcript and Presenter's Notes

Title: Machine


1
Machine Assembly Language
2
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.

3
Von Neumann Architecture
Memory
CPU
Control Unit
Registers
ALU
4
Slightly More Complete Picture
Memory
CPU
Control Unit
Registers
ALU
Secondary Storage
5
Von Neumann Architecture
  • Program and Data are both stored in memory.
  • Fetch, Decode, Execute cycle

6
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.

7
Sample Instruction
Instruction ID
Register
Memory Location
8
Machine Language
9
Machine Language
10
Sample Machine Language Program
  • Add the contents of register 1 to the contents of
    register 2 and store it in register 0
  • 1010000100 00 01 10
  • 1111111111111111

11
Sample Machine Language Program
  • Add the contents of memory location 1 to the
    contents of register 2 and store it in register
    0
  • 100000010 01 00001
  • 1010000100 00 01 10
  • 1111111111111111

12
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.

13
Assembly Language
14
Assembly Language
15
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

16
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

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

18
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

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

20
Exercise
  • What would be the assembly instructions to do
    the following computation
  • R0 Mem7 R2 - R3
  • STORE MEM REG
  • LOAD REG MEM
  • MOVE REG REG
  • ADD REG REG REG
  • SUB REG REG REG
  • HALT

21
Exercise Solution
  • SUB R2 R2 R3
  • LOAD R1 7
  • ADD R0 R1 R2
  • HALT
  • (we want R0 Mem7 R2 - R3)

22
Some More Instructions
  • We are missing some crucial functionality
  • ??

23
Some More Instructions
  • We are missing some crucial functionality
  • Loops!

24
A More Complex Example
25
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 y3

26
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.

27
Program Translation
z 0 x 3 while x ! 0 z y x
x -1 y z
1010000100000110 1010001000000110 0000001000000100
0000000100000000 1001000100001011
1111111111111111
Compiler
Assembler
Write a Comment
User Comments (0)
About PowerShow.com