Little Man Computer (LMC) Explained: Branching, Compilation and Assembly

Поділитися
Вставка
  • Опубліковано 9 вер 2024
  • This video continues the journey of understanding how a computer runs program code (machine instructions) which "tell" the hardware what to do. Here we add branching instructions to complete our Little Man Computer instruction set. Little Man Computer (LMC) 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.
    We see how using branching to change program flow allows us to perform a conditional (if statement) in machine instructions. The conditional statement is "compiled" from a high level language to LMC Assembler, then assembled into LMC instructions. We discuss how the instructions are "loaded" into memory and then run them through the LMC instruction cycle to see the way the information moves around I/O, registers and memory.
    *** NOTE: there is a mistake on line 5 and 9 of the LMC instructions, the subtraction op code is 2 not 1 (which is add). I made a note of this in Closed Captioned messages, but you must have CC on to see the messages! ****
    I have a recommended introduction to Little Man computer video here: • Little Man Computer Ex...
    And a "Hello LMC" video where we do a smaller program and talk more in-depth about the instruction cycle and basic instructions: • Little Man Computer (L...
    This video is followed by a more advanced one that introduces labels and iteration: • Little Man Computer (L...
    Please like this video and subscribe and would like to see more like it! / @codingcoach
    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...

КОМЕНТАРІ • 36

  • @CodingCoach
    @CodingCoach  4 роки тому +2

    Try creating your own little man computer branching algorithm that solves a common computing problem. If you want to be really adventurous, try creating a loop or recursion of some sort. This will be a topic I will cover in a future video and you will get to check you work against it!

    • @roxannelai7803
      @roxannelai7803 3 роки тому +1

      I watched the video about iteration, branching and labels and wanted to try my hand at the countdown problem. I am not sure that this is the right way to go about it (the video only had around 6 steps), but I tried my best! So, here is my try at the countdown problem with both the assembler and LMC instructions:
      00 INP /901
      01 STA A /312
      02 loop LDA A /512
      03 OUT /902
      04 SUB one /113
      05 STA A /312
      06 BRZ endIt /708
      07 BR(A) loop /602
      08 endIt LDA A /512
      09 SUB A /112
      10 OUT /902
      11 HLT /000
      12 A DAT
      13 one DAT

    • @CodingCoach
      @CodingCoach  3 роки тому

      Roxanne this looks very good!
      Couple of things I noticed:
      1. Lines 4 and 9 use the SUB assembler but have an add op code! (this was an error I made in this video that i noted in with text on the screen, 1 = add, 2 = sub) so i believe both lines should have had a 213 and 212 respectively.
      Running the program with an input value of 3 I get:
      3
      2
      1
      0

    • @roxannelai1514
      @roxannelai1514 3 роки тому

      @@CodingCoach Thank you! And okay got it, I must have missed the text on the screen. It is definitely not the most concise, but as you said, at least it works!

  • @davegraham7550
    @davegraham7550 3 роки тому +2

    LMC should be used everywhere in the world.

    • @davegraham7550
      @davegraham7550 3 роки тому

      Teaching to ngabere language speakers in Panama today. Mostly learner in one session.

    • @CodingCoach
      @CodingCoach  3 роки тому

      LMC is an amazing way to break down how the ISA works, I love using it as a starting point! Enjoy the lesson!

    • @davegraham7550
      @davegraham7550 3 роки тому +1

      Works well going between any languages. Digital and language learning are a natural match.

    • @davegraham7550
      @davegraham7550 3 роки тому

      From as soon as people are learning to speak and write..

    • @davegraham7550
      @davegraham7550 3 роки тому

      All people can understand computing, a small set of simple actions done at very high speed. Programming via programming languages can come later and is far less fundamental than understanding the digital engine analagious in many ways to a combustion engine. A repeating cycle and that is all it can do.

  • @erim1434
    @erim1434 3 роки тому +2

    This was very helpful, thank you!

  • @jaygobeasty4162
    @jaygobeasty4162 3 роки тому +1

    great video, can't fid anything like this on the internet

  • @alessandramancas416
    @alessandramancas416 Рік тому

    Thank you this was so helpful!!

  • @pranavsuthar923
    @pranavsuthar923 3 роки тому +2

    ahh that window reflectiom :)

  • @nataliejohn376
    @nataliejohn376 3 роки тому +2

    Shouldn't step 5 be 213 bcs it's substract? But u put 113. Am I misunderstanding this or did u do a mistake there?

    • @CodingCoach
      @CodingCoach  3 роки тому +2

      yes you are correct!
      I had added a note in the description and I think I added subtitles although I understand most people don't have the on. UA-cam does not seem to let me edit the video after I've posted it at least not when I did it.

    • @nataliejohn376
      @nataliejohn376 3 роки тому

      @@CodingCoach aaa I see. But overall, the video made me understand more about LMC. Online classes make it really hard for me to understand so I really am grateful to you 😁

  • @vedbhanushali608
    @vedbhanushali608 3 роки тому +1

    thank you sir.

  • @gailenkelly5481
    @gailenkelly5481 3 роки тому

    How would you just output a number, say 1, using a branch for only if the first input is greater than the second number? Can you specify the output instead of BRP or BRZ?

    • @CodingCoach
      @CodingCoach  3 роки тому +1

      If you input 2 numbers and then subtract the first from the second and the result is negative you know the first number was bigger then the second (remember you have to store the first)
      so..
      00 INP // lets say input is 5
      01 STA 10
      02 INP // lets say input is 3
      03 SUB 10 // would be 3 - 5 (since 3 is still in the acc)
      so choosing a BRP would work for your question since anything 0 or greater would indicate a larger second input. If it does not branch the first number was bigger
      something like..
      04 BRP 07
      05 LDA 11 // we will put a 1 here
      06 OUT
      07 HLT
      10 DAT
      11 001
      I think if understood your question correctly this would work.

    • @gailenkelly5481
      @gailenkelly5481 3 роки тому

      @@CodingCoach Ok, I assumed what you just wrote except I got stuck after the branch instruction. Thank you!

  • @nadirberrachedi4347
    @nadirberrachedi4347 2 роки тому

    Hi there i am trying to create a program which displays the highest number. I tried to follow your tutorial but got a bit stuck. the program is always outputing the first number. Do you know what the problem is?
    INP
    STA num1
    INP
    STA num2
    SUB num1
    BRP pos
    pos LDA num2
    LDA num1
    OUT
    BRA exit

    exit HLT
    num1 DAT
    num2 DAT