Purpose Of The Following Little Man Computer Program
This program is simulating how is a CPU works with ALU and RAM.
Let me introduce how this program works.
00 IN; <-- Load the first input. (Let say it is 2.)
01 STA 89; <-- Store the value 2 into RAM with the address 89.
02 IN; <-- Load the second input. (Let say it is 3.)
03 STA 90; <-- Store the value 3 into RAM with the address 90.
04 SUB 89; Deduct the current value by the value contained in 89. (The result will be 3-2 = 1.)
05 SKP; <-- Skip the next line if the current value is >=0.
06 JMP 09; <-- This will be skipped as the current value is one which is >=0.
07 LDA 89; Load value in the address 89 into current value.
08 JMP 10; <-- Jump to line 10;
09 LDA 90; <-- This will be skipped.
10 STA 92; <-- Store the current value into 92. (2 will be stored into.)
11 IN; <-- Load the third input. (Let say it is 9.)
12 STA 91; Store 9 into the RAM with the address 91.
13 SUB 92; Deduct the current value by the value in address 92. (9-2 = 7.)
14 SKP; <-- Skip the next line if the current value is >=0.
15 JMP 19; <-- This will be skipped.
16 LDA 92; <-- Load the value in address 92 to be the current value. (2 will be executed.)
17 JMP 19; <-- Jump to line 19.
18 LDA 91; <-- This will be skipped.
19 OUT; <-- Output the current value 2.
So, we can know how CPU works with ALU and RAM by using Little Man Computer.
And the purpose of this program is actually finding the minimum value among three inputs.
If we modify this program a little bit, we can change the purpose of this program into finding the maximum value.
Steps:
1. Change 05 into SKN;
2. Change 14 into SKN;
And the purpose of this program is actually finding the minimum value among three inputs.
If we modify this program a little bit, we can change the purpose of this program into finding the maximum value.
Steps:
1. Change 05 into SKN;
2. Change 14 into SKN;

So, we can 'how' CPU works with ALU and RAM by using Little Man Computer.
回覆刪除know is missed
Nice work with clear explanation , good
回覆刪除It is excellent that you try to substitute real values into the example, it helps me to understand the example clearer.
回覆刪除Thank you for your blog which is very clear defined of the explanation of the example of little man computer. I suggest that you can talk more about how the relationship between little man computer and how the CPU work.
回覆刪除WELL DONE. CLEAR explantion and purpose of the program. KEEP going!
回覆刪除Explained in detail. Easy to understand and follow ^^!
回覆刪除Can u also give a set of sample input and output?
Good and fluent explanation on how the above program run
回覆刪除Each steps are explained woth details.
Modification are provided too