Little Man Computer (LMC) Example Programs

Поділитися
Вставка
  • Опубліковано 9 вер 2024
  • Here are a few little simple programs for Little Man Computer.
    They use the simulator from www.PeterHigginson.co.uk/LMC.
    Follow along with them if you are not confident, or if you are more confident pause when the task is displayed, try to create a solution them compare your solution to mine. There are many ways to solve a problem with code, mine will not be the only way but I try to keep things simple and flowing.

КОМЕНТАРІ • 22

  • @yuliethcardenascontreras8102
    @yuliethcardenascontreras8102 Рік тому +1

    Thank you so much for this , honestly !!

  • @MrBobelli
    @MrBobelli 2 роки тому +2

    this saved me ty

  • @phpremium1501
    @phpremium1501 Рік тому +2

    thanks mate

  • @RayRay-ym9xy
    @RayRay-ym9xy Рік тому +2

    Ask the user for two numbers. Print out the answer to first number minus the second
    number, followed by the answer to the second number minus the first number.
    Example test data Expected output
    7, 3 4, -4

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

      That problem should be in the videos.

    • @iainprice8205
      @iainprice8205  Рік тому +2

      Inp
      Sta n1
      Inp
      Sta n2
      Lda n1
      Sub n2
      Out
      Lda n2
      Sub n1
      Out
      Hlt
      n1 dat
      n2 dat

  • @LyricalLemon
    @LyricalLemon Рік тому +1

    just had a curious thought on the last example where instead of multiplying two numbers, what if u were to divide one number by the other
    any idea what that you look like??

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

    What mic do you use? It sounds great.

  • @ghazalhelmy2248
    @ghazalhelmy2248 Рік тому +3

    Hello, how can i reverse the order of an array on LMC?
    For example: [1,2,3,4,5] to [5,4,3,2,1]
    Thank you, your quick response will be highly appreciated!!

    • @xyzabc08
      @xyzabc08 8 місяців тому

      Can u give explanation on how the reverse sequence is generated? Please

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

    Write a LMC program that can convert an n-bit binary number into a decimal number. Display the natural number as
    output before halting the program.
    The first input determines the value for n. It is assumed this value will be equal to four, or greater.
    For example, if the first input is eight (8) then eight subsequent inputs are requested.
    If the subsequent inputs number were 1, 0, 0, 1, 0, 0, 0, 0 then the output would be 9.
    n input values are provided by the user, one for each bit:
    The first of these is the least-significant bit.
    The n’th input is the most-significant bit.

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

      please solve it

    • @iainprice8205
      @iainprice8205  Рік тому +2

      😂I’m not going to do your homework for you. Ha ha ha. This is the method. The first number needs to be stored to help you with a loop counter. Then you need a variable that starts at one. Each loop you add it to itself. Do 1 then 2 then 4 then 8 etc. also each time around the loop you take in a number. If it is one then add on the variable from before and store as a total. At the end output the total.

  • @rotten_eggz
    @rotten_eggz Рік тому +1

    11:05 what would the code look like if it asks for 3 numbers instead of 2 numbers and outputs the largest number?

  • @joshgilchrist05
    @joshgilchrist05 Рік тому +1

    "Ask the user to enter two numbers. C is a counter and N is a number. Output the first C multiplies of N, starting with 0. So, if C is 5 and N is 3, the output is 0, 3, 6, 9, 12". pls help :(

  • @lauryngibb6044
    @lauryngibb6044 11 місяців тому

    Hi Iain,
    Would you be able to write a program which would allow the user to input three numbers and then for the program to display the numbers input largest to smallest please!

  • @minelorkan9023
    @minelorkan9023 Рік тому +2

    “”Enter three numbers and output them in ascending order””. Please help🥹🥹🥹🥹you can immediately write an answer here, I beg you, it is very necessary???!!!

    • @iainprice8205
      @iainprice8205  Рік тому +2

      Descending order here:
      INP
      STA first
      INP
      STA second
      INP
      STA third
      SUB first
      BRP branch1
      LDA first
      STA temp
      LDA third
      STA first
      LDA temp
      STA third
      branch1 LDA third
      SUB second
      BRP branch2
      LDA second
      STA temp
      LDA third
      STA second
      LDA temp
      STA third
      branch2 LDA third
      OUT
      LDA first
      SUB second
      BRP branch3
      LDA second
      OUT
      LDA first
      OUT
      HLT
      branch3 LDA first
      OUT
      LDA second
      OUT
      HLT
      first DAT
      second DAT
      third DAT
      temp DAT

    • @jewaljiji5425
      @jewaljiji5425 Рік тому +1

      @@iainprice8205In line 7, if subtracting first from third produces a negative value (third>first), brp condition isnt satisfied, the program control skips brp and continues downwards. Could you please explain what happens when program control reaches line 14 (STA third). Where does it go next?
      Would appreciate a reply greatly.

    • @iainprice8205
      @iainprice8205  Рік тому +1

      @@jewaljiji5425 the first section is checking the first and third number. If the branch is not taken you then look at the second and third to determine the order.

    • @jewaljiji5425
      @jewaljiji5425 Рік тому +1

      @@iainprice8205 could you specify how the program control travels