A virtual memory implementation with paging support built on top of a LC-3 virtual machine architecture. Features memory management, process handling, and system calls.
- Overview
- Features
- Implementation Details
- Building and Running
- Sample Programs
- Acknowledgements
- License
This project extends an existing virtual machine implementation that uses simple assembly language, LC-3 to incorporate paging and virtual memory management capabilities. It builds upon Andrei Ciobanu's LC-3 VM implementation by adding:
- Page-based memory management
- Virtual-to-physical address translation
- Multi-process support with PCBs (Process Control Blocks)
- Dynamic memory allocation
- System calls for process control and memory management
The implementation assumes a 16-bit address space with 4KB page size and includes features like:
- Separate code and heap segments
- Read/write access control at page level
- Process isolation through virtual address spaces
- Free page frame management using bitmaps
- 128KB total memory space (16-bit addressing)
- 4KB page size
- Page-level access control (read/write permissions)
- Dynamic page allocation and freeing
- Bitmap-based free page tracking
- Process Control Block (PCB) support
- Context switching capabilities
- Process creation and termination handling
- Process scheduling through yield system call
yield: Voluntarily releases CPU controlbrk: Dynamic memory allocation/deallocationhalt: Process termination with cleanup
- Reserved region (0x0000 - 0x2FFF)
- Code segment (0x3000 - 0x4FFF, 8KB fixed)
- Heap segment (0x5000+, dynamically sized)
-
Page Table Entry (PTE) Structure
- 5 bits: Page Frame Number (PFN)
- 8 bits: Padding
- 3 bits: Access control (write, read, valid)
-
Physical Memory Organization
- First 8KB: OS region (PCBs, metadata)
- Third 4KB page: Page Tables
- Remaining space: Page frames for processes
-
Process Control Block Fields
- PID
- Program Counter
- Page Table Base Register
The implementation includes several protection mechanisms:
- Segmentation fault detection
- Read/write permission enforcement
- Invalid page access prevention
- Reserved memory protection
# Compile the project
make
# Run single program
./vm code.obj heap.obj
# Run multiple programs
./vm code1.obj heap1.obj code2.obj heap2.obj
# Run sample programs
./samples/sample1.sh
./samples/sample2.sh
./samples/sample3.sh
./samples/sample4.sh
./samples/sample5.shThe project includes several sample scripts that demonstrate different aspects of the VM:
- Single process that adds 10 numbers from memory
- Tests basic memory access and process execution
- Process that requests additional memory page via BRK before adding numbers
- Tests dynamic memory allocation and page table management
- Two copies of Sample1 running concurrently
- Tests basic multi-process support and context switching
- Three processes running together:
- Two processes that yield explicitly (yld.c)
- One process that allocates memory (brk.c)
- Tests mixed workload with memory allocation and context switching
- Two copies of a program (brk2.c) that each request two memory pages with a yield in between
- Tests interleaved memory allocation between processes
- This project builds upon the LC-3 virtual machine implementation by Andrei Ciobanu. The original implementation provided the foundation for the basic VM functionality, which was then extended with paging and process management capabilities.
- This project was developed as part of the Operating Systems course at Sabanci University. Special thanks to the course instructor Süha Mutluergil and teaching assistants for their guidance and support. The pictures used are prepared by the OS course team.
This project is licensed under the MIT License - see the LICENSE file for details.

