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

EoC-1 - Lecture - 18 - Machine Language - Part 3

This document discusses the Hack assembly language and programming. It covers topics such as working with registers and memory, branching, variables, iteration, pointers, and input/output. The document provides examples to illustrate how to add two numbers, use branching and labels, define variables, perform iterative processing, and use pointers. It also discusses built-in symbols and terminating a program in Hack assembly language. The intended audience is a class on Elements of Computing Systems-II taught by Ms. Sreelakshmi K at Amrita School of Engineering, Coimbatore.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

EoC-1 - Lecture - 18 - Machine Language - Part 3

This document discusses the Hack assembly language and programming. It covers topics such as working with registers and memory, branching, variables, iteration, pointers, and input/output. The document provides examples to illustrate how to add two numbers, use branching and labels, define variables, perform iterative processing, and use pointers. It also discusses built-in symbols and terminating a program in Hack assembly language. The intended audience is a class on Elements of Computing Systems-II taught by Ms. Sreelakshmi K at Amrita School of Engineering, Coimbatore.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

22AIE102

Elements of Computing Systems-II


Hack Progamming

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
Hack assembly language (overview)

22AIE102|CEN 2
CPU Emulator

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

22AIE102|CEN 5
Typical operations

22AIE102|CEN 6
Program example: add two numbers

Implicit line
numbers

22AIE102|CEN 7
Program example: add two numbers

22AIE102|CEN 8
DEMO

22AIE102|CEN 9
Terminating a program

22AIE102|CEN 10
Terminating a program

22AIE102|CEN 11
Terminating a program

22AIE102|CEN 12
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

22AIE102|CEN 13
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

22AIE102|CEN 14
Hack Programming
• Working with registers and memory
• Branching
• Variables
• Iteration
• Pointers
• input/output
22AIE102|CEN 15
example:
Branching

If you remove
the comments,
and preamble
the code
becomes cryptic

22AIE102|CEN 16
Labels

22AIE102|CEN 17
Labels

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

22AIE102|CEN 20
Hack Programming
• Working with registers and memory
• Branching
• Variables
• Iteration
• Pointers
• input/output
22AIE102|CEN 21
Iterative processing

22AIE102|CEN 22
22AIE102|CEN 23
22AIE102|CEN 24
Hack Programming
• Working with registers and memory
• Branching
• Variables
• Iteration
• Pointers
• input/output
22AIE102|CEN 25
Pointers
Suppose arr=100, and n=10 Variable arr = 100
address (pointer)

In the memory from location


100 till 110 store -1.

22AIE102|CEN 26
22AIE102|CEN 27
22AIE102|CEN 28
Thank You

22AIE102|CEN 29

You might also like