Presentation is loading. Please wait.

Presentation is loading. Please wait.

Learning how to use the Little man computer

Similar presentations


Presentation on theme: "Learning how to use the Little man computer"— Presentation transcript:

1 Learning how to use the Little man computer
The following program will demonstrate the input and output instructions of the LMC.  The first instruction will copy a three-digit number from the In Box to the accumulator, and the second instruction will copy the value of the accumulator to the Out Box. Program INP OUT HLT

2 Learning how to use the Little man computer
The following program will demonstrate the load and save instructions of the LMC.  Program INP STA FIRST INP STA SECOND LDA FIRST OUT LDA SECOND OUT HLT FIRST DAT SECOND DAT

3 Learning how to use the Little man computer
The following program will demonstrate the add and subtract instructions of the LMC.  Note: The Accumulator (calculator) in the LMC is only designed to work with non-negative three-digit numbers.  Mathematical operations which produce values greater than 999 or less than 000 can cause undefined effects to occur.  Program INP STA FIRST INP ADD FIRST OUT INP SUB FIRST OUT HLT FIRST DAT

4 LMC Branch Instructions (for making decisions)
The following program will demonstrate how to use the branching instructions of the LMC to implement decision making.  Note: The Branch Always instruction should only be used to connect paths indicated by your flowchart.  Flowchart The following is the flowchart for a program that will output the largest of two input values.  Note: if the values are equal, both numbers represent the largest value, so either can be output.

5

6 LMC Branch Instructions (for making decisions)
Program INP STA FIRST INP STA SECOND SUB FIRST BRP SECONDBIG LDA FIRST OUT BRA PROGRAMEND SECONDBIG LDA SECOND OUT PROGRAMEND HLT FIRST DAT SECOND DAT

7 LMC Branch Instructions (for implementing loops)
The following program will demonstrate how to use the branching instructions of the LMC to implement looping.  Note: The Branch Always instruction should only be used to connect paths indicated by your flowchart.  Flowchart The following is the flowchart for a program that will output the values from 1 to 10.

8

9 LMC Branch Instructions (for implementing loops)
Program LDA ONE STA COUNT OUT LOOPTOP LDA COUNT ADD ONE OUT STA COUNT SUB TEN BRP ENDLOOP BRA LOOPTOP ENDLOOP HLT ONE DAT 001 TEN DAT 010 COUNT DAT

10 LMC Sample Program The triangular numbers are as follows :     1     =    1  3     =     6     =     10    =     15    =     21    =     etc. The series begins with 1 (the first triangular number).  To calculate the nth triangular number, n is added to the previous triangular number.  For example, the fourth triangular number is calculated by adding 4 to the third triangular number (which is 6), i.e. 10 = ( ) + 4. Write a program that takes a single value (greater or equal to zero) as input and outputs which triangular number it is or 0 if it is not a trinangular number.  For example, if the input is 15, the output will be 5 (15 is the 5th triangular number); and if the input is 7, the output will be 0 (7 is not a triangular number).

11

12 LMC Sample Program Program
INP STA VALUE LDA ZERO STA TRINUM STA N LOOP LDA TRINUM SUB VALUE BRP ENDLOOP LDA N ADD ONE STA N ADD TRINUM STA TRINUM BRA LOOP ENDLOOP LDA VALUE SUB TRINUM BRZ EQUAL LDA ZERO OUT BRA DONE EQUAL LDA N OUT DONE HLT VALUE DAT 000 TRINUM DAT 000 N DAT 000 ZERO DAT 000 ONE DAT 001 LMC Sample Program


Download ppt "Learning how to use the Little man computer"

Similar presentations


Ads by Google