LMC Machine Level Programming


Machine level processing of instructions involves a systematic and almost mechanical repetition of actions.


Sample Program Execution


Encoding a Simple, Linear Program


LMC Flow Control Instructions

Flow control instructions enable machine level execution to perform the standard selection and repetition sequences.


Symbolic Labels

In the same way that mnemonic codes make it easier to write (and think about) instructions, "symbolic labels" make it easier to work with mailbox addresses. Instead of coding numeric addresses, it is usually easier to use label "names"; of course, for this to work, any label "name" which is used in an instruction must be defined as being the identifier ("symbolic label") for a mailbox containing either an instruction or a data value.


IF...THEN...ELSE...ENDIF (Selection)


WHILE...DO...ENDWHILE (Repetition)


Sample Program


Subroutine and Function Calls

All practical computer processors provide some method, at a low level, for using subroutines and functions. Unfortunately, the Little Man Computer is not a "practical computer processor". We could, however, imagine a more advanced model of the LMC, the "son of LMC" which would provide such support.

There are many different ways this support could be implemented even within a computer architecture as limited as the LMC. Note that a significant problem in implementing additional instructions to "call" and "return" from a subroutine involves the fact that almost all the numeric instruction code values have been used up. It is possible however to "squeeze" this subroutine handling ability in. The method described below is by no means "standard" but it will provide the necessary capabilities.

We will assume that our modified "son of LMC" has an additional instruction "CALL xy" with a numeric form "0xy". This CALL instruction will behave very much like the JMP instruction except that before changing the counter, it will save the contents of the counter plus "900" (that is a JMP to the counter contents address) in the mailbox immediately before "xy" (that is in the mailbox with address xy-1). Notice that at the time this "save" is done, the counter will already have been incremented and will contain the address of the instruction serially after the CALL.

Subroutines will always be coded to allow for a mailbox location immediately before the first instruction of the subroutine. When a subroutine has finished processing requirements, it will JMP to that "prefix" mailbox which will, in turn, contain the JMP instruction (provided by the CALL) back to the instruction immediately following the CALL.

Example:

The CALL RTN (006) in mailbox 01 will change the contents of mailbox 05 (05 being the mailbox immediately before 06) to contain "902" (a JMP to the mailbox after this CALL), and then it will change the contents of the counter to contain "06". The next instruction to be performed will therefore be the one in mailbox 06.

When execution reached the JMP RTN-1 (905) in mailbox 09, execution of this instruction will cause the counter to change to 09. Therefore the next instruction to be performed will be the "902" placed in mailbox 05 by the earlier CALL RTN. The next instruction after this will then be the one in mailbox 02, the second IN.

After the second IN, a second CALL RTN is performed, but this time the contents of mailbox 05 are changed to "904", a JMP to the instruction following this second CALL RTN.