π Project Overview β
The Little Man Computer (LMC) is a simplified model of a computer designed for educational purposes. It features 100 memory cells (numbered 0 to 99), each capable of holding a number from 0 to 999. The computer includes an accumulator register, an input queue, and an output queue. LMC supports a limited set of instructions and a simplified assembly language.
π― Project Goals β
The primary objectives of this project were to develop:
- An LMC simulator that, given the initial memory content (a list of 100 numbers) and a sequence of input values, simulates LMC's behavior and produces the output queue content after the LMC halts.
- An assembler that converts a file written in LMC's simplified assembly language into the initial memory content.
π§βπ» The challenge β
My main challenge was to implement the LMC simulator using Prolog, applying theoretical knowledge from the programming languages course. Initially, it was challenging to adapt to Prolog's unique logic programming paradigm. However, with persistence, I gained proficiency in Prolog, which I found incredibly rewarding and enjoyable. Hereβs a snippet of the Prolog code that demonstrates the logic used in the project:
check_instruction_cell([[L, I] | Xs], C, [[I] | Ys]) :-
lmc_text_instruction(I, _Pred),
!,
assert(label(L, C)),
NC is C + 1,
check_instruction_cell(Xs, NC, Ys).
This snippet defines a predicate to check each instruction cell, ensuring it follows the LMC's simplified assembly rules. The predicate processes a list [[L, I] | Xs]
, where L
is a label and I
is an instruction, with the current cell index C
, producing a list of instructions [[I] | Ys]
without labels. It verifies if I
is a valid LMC instruction using lmc_text_instruction(I, _Pred)
, commits to the current choice with the cut operator !
, associates the label L
with the cell index C
using assert(label(L, C))
, increments the cell index (NC is C + 1
), and recursively processes the rest of the list (check_instruction_cell(Xs, NC, Ys)
). What a beauty, right? This line showcases the elegance of Prolog's pattern matching and logical flow, embodying the joy of solving complex problems with concise code.
π Impact and Reflection β
This project not only deepened my understanding of Prolog but also strengthened my problem-solving skills in logic programming. Despite the difficulties, the experience was highly educational and enjoyable, solidifying my appreciation for Prolog. It was super FUN, and I love Prolog. I will never forget this beautiful language! π₯°