Machine Language

Only available on StudyMode
  • Topic: Machine code, Computer, Computer architecture
  • Pages : 8 (1139 words )
  • Download(s) : 112
  • Published : December 28, 2012
Open Document
Text Preview
Harvard University

CS 101

Fall 2005, Shimon Schocken

Machine Language

Elements of Computing Systems

1

Machine Language (Ch. 4)

Where we are at:
Human Thought Abstract design
abstract interface
Chapters 9, 12

H.L. Language & Operating Sys.

Compiler
abstract interface
Chapters 10 - 11

Software hierarchy

Virtual Machine

VM Translator
abstract interface
Chapters 7 - 8

Assembly Language
Assembler
Chapter 6

abstract interface

Machine Language

Computer Architecture
abstract interface
Chapters 4 - 5

Hardware Platform

Gate Logic
abstract interface
Chapters 1 - 3

Hardware hierarchy

Chips & Logic Gates

Electrical Engineering Physics

Elements of Computing Systems

2

Machine Language (Ch. 4)

Copyright © Shimon Schocken

Machine language is “the soul of the machine”
Duality: Machine language ( = instruction set) can be viewed as an abstract description of the hardware platform The hardware can be viewed as a means for realizing an abstract machine language Another duality: Binary version Symbolic version Loose definition: Machine language = an agreed upon formalism for manipulating a memory using a processor and a set of registers Varies across different hardware platforms. Elements of Computing Systems 3 Machine Language (Ch. 4)

Binary and symbolic notation
1010 0011 0001 1001 1010 0011 0001 1001 ADD R3, R1, R9 ADD R3, R1, R9

Evolution: Physical coding Symbolic documentation Symbolic coding Requires a translator. Jacquard loom (1801)

Ada Lovelace (1815-1852)

Elements of Computing Systems

4

Machine Language (Ch. 4)

Copyright © Shimon Schocken

Lecture plan

Machine languages at a glance The Hack machine language: Symbolic version Binary version Perspective.

Elements of Computing Systems

5

Machine Language (Ch. 4)

Arithmetic / logical operations
ADD R2,R1,R3 // R2 R1+R3 where R1,R2,R3 are registers ADD R2,R1,R3 // R2 R1+R3 where R1,R2,R3 are registers AND R1,R1,R2 // R1 bit wise And of R1 and R2 AND R1,R1,R2 // R1 bit wise And of R1 and R2 ADD R2,R1,foo // R2 R1+foo where foo stands for the value of the ADD R2,R1,foo // R2 R1+foo where foo stands for the value of the // memory location pointed at by the user-defined // memory location pointed at by the user-defined // label foo. // label foo.

Elements of Computing Systems

6

Machine Language (Ch. 4)

Copyright © Shimon Schocken

Memory access
Direct addressing: LOAD R1,67 // R1 Memory[67] LOAD R1,67 // R1 Memory[67] // Or, assuming that bar refers to memory address 67: // Or, assuming that bar refers to memory address 67: LOAD R1,bar LOAD R1,bar // R1 Memory[67] // R1 Memory[67]

Immediate addressing: LOADI R1,67 LOADI R1,67 // R1 67 // R1 67 STORE R1,bar // bar R1 STORE R1,bar // bar R1 Indirect addressing: // Translation of x=foo[j] or x=*(foo+j): // Translation of x=foo[j] or x=*(foo+j): ADD R1,foo,j // R1 foo+j ADD R1,foo,j // R1 foo+j LOAD* R2,R1 LOAD* R2,R1 STORE R2,x STORE R2,x Elements of Computing Systems

// R2 memory[R1] // R2 memory[R1] // x R2 // x R2
7 Machine Language (Ch. 4)

Flow of control
Branching JMP foo // unconditional jump JMP foo // unconditional jump

Conditional branching JGT R1,foo JGT R1,foo // If R1>0, goto foo // If R1>0, goto foo

// in general: // in general:

cond register, label cond register, label Where: cond is JEQ,,JNE,,JGT,,JGE ,,... Where: cond is JEQ JNE JGT JGE ... register is R1,,R2,,... and register is R1 R2 ... and label is aauser-defined label label is user-defined label

And that’s all you need in order to implement any high-level control structure in any programming language. Elements of Computing Systems 8 Machine Language (Ch. 4)

Copyright © Shimon Schocken

A hardware abstraction (Hack)
Registers: D, A Data memory: M ≡ RAM[A] ALU: {D|A|M} = ALU(D,A,M) Instruction memory: current instruction = ROM[A] Control: instruction memory is loaded with a sequence of instructions, one...
tracking img