This repository contains educational examples of HACK assembly language implementations, demonstrating fundamental programming constructs and algorithms translated from high-level pseudocode.
HACK is a simplified assembly language designed for educational purposes, particularly in computer science courses like Nand2Tetris. It provides a clean, minimal instruction set that helps students understand low-level programming concepts.
-
for_loop.asm- Demonstrates for loop implementationj = 5 for(i = 1; i < 5; i++) { j-- } -
if_then_else.asm- Shows conditional branchingi = 4 if (i < 5) then j = 3 else j = 2 -
while_loop.asm- Implements while loop with nested conditionsi = 0 j = 0 while(i == 0) { j++ if j == 5 then i = j }
array_traversal.asm- Array manipulation and traversalA[0] = 5, A[1] = 4, A[2] = 3, A[3] = 2, A[4] = 1, A[5] = 0 for (i = 0; i <= 5; i++) { if A[i] == 0 then A[i] = 5; }
bubble_sort_algorithm.asm- Complete bubble sort implementation// Bubble Sort Algorithm A[0] = 5, A[1] = 4, A[2] = 3, A[3] = 2, A[4] = 1, A[5] = 0 flag = 1; // set flag to true to begin first pass while (flag == 1) { flag = false; // set flag to false awaiting a possible swap for (j = 0; j < 6; j++) { if (A[j] > A[j+1]) { // test for ascending sort temp = A[j]; // swap elements A[j] = A[j+1]; A[j+1] = temp; flag = 1; // shows a swap occurred } } }
- Software package provided by the Nand to Tetris platform
- Download the HACK Assembler along with other useful tools (compiler, emulator, simulator) from the software package.
- Extract the ZIP file.
- Refer to the manual for detailed usage instructions.
- Compile and run
.asmfiles using thenan2tetris/tools/Assembler.bat.
- Control Flow: Understanding loops, conditionals, and branching
- Memory Management: Working with variables and arrays
- Algorithm Implementation: Translating algorithms to assembly language
- Low-Level Programming: Understanding computer architecture concepts
This project is part of coursework and is intended for educational purposes.