Professional Documents
Culture Documents
EoC-1 - Lecture - 16 - Machine Language - Part 1
EoC-1 - Lecture - 16 - Machine Language - Part 1
22AIE102|CEN 1
Computers are flexible
Same hardware can run many different software programs
22AIE102|CEN 2
Universality
22AIE102|CEN 3
Stored program concept
22AIE102|CEN 4
Stored program concept
22AIE102|CEN 5
Machine language : operations
22AIE102|CEN 6
Machine language : program counter
We are now
at inst. 159.
Next inst. is
160
Operate on
memory
location
340
22AIE102|CEN 9
Mnemonics
22AIE102|CEN 10
Mnemonics
22AIE102|CEN 11
Symbols
The assembler will resolve the symbol index into a specific address
22AIE102|CEN 12
Machine language : Basic elements
22AIE102|CEN 13
Machine language
• Specification of the hardware/software
interface:
– What supported operations?
– What do they operate on?
– How is the program controlled?
22AIE102|CEN 14
Machine operations
• Usually correspond to the operations that the
hardware is designed to support:
– Arithmetic operations: add, subtract, …
– Logical operations: and, or, …
– Flow control: “goto instruction n”
22AIE102|CEN 15
Addressing
22AIE102|CEN 16
Memory hierarchy
• Accessing a memory location is expensive:
– Need to supply a long address
– Getting the memory contents into the CPU takes
time
• Solution: memory hierarchy
22AIE102|CEN 17
22AIE102|CEN 18
Registers
• The CPU typically contains a few, easily accessed, registers
• Their number and functions are a central part of the machine language
22AIE102|CEN 19
22AIE102|CEN 20
Addressing modes
Back to the question:
How do we decide which data
to work on?
22AIE102|CEN 21
Flow control
• How does the language allow us to decide, and
specify, which instruction to process next?
• Usually the CPU executes machine instructions in
sequence
• Sometimes we need to “jump” unconditionally to
another location,
– e.g. in order to implement a loop:
22AIE102|CEN 22
Flow control continued..
22AIE102|CEN 23
Flow control continued..
• Sometimes we need to jump only if some
condition is met:
22AIE102|CEN 24
Hack computer: hardware
A 16-bit machine consisting of:
22AIE102|CEN 25
Hack computer: software
22AIE102|CEN 26
Hack computer: registers
Semantics:
Sets the A register to value
Side effects: RAM[A] becomes the selected RAM register
22AIE102|CEN 28
The C-instruction
Semantics:
• Computes the value of comp
• Stores the result in dest
22AIE102|CEN 29
22AIE102|CEN 30
22AIE102|CEN 31
22AIE102|CEN 32
Hack machine language
22AIE102|CEN 33
A-instruction specification
22AIE102|CEN 34
C-instruction specification
22AIE102|CEN 35
22AIE102|CEN 36
22AIE102|CEN 37
22AIE102|CEN 38
22AIE102|CEN 39
A typical HACK program
Observations:
22AIE102|CEN 40
Thank You
22AIE102|CEN 41