🔐
SecWiki
  • Home
  • General
    • Interesting Links
      • Curriculum
    • Pentest Labs, Wargames Sites
      • How To Vulnhub with VirtualBox
  • Network Pentest
    • Courses
      • TCM - Zero to Hero
        • Week 1: Setup
          • ipsweep.sh
        • Week 2: Python 101
          • python101.py
          • bof.py
        • Week 3: Python 102
          • python102.py
          • scanner.py
        • Week 4: Passive OSINT
        • Week 5: Scanning Tools & Tactics
          • nmap
          • Nessus
          • msfconsole
        • Week 6: Enumeration
        • Week 7: Exploitation, Shells, and Some Credential Stuffing
        • Week 8: LLMNR/NBT-NS Poisoning
        • Week 9: NTLM
        • Week 10: MS17-010, GPP/cPasswords, and Kerberoasting
        • Week 11: File Transfers, Pivoting, Reporting
        • Commands
      • Penetration Testing Student (PTS)
      • OSCP Study
    • Recon
      • OSINT
    • Enumeration
      • Samba Shares
      • ProFtpd
    • Gaining Access
      • Reverse Shells
    • Privilege Escalation
      • Meterpreter
      • Spawning a TTY Shell
      • Reverse Shell Cheat Sheet
      • Cracking Hashes
      • Restricted Linux Shell Escape
      • Linux Privilege Escalation
        • lxd
        • sytemctl
      • Windows Privilege Escalation
        • Active Directory
          • What is AD?
        • User Enumeration
    • Post Exploitation
      • Cleanup
      • Maintaining Access
      • Pivoting
      • File Transfers
      • Covering Tracks
    • Vulnerabilities Checklist
    • Report Writing
  • Web App Pentest
    • Tools
      • Burp Suite
      • THC-Hydra BruteForce
    • Injection
      • SQL Injection
    • Broken Authentication
    • Sensitive Data Exposure
      • SQLite3
    • XML External Entity
      • XML Background
      • XPath Injection
    • Broken Access Control
    • Security Misconfiguration
    • Upload/Download
      • Download Bypass: Poison Null Byte
    • XSS
      • DOMXSS
      • Persistent XSS
      • Reflected (Client-side) XSS
      • Data URLs
    • Insecure Deserialization
    • Components with Known Vulnerabilities
    • Insufficient Logging and Monitoring
    • Server-Side Request Forgery (SSRF)
  • CTF
    • Intro to CTF
    • Forensics
      • Challenges
    • Steganography
    • Reverse Engineering
    • Tools
  • Network Security
    • Courses
      • Sec+
      • IBM Cybersecurity Analyst Professional Certificate
      • ISCI CNSS Course
        • Introduction to Network Security
          • Network Basics
          • Basic Network Utilities
          • The OSI Model
          • Threat Classification
          • Security Terminology
          • Approaches of Network Security
          • Law and Network Security
        • Types of Attacks
          • Denial of Service Attacks
          • Buffer Overflow Attacks
          • IP Spoofing
          • Session Hijacking
        • Fundamentals of Firewalls
          • What is a Firewall
          • Firewall Types
          • Firewall Implementation
          • Proxy Servers
          • Windows Firewalls
          • Linux Firewalls
        • Intrusion-Detection Systems
          • IDS Concepts
          • Components and Processes of IDS
          • Implementing IDS
          • Honeypots
        • Fundamentals of Encryption
          • The History of Encryption
          • Modern Encryption Methods
          • Windows and Linux Encryption
          • Hashing
          • Cracking Passwords
        • Virtual Private Networks (VPN)
          • Introduction to VPN
          • VPN Protocols
          • IPSec
          • SSL/TLS
          • VPN Solutions
        • Operating System Hardening
          • Configuring Windows
          • Configuring Linux
          • Operating System Patches
        • Virus Attacks and How to Defend
          • Virus Types and Attacks
          • Virus Scanners
          • Antivirus
          • Virus Infection and Identification
          • Trojan Horses
          • Spyware or Adware
        • Security Policies
          • User Policies Definition
          • System Administration Policies
          • Access Control
        • Assessing System Security
          • Risk Assessment
          • Conducting an Initial Assessment
          • Probing the Network
          • Vulnerabilities
          • Documenting Security
        • Security Standards
          • ISO Standards
          • NIST Standards
          • General Data Protection Regulation (GDPR)
          • PCI DSS
        • Physical Security and Recovery
          • Physical Security
          • Disaster Recovery
          • Fault Tolerance
        • Attackers Techniques
          • Hacking Preparation
          • The Attack Phase
          • Hacking Wi-Fi
    • The Web
    • The OSI Model
    • Malware Traffic Analysis with Wireshark
  • Digital Forensics
    • Autopsy - open-source digital forensics platform
  • Exploit Dev/Analysis
    • Code Review
      • Tools
    • Buffer Overflows
    • Static Analysis
      • Antivirus Scanning
      • Hashing
      • File strings
      • Packed and Obfuscated Malware
        • Demo: UPX
      • Portable Executable File Format (PE)
        • Tools
        • Linked Libraries and Functions
        • PE File Headers and Sections
  • Shell
    • ./missing-semester
      • Course overview + the shell
      • Shell Tools and Scripting
      • Editors (Vim)
      • Data Wrangling
      • Command-line Environment
    • Bash Tricks
    • .bashrc
    • Random Commands
      • sed
  • Hardware
    • NAND2Tetris
      • Boolean Functions and Gate Logic
      • Boolean Arithmetic and the ALU
      • Memory
      • Machine Language
      • Computer Architecture
      • Assembler
  • Other
    • K8s
      • Chapter 1: From Monolith to Microservices
      • Chapter 2: Container Orchestration
      • Chapter 3: Kubernetes
      • Chapter 4: Kubernetes Architecture
Powered by GitBook
On this page
  • Unit 6.1: Assembly Languages and Assemblers
  • Unit 6.2: The Hack Assembly Language
  • Unit 6.3: The Assembly Process - Handling Instructions
  • Unit 6.4: The Assembly Process - Handling Symbols
  • Unit 6.5: Developing a Hack Assembler
  • Unit 6.6: Project 6 Overview: Programming Option

Was this helpful?

  1. Hardware
  2. NAND2Tetris

Assembler

In a nutshell: Every computer has a binary machine language, in which instructions are written as series of 0's and 1's, and a symbolic machine language, also known as assembly language, in which instructions are expressed using human-friendly mnemonics. Both languages do exactly the same thing, and are completely equivalent. But, writing programs in assembly is far easier and safer then writing in binary. In order to enjoy this luxury, someone has to translate our symbolic programs into binary code that can execute as-is on the target computer. This translation service is done by an agent called assembler. The assembler can be either a person who carries out the translation manually, or a computer program that automates the process. In this module and final project in the course we learn how to build an assembler. In particular, we'll develop the capability of translating symbolic Hack programs into binary code that can be executed as-is on the Hack platform. Each one of you can choose to accomplish this feat in two different ways: you can either implement an assembler using a high-level language, or you can simulate the assembler's operation using paper and pencil. In both cases we give detailed guidelines about how to carry out your work.

Key concepts: Binary and symbolic machine languages, parsing, symbol tables, code generation, cross assembler, assembler implementation.

Unit 6.1: Assembly Languages and Assemblers

  • Basic Assembler Logic

    • Repeat:

      • Read the next Assembly language command

      • Break it into the different fields it is composed of

      • Lookup the binary code for each field

      • Combine these codes into a single machine language command

      • Output this machine language command

  • The assembler translates assembly language to machine language

  • The assembler enters a symbol into the table only when that symbol has not appeared before.

Unit 6.2: The Hack Assembly Language

  • Assembly Program Elements

    • white space

      • Empty lines / indentation

      • Line comments

      • in-line comments

    • instructions

      • A

      • C

    • symbols

      • references

      • label declarations

  • Ignore white space!

Unit 6.3: The Assembly Process - Handling Instructions

  • Translating A Instructions

    • if value is a decimal constant, generate the equivalent 15-bit binary constant

    • if value is a symbol, later

    • Example

      • What is the binary value of the instruction @9 ?

        • 0000000000001001

  • Translating C Instructions

    • Parse statement and save it into 3 individual fields

      • dest = comp ; jump

    • Example

      • What is the binary value of the instruction MD=A-1;JGE ?

        • 111 0 110010 011 011

  • For each instruction

    • parse, break into fields

    • A: translate dec to bin

    • C: generate bin for each field, assemble into full 16bit instruction

    • Write the 16 bit instructions to output file

Unit 6.4: The Assembly Process - Handling Symbols

  • Symbols

    • variable: represent memory locations where the programmer wants to maintain values

      • any symbol XXX appearing which is not predefined and is not defined elsewhere using (XXX) directive is treated as a variable

      • assigned a unique memory address, starting at 16

      • @variableSymbol

        • if first time, assign a unique memory address

        • else, replace with it's value

    • label: represent destinations of goto instructions

      • declared by the pseudo-command (xxx)

      • this directive defines the symbol XXX to refer to the memory location holding the next instruction in the program

      • @labelSymbol -> replace with its value

    • pre-defined: represent special memory locations

      • 23 symbols

      • @preDefinedSymbol -> replace with its value

  • Symbol table

    • Contains symbol:value pairs

    • initialize with the predefined symbols

    • First pass: add the label symbols --look for '(' symbols

    • Second pass: add the var. symbols

  • The Assembly process

    • Initialization

      • Construct an empty symbol table

      • Add the predefined symbols to the symbol table

    • First pass

      • Scan the entire program

      • For each instruction of the form (xxx):

        • add the pair (xxx, address) to the symbol table, where address is the number of the instruction following (xxx)

    • Second pass

      • Set n to 16

      • Scan the entire program again; for each instruction:

        • If the instruction is @symbol, look up symbol in the table:

          • If (symbol, value) is found, use value to complete the instruction's translation;

          • if not found:

            • Add (symbol, n) to the symbol table

            • Use n to complete the instruction's translation

            • n++

        • If the instruction is a C instruction, complete the instruction's translation

        • Write the translated instruction to the output file

Unit 6.5: Developing a Hack Assembler

  • Main loop

    • Get the next command and parse it

    • select A or C, translate

    • output the resulting machine language command

Unit 6.6: Project 6 Overview: Programming Option

  • Contract

    • Develop a HackAssembler program

    • The source program is supplied: Xxx.asm

    • The generated code is written into a text file named Xxx.hack

    • Assumption: Xxx.asm is error-free

  • Proposed design

    • Parser: unpacks each instruction into its underlying fields

    • Code: translates each field into its corresponding binary value

    • SymbolTable: manages the symbol table

    • Main: initializes the I/O files and drives the process

  • Proposed implementation

    • staged development

      • develop a basic assembler that translates assembly programs without symbols

      • develop an ability to handle symbols

      • morph basic into one that can translate any assembly program

      • Supplied test programs

        • Add.asm: tests white space and instruction handling

        • Max.asm (with symbols) and MaxL.asm (without symbols)

  • Testing Options

    • Hardware sim

      • load Xxx.hack into Hack Computer chip, then execute it

    • CPU Emulator

      • load Xxx.hack into supplied CPUEmulator, then execute it

    • Assembler

      • use supplied Assembler to translate Xxx.asm; compare resulting code with yours

PreviousComputer ArchitectureNextK8s

Last updated 4 years ago

Was this helpful?