An address is a translation.
Virtual Memory
A command-line study of translating virtual addresses through a page table and writing their physical representations.
- Java
- Binary I/O
- Page tables
Private source · project overview
Follow the bits
The program reads eight-byte words, reverses their byte order, separates a page index from an offset, and looks up the frame in a fixed table. The translated addresses are formatted and written to an output file.
A deliberately small model
This models a fixed mapping, not a complete memory manager. The code wraps page indices modulo the table length and only retains addresses within its chosen bit width. Those choices make the scope clear: a small exercise in representation and translation.
VIRTUAL ADDRESS
┌────────────┬─────────────┐
│ page index │ offset │
└─────┬──────┴──────┬──────┘
▼ │
PAGE TABLE │
│ │
└── frame + offset ──► PHYSICAL ADDRESSSplit the address. Translate the page. Keep the offset.
- 01 / input
DataInputStream
readLong() · eight bytes
Long.reverseBytes()
- binary string → 2. checkLengthThenAdd
- 02 / representation
checkLengthThenAdd
Pad to 12 bits
Discard wider values
- accepted address → 3. 12-bit virtual address
- 03 / bit fields
12-bit virtual address
Page: first 5 bits
Offset: remaining 7 bits
- page index → 4. Fixed pageTable[7]
- preserved offset → 5. Frame bits + offset
- 04 / lookup
Fixed pageTable[7]
page index modulo 7
Frames: 2,4,1,7,3,5,6
- frame number → 5. Frame bits + offset
- 05 / translation
Frame bits + offset
Concatenate bit strings
Parse physical address
- formatted result → 6. writeAddressesToFile
- 06 / output
writeAddressesToFile
Uppercase hex text
output/output-OS1
- 1DataInputStream checkLengthThenAddbinary string
- 2checkLengthThenAdd 12-bit virtual addressaccepted address
- 312-bit virtual address Fixed pageTable[7]page index
- 412-bit virtual address Frame bits + offsetpreserved offset
- 5Fixed pageTable[7] Frame bits + offsetframe number
- 6Frame bits + offset writeAddressesToFileformatted result
Read from the implementation
OS1Assignment.java · readFromFilecheckLengthThenAdd / processAddressesaddToOutput / writeAddressesToFile