Code Monkey home page Code Monkey logo

lmc's Introduction

LMC

Intro

Little man computer (LMC) is a simple model of a computer that is generally used for learning purposes. When I first read about LMC I tought that programming my own simulator would be a great learning opportunity. Simulator is mostly based on Wikipedia entry of LMC. My simulator also has a functional assembler that supports mneumonics and labels for ease of programming.

Quick Start

  1. Open the app
  2. Choose a pre-loaded program
  3. Click Load to get the program
  4. Click Assemble to assemble the program to the memory
  5. Click Step/Run to run the program

Registers

The computer has five registers. Three of them hold an integer value and two of them have a boolean value. Program counter holds the value for the next instruction to be executed. Accumulator is used as a work memory that is used in almost every instruction. Cycle count counts the cycles your program has used and can't be altered or accessed. Negative flag shows if accumulator value is negative after a subtraction operation. End of program flag is used to indicate that the end of the program has been reached.

Memory

Memory consists of 100 slots of 3 digit decimal numbers. The same memory is used for both instructions and program memory.

Instructions

Instructions consist of 3 digit decimal numbers where first digit generally stands for instruction to execute and last two digits stand for memory address that are used with instruction.

List of instructions

Machine code Assembler Explanation
1XX ADD Adds the value in given memory index to the accumulator. Resets negative flag to false.
2XX SUB Subtracts the value in given memory index from the accumulator. If the new accumulator value would be less than zero sets negative flag to true and sets accumulator value to zero.
3XX STA Replaces current value in given memory index with the value in the accumulator.
5XX LDA Replaces current accumulator value with a value from given memory index and resets negative flag to false.
6XX BRA Replaces current value in the program counter with given address.
7XX BRZ If the accumulator value is zero, replaces current value in the program counter with given address.
8XX BRP If the accumulator value is positive (negative flag is false), replaces current value in the program counter with given address.
901 INP Replaces the accumulator value with the next value in the inbox and removes that value from the inbox.
902 OUT Copies the value from the accumulator to the outbox.
000 HLT Stops the program from running.
None DAT Stores a value to the next available memory slot. Not an instruction but only used in assembler with labels.

GUI

  1. Menubar
  • About
    • Links to the github page.
  • Load
    • Loads a template program to the code input.
  • Assemble
    • Assembles code to the memory.
  • Step
    • Execute the next instruction.
  • Run
    • Executes the program instantly until the end (or 1000 cycles).
  1. Code Input
  • Input your code here.
  1. Reg
  • PC
    • Shows the current value of the program counter.
  • CC
    • Shows the amount of computer cycles executed so far.
  • AC
    • Shows the current value of the accumulator.
  1. Inbox
  • Here you can enter the input. Each value is separated by new line.
  1. Outbox
  • Your program prints the output here.
  1. Memory
  • Shows current value in each memory address.

lmc's People

Contributors

antti-k avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.