0% found this document useful (0 votes)
55 views

EoC-1 - Lecture - 16 - Machine Language - Part 1

This document discusses the basics of machine language. It introduces the stored program concept where both instructions and data are stored in memory. It describes machine language operations like arithmetic and logical operations. It discusses addressing modes that allow specifying where data is located in memory. It also covers flow control elements like jumps that allow changing the order of instruction execution. Finally, it provides examples of a simple Hack machine language with A and C instructions and shows a sample program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

EoC-1 - Lecture - 16 - Machine Language - Part 1

This document discusses the basics of machine language. It introduces the stored program concept where both instructions and data are stored in memory. It describes machine language operations like arithmetic and logical operations. It discusses addressing modes that allow specifying where data is located in memory. It also covers flow control elements like jumps that allow changing the order of instruction execution. Finally, it provides examples of a simple Hack machine language with A and C instructions and shows a sample program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

22AIE102

Elements of Computing Systems-II


Basic Elements of Machine Language

Ms. Sreelakshmi K, Assistant Professor


Center for Computational Engineering and Networking (CEN)
Amrita School of Engineering, Coimbatore
Acknowledgment: Prof. Noam Nisan and Prof. Shimon Schocken

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

What are the instructions or


what each instruction means?

22AIE102|CEN 6
Machine language : program counter

We are now
at inst. 159.
Next inst. is
160

What instruction has to be


executed next?
22AIE102|CEN 7
Machine language : Addressing

Operate on
memory
location
340

What the hardware has to


operate on or where the data it
has to operate on is present?
22AIE102|CEN 8
Compilation

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:

• Data memory (RAM): a sequence of 16-bit registers:


RAM[0], RAM[1], RAM[2],…

• Instruction memory (ROM): a sequence of 16-bit registers:


ROM[0], ROM[1], ROM[2],…

• Central Processing Unit (CPU): performs 16-bit instructions

22AIE102|CEN 25
Hack computer: software

Hack machine language:


• 16-bit A-instructions
• 16-bit C-instructions

Hack program = sequence of instructions


written in the Hack machine language

22AIE102|CEN 26
Hack computer: registers

The Hack machine language recognizes three 16-bit registers:


• D: used to store data
• A: used to store data / address the memory
• M: represents the currently addressed memory register: M = RAM[A]
22AIE102|CEN 27
The A-instruction
Where value is either:
a non-negative decimal constant or
a symbol referring to such a constant

Semantics:
 Sets the A register to value
 Side effects: RAM[A] becomes the selected RAM register

22AIE102|CEN 28
The C-instruction

JGT – Jump greater that 0

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

Two ways to express the same semantics:

22AIE102|CEN 33
A-instruction specification

Where value is a 15-bit binary constant

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:

• Hack program: a sequence of Hack instructions

• White space is permitted

• Comments are welcome

22AIE102|CEN 40
Thank You

22AIE102|CEN 41

You might also like