GithubHelp home page GithubHelp logo

haskell-little-man-computer's Introduction

Haskell-Little-Man-Computer

A simple implementation of Little Man Computer in Haskell(Denoted as LMC in later docs)

Detailed discription of LMC: http://en.wikipedia.org/wiki/Little_man_computer

###LMC Instruction Code Reference

  • INP: ask user to type in a number then store it in the accumulator
  • STA: get the value in the accumulator then store it in the mailbox of the given label
  • LDA: get the value in the mailbox of the given label then store it in the accumulator
  • ADD: get the value in the mailbox of the given label, add it with the accumulator and store
  • SUB: subtract the value in mailbox of the given label from the value in the accumulator
  • OUT: print out the value in the accumulator
  • BRA: jump to the instruction with the given label
  • BRZ: check the value in the accumulator. if it is zero jump to the instruction with the given label
  • BRP: check the value in the accumulator. if it is positive, jump to the instruction with the given label
  • HLT: terminate the program
  • DAT: declare a variable with an initial value. The initial value is zero by default

###Rules:

1.Every line must contain an instruction

2.Each line starts with either a label or a space and/or end with a comment.

3.DAT instructions will appear only at the bottom of a program

###Sample Code:

####A) INP STA FIRST INP STA SECOND LDA FIRST SUB SECOND OUT HLT FIRST DAT SECOND DAT

####B) INP LOOP SUB ONE // Label this memory address as LOOP, The instruction will then subtract the value stored at address ONE from the accumulator OUT BRZ QUIT // If the accumulator value is 0, jump to the memory address labeled QUIT BRA LOOP // If the accumulator value is not 0, jump to the memory address labeled LOOP QUIT HLT // Label this memory address as QUIT ONE DAT 1 // Store the value 1 in this memory address, and label it ONE (variable declaration)

haskell-little-man-computer's People

Contributors

simonzsx avatar

Stargazers

 avatar

Watchers

 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.