Little Man Computer (LMC) Explained: Hello World in Machine Instructions!
Вставка
- Опубліковано 9 вер 2024
- This video explains the best way to understand how a computer works and how your program code (machine instructions) "tell" the hardware what to do. Little Man Computer is a thought experiment developed at MIT by Dr. Stuart Madnick that helps us understand the process that unfolds within the computer CPU or Central Processing Unit.
This video starts with a brief explanation of the components of a little man computer, but also identifies the actual components from a real processor that they represent. This will make the transition easier when start dissecting the workings of a real process in later videos. The video then describes the core of the Little Man Computer instruction set (branching is brought in in the next video in this series) and the instruction cycle is described by following along with "Hello World" program (which is actually an addition problem) running in the system.
Please like this video and subscribe and would like to see more like it! / @codingcoach
I have a recommended introduction to Little Man computer video here: • Little Man Computer Ex...
The next video in this series expands on this one by following a subtraction problem that returns an absolute value (positive difference of 2 numbers). We see how high level code transitions through compilation and assembly and how branching is used in the CPU, you can that video here: • Little Man Computer (L...
This video is part of my Fundamentals of Computer Science series which you can find here: • Computer Science Funda...
It is also part of my Computer Organization and Architecture course which you can find here: • Computer Organization ...
Another set of videos that may be helpful is my series on Binary, Hexadecimal and Octal numbers which you can find here:
- Number Systems (how to convert): • Number Systems: How to...
- Binary Arithmetic: • Binary Math: How to do...
- Hexadecimal and Octal Arithmetic: • Hexadecimal and Octal ...
- Hexadecimal, Octal and Binary cheatsheet (quick conversion guide): • Hexadecimal Octal and ...
Here are presentation slides that can be used as a supplement to follow along and as a future reference for this content: drive.google.c...
As I mentioned in the video, try creating your own programs here. Mathematics are the easiest first ones to try, I recommend using load and store for practice saving all the values in open memory addresses. A good next step would be a multiplication or division problem!
I am not sure if these addresses are correct, but here is my attempt at a subtraction problem!
901 → in
(in input box) 007 (new value in accumulator)
317 → store in address 17
901 → in
(in input box) 004 (new value in accumulator)
318 → load from address 18
517 (007 new/current value in accumulator) → load from address 17
218 (subtracts 004[address 18] from 007[address 17]) (003 new value in accumulator)
319 → store in address 19
902 (output 003) → out
000 → halt
@@roxannelai7803 Looks great! one small change to your 4th line 318 would store, not load
subtract 2 numbers input from the user:
INP (user inputs 10)
STA NUM1
INP (user inputs 5)
STA NUM2
SUB NUM2 (10 - 5)
OUT (output result)
HLT (halt)
NUM1 DAT 000 (label to store data)
NUM2 DAT 000 (label to store data)
@@ethanhart8116 note your result will actually be 0! You are actually subtracting 5-5. Remember that the contents of the accumulator are left alone after you STA of NUM2, and you do not bring NUM1 back, so the accumulator contains the 5. You then subtract the value of NUM2 again (5) leaving you a 0.
You're very good at concise explanation. Commenting again for the algorithm :)
Thank you! Big props if you can make the yt algorithm run in LMC :P
Multiply any # by 4:
901
Great supplement to my lectures, thank you for this!
You're very welcome!
@@CodingCoach 🙏🙏
901 --> (read 9)
310 --> (store 9 in 10)
901 -->(read 6)
311 -->(store 6 in 11)
510 -->(load 9)
611 -->(sub 6 from 9)
902 -->(out put value of 3)
000 -->(end/halt)
Looks good!
00 | 901 -> INP
(of 078)
01 | 315 -> STA (store 78 in box 15)
02 | 901 -> INP(of
028)
03 | 316 -> STA (store 28 in box 16)
04 | 515 -> LDA (loads 78 into accumulator)
05 | 216 -> SUB (subtracts 28 from accumulator value(78))
06 | 902 -> OUT (outputs accumulator value(50))
07 | 000 -> HLT
Looks good!
901 -> INP
(Put 15 in accumulator)
308 -> STA (store 15 in box 08)
901 -> INP
(Input second value 25 in accumulator)
309 -> STA (store 25 in box 09)
308 -> LDA
98 -> ADD (add 15+25)
307 -> STA (store the result in box 07)
902 -> OUT (puts the result in the output box)
000 -> HLT
Hi Matt,
This is very good, I noticed a subtle bug.. your STA on line 01 (storing the 15 value) overwrites your HLT instruction in mailbox 08!
Also your add should be 109 (if you loaded 08 before). Lastly your STA for the result overwrites itself.
Interesting I see everyone is storing to different memory. What if I constantly use the same memory? Such as,
901 (Take in 2)
320 (Store 2 to Mem 20)
901 (Take in 3)
220 (Subtract 2 from 3)
320 (Store 1 to 20)
902 (Output 1)
000 (Stop running)
Yes, this would work in this case, it is equivalent to:
int myNumber = input();
myNumber = input() - myNumber;
output(myNumber);
I used input() in-line in the subtract statement to highlight that you are not assigning it in memory, just keeping it in a register.
901 -> (read in value 005)
317 -> (store value 005 in address 17)
901 -> (read in value 003)
316 -> (store value 003 in address 16)
901 -> (read in value 002)
117 -> (Adds value 005 to 002 results in 007)
116 -> (Adds value 003 to 007 results in 010)
902 -> (output calculated value 010)
000 -> (ends program)
Nice work!
GREAT VIDEO!! THANK YOU!!
You're welcome!
thanks for this video!!
901 --> (input 5 in accumulator)
308 -> (store 5 in address slot 8)
901 --> (input 5 in accumulator)
108 --> (add 5 and 5 in accumulator now 10 in accumulator)
208 --> (subtract 002 from address slot 8, now 8 in accumulator)
902 --> (outputs 8)
000--> (halts)
_ maverick
901
(in input box) 005 (new value in accumulator)
310
901
(in input box) 003 (new value in accumulator)
311
510 (005 new value in accumulator)
211 (subtracts 003 from address 11) (002 new value in accumulator)
312
902 (output 002)
Nice work! great work storing all the values and the answer... Soon we will look more at why these can be left out as an optimization. Great first program.
I agree Logan
great!
Hi, where can I download this program
Hello Coach, my niece need help. Do u teaches one on one pls? I like to have ur response. Thank you