GO-V.ORG
As seen in

Little Man Computer

The Little Man Computer (LMC) is an instructional model of a computer, created by professor Stuart Madnick in 1965. The LMC is generally used to teach students, because it models a simple von Neumann architecture computer—which has all of the basic features of a modern computer. It can be programmed in machine code (albeit in decimal rather than binary) or assembly code. The LMC model is based on the concept of a little man shut in a closed mail room (analogous to a computer in this scenario). At one end of the room, there are 100 mailboxes (memory), numbered 0 to 99, that can each contain a 3 digit instruction or data (ranging from 000 to 999). Furthermore, there are two mailboxes at the... Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.

The Little Man Computer (LMC) is an instructional model of a computer, created by professor Stuart Madnick in 1965. The LMC is generally used to teach students, because it models a simple von Neumann architecture computer—which has all of the basic features of a modern computer. It can be programmed in machine code (albeit in decimal rather than binary) or assembly code. The LMC model is based on the concept of a little man shut in a closed mail room (analogous to a computer in this scenario). At one end of the room, there are 100 mailboxes (memory), numbered 0 to 99, that can each contain a 3 digit instruction or data (ranging from 000 to 999). Furthermore, there are two mailboxes at the other end labeled "INBOX" and "OUTBOX" which are used for receiving and outputting data. In the center of the room, there is a work area containing a simple two function (addition and subtraction) calculator known as the Accumulator and a resettable counter known as the program counter. The program counter holds the address of the next instruction the Little Man will carry out. This program counter is normally incremented by 1 after each instruction is executed, allowing the Little Man to work through a program sequentially. Branch instructions allow iteration (loops) and conditional programming structures to be incorporated into a program. The latter is achieved by setting the program counter to a non-sequential memory address if a particular condition is met (typically the value stored in the accumulator being zero or positive). As specified by the von Neumann architecture, any mailbox (signifying a unique memory location) can contain either an instruction or data. Care therefore needs to be taken to stop the program counter from reaching a memory address containing data – or the Little Man will attempt to treat it as an instruction. One can take advantage of this by writing instructions into mailboxes that are meant to be interpreted as code, to create self-modifying code. To use the LMC, the user loads data into the mailboxes and then signals the Little Man to begin execution, starting with the instruction stored at memory address zero. Resetting the program counter to zero effectively restarts the program, albeit in a potentially different state. BRZ END // Branch to program END if input = 0 STA VALUE // Store input as VALUE LOOP LDA RESULT // Load the RESULT ADD VALUE // Add VALUE, the user provided input, to RESULT STA RESULT // Store the new RESULT LDA COUNT // Load the COUNT ADD ONE // Add ONE to the COUNT STA COUNT // Store the new COUNT SUB VALUE // Subtract the user provided input VALUE from COUNT BRZ ENDLOOP // If zero (VALUE has been added to RESULT by VALUE times), branch to ENDLOOP BRA LOOP // Branch to LOOP to continue adding VALUE to RESULT ENDLOOP LDA RESULT // Load RESULT OUT // Output RESULT BRA START // Branch to the START to initialize and get another input VALUE END HLT // HALT - a zero was entered so done! RESULT DAT // Computed result (defaults to 0) COUNT DAT // Counter (defaults to 0) ONE DAT 1 // Constant, value of 1 VALUE DAT // User provided input, the value to be squared (defaults to 0) ZERO DAT // Constant, value of 0 (defaults to 0) Note: If there is no data after a DAT statement then the default value 0 is stored in the memory address. In the example above, BRZ ENDLOOP depends on undefined behavior, as COUNT-VALUE can be negative, after which the ACCUMULATOR value is undefined, resulting in BRZ either branching or not ( ACCUMULATOR may be zero, or wrapped around). To make the code compatible with the specification, replace: ... LDA COUNT // Load the COUNT ADD ONE // Add ONE to the COUNT STA COUNT // Store the new COUNT SUB VALUE // Subtract the user provided input VALUE from COUNT BRZ ENDLOOP // If zero (VALUE has been added to RESULT by VALUE times), branch to ENDLOOP ... with the following version, which evaluates VALUE-COUNT instead of COUNT-VALUE , making sure the accumulator never underflows: ... LDA COUNT // Load the COUNT ADD ONE // Add ONE to the COUNT STA COUNT // Store the new COUNT LDA VALUE // Load the VALUE SUB COUNT // Subtract COUNT from the user provided input VALUE BRZ ENDLOOP // If zero (VALUE has been added to RESULT by VALUE times), branch to ENDLOOP ... Another example is a quine, printing its own machine code (printing source is impossible because letters cannot be output): LOAD LDA 0 // Load position 0 into the accumulator. This line will be modified on each loop to load the next lines into the accumulator OUT // Output the accumulator's value. The accumulator's value will be the line that was just loaded SUB ONE // Subtract 1 from the value in the accumulator. This is so we can do the BRZ in the next step to see if we are on the last line in the program BRZ ONE // If the previous subtraction has made the accumulator 0 (which means we had the value 001 in the accumulator), then branch to position ONE LDA LOAD // Load the LOAD position into the accumulator, this is in preparation to increment the address digits for this position ADD ONE // Increment the position digits for the LOAD line. The value currently in the accumulator would, if read as an instruction, load the next line into the accumulator, compared to the last line loaded STA LOAD // Store the newly incremented LOAD line back in the LOAD position BRA LOAD // Return to the beginning of the loop ONE DAT 1 // The variable ONE. If read as an instruction, this will be interpreted as HLT/COB and will end the program This quine works using self-modifying code. Position 0 is incremented by one in each iteration, outputting that line's code, until the code it is outputting is 1, at which point it branches to the ONE position. The value at the ONE position has 0 as opcode, so it is interpreted as a HALT / COB instruction. ==See also== CARDboard Illustrative Aid to Computation, another instructional model TIS-100 (video game) Hack computer, another educational abstract computer Human Resource Machine, a computer game heavily influenced by the LMC WDR paper computer Digi-Comp I The Little Man Stack Machine, an expansion on the LMC with dedicated stack instructions. Peter Higginson's online LMC emulator. Tiny Binary Computer, a binary computer simulation that uses an extension of the LMC instruction set.

source: e01 Encyclopedia · licence: CC BY-SA 4.0 · page · source revision

Cite this

"Little Man Computer". 1789799735. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1375678679

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·