) Machine Language Part 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

22AIE113

Elements of Computing Systems-2


Hack Machine Language

Ms. Sreelakshmi K, Assistant Professor


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

Observations:

• Hack program: a sequence of Hack instructions

• White space is permitted

• Comments are welcome

5-Feb-24 22AIE113|EOC-2|B.TECH CSE (AI)|CEN|Ms.Sreelakshmi 2


Input / output

I/O handling (high-level):


Software libraries enabling text, graphics, audio, video, etc.

I/O handling (low-level):


Bits manipulation.
22AIE102|CEN 3
Memory mapped output

Memory mapped output

A designated memory area, dedicated to manage a display unit

The physical display is continuously refreshed from the memory map,


many times per second

Output is effected by writing code that manipulates the screen memory map

22AIE102|CEN 4
Screen memory map

To set pixel (row,col) on/off:

22AIE102|CEN 5
DEMO of Screen memory map in Hardware
Simulator

22AIE102|CEN 6
Memory mapped input

The physical keyboard is associated with a keyboard memory map.

22AIE102|CEN 7
When a key is pressed on the keyboard, the key’s scan code appears in
the keyboard memory map

 When no key is pressed, the resulting code is 0.

22AIE102|CEN 8
The Hack character set

22AIE102|CEN 9
Handling the keyboard
To check which key is currently pressed:
• Probe the contents of the Keyboard chip
• In the Hack computer: probe the contents of
RAM[24576].

22AIE102|CEN 10
DEMO of Keyboard memory map in Hardware
Simulator

22AIE102|CEN 11
Hack assembly language (overview)

22AIE102|CEN 12
Hack Programming
• Working with registers and memory
• Branching
• Variables
• Iteration
• Pointers
• input/output

22AIE102|CEN 13
Registers and memory

22AIE102|CEN 14
Typical operations

22AIE102|CEN 15
Program example: add two numbers

Implicit line
numbers

22AIE102|CEN 16
Program example: add two numbers

22AIE102|CEN 17
Terminating a program

22AIE102|CEN 18
Terminating a program

NOP slide
22AIE102|CEN 19
Terminating a program

22AIE102|CEN 20
Built-in symbols
• The Hack assembly language features built-in symbols:

These symbols can be used to denote “virtual registers”

• Example: suppose we wish to use RAM[5] to represent some variable,


say x, and we wish to let x=7

21
Built-in symbols
• The Hack assembly language features built-in symbols:

• SCREEN and KBD : base addresses of I/O memory maps


• Remaining symbols: used in the implementation of the Hack virtual machine

22
Thank You

22AIE102|CEN 23

You might also like