From 56df71bb1dfa9ce8847cd9ed81334f8c913c0ea1 Mon Sep 17 00:00:00 2001 From: feng-arch Date: Wed, 13 Nov 2024 10:35:38 +0800 Subject: [PATCH] add readme file to this project --- .gitignore | 5 ++ README.md | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 195 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7a042f5..aa4e57c 100644 --- a/.gitignore +++ b/.gitignore @@ -86,3 +86,8 @@ Module.symvers Mkfile.old dkms.conf +lc4 + +tests/ + +.vscode/ \ No newline at end of file diff --git a/README.md b/README.md index 63498a1..40340e0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,191 @@ -# lc4_asm_disassembling +# LC4 Disassembler Project + +This project implements a disassembler for the LC4 instruction set. It reads LC4 object files, parses the instructions and data, and outputs a human-readable assembly listing. + +## Table of Contents + +- [Overview](#overview) +- [Project Structure](#project-structure) +- [Compilation and Execution](#compilation-and-execution) +- [Usage](#usage) +- [File Descriptions](#file-descriptions) +- [Sample Output](#sample-output) +- [LC4 Instruction Set](#lc4-instruction-set) +- [Notes](#notes) + +## Overview + +The program mimics the PennSim loader and disassembler. It performs the following steps: + +1. Loads LC4 object files containing code, data, and symbols. +2. Parses the object files and constructs a memory linked list. +3. Disassembles the machine code into assembly instructions. +4. Outputs the contents of the memory, including addresses, contents, labels, and assembly instructions. + +## Project Structure + +``` +./submit +├── lc4_disassembler.c +├── lc4_disassembler.h +├── lc4_loader.c +├── lc4_loader.h +├── lc4_memory.c +├── lc4_memory.h +├── lc4.c +└── Makefile +``` + +- `lc4.c`: The main driver of the program. +- `lc4_memory.*`: Implements the memory linked list and related helper functions. +- `lc4_loader.*`: Handles loading and parsing of the LC4 object files. +- `lc4_disassembler.*`: Contains the logic for disassembling machine code into assembly instructions. +- `Makefile`: Automates the compilation process. + +## Compilation and Execution + +### Prerequisites + +- GCC compiler +- Make utility + +### Compilation + +Run the following command to compile the project: + +```bash +cd ./submit +make all +``` + +This will produce an executable named `lc4`. + +### Execution + +To run the disassembler, use: + +```bash +./lc4 +``` + +Replace `` with the path to your LC4 object file. + +## Usage + +1. **Compile the program** using the provided `Makefile`. +2. **Run the executable** with an LC4 object file as an argument. +3. **View the output**, which displays the labels, addresses, contents, and assembly instructions. + +Example: + +```bash +./lc4 example.obj +``` + +## File Descriptions + +### `main.c` + +- Initializes the memory linked list. +- Parses command-line arguments to get the object file name. +- Calls functions to load the object file, disassemble the instructions, print the memory contents, and clean up. + +### `lc4_memory.h` and `lc4_memory.c` + +- Defines the `row_of_memory` struct representing each memory location. +- Implements functions to: + - Add nodes to the memory linked list. + - Search for nodes by address or opcode. + - Print the memory contents. + - Delete the memory linked list. + +### `lc4_loader.h` and `lc4_loader.c` + +- Handles opening the object file. +- Parses the object file sections: + - Code (`0xCADE`), Data (`0xDADA`), and Symbol (`0xC3B7`) sections. +- Populates the memory linked list with addresses, contents, and labels. + +### `lc4_disassembler.h` and `lc4_disassembler.c` + +- Contains the `reverse_assemble` function. +- Disassembles machine code instructions into their assembly equivalents. +- Supports various LC4 instructions as per the instruction set. + +### `Makefile` + +- Automates the compilation process. +- Usage: + - `make all`: Compiles the project. + - `make clean`: Cleans up object files. + - `make clobber`: Cleans up object files and the executable. + +## Sample Output + +When running the program with a valid LC4 object file, the output will display the memory contents in the following format: + +``` +