1 / 12

Learning how to use the Little man computer

Learning how to use the Little man computer

gretel
Télécharger la présentation

Learning how to use the Little man computer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 INPOUTHLT

  2. Learning how to use the Little man computer The following program will demonstrate the load and save instructions of the LMC.  Program INPSTA FIRSTINPSTA SECONDLDA FIRSTOUTLDA SECONDOUTHLTFIRST DATSECOND 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 INPSTA FIRSTINPADD FIRSTOUTINPSUB FIRSTOUTHLTFIRST 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. LMC Branch Instructions (for making decisions) Program INPSTA FIRSTINPSTA SECONDSUB FIRSTBRP SECONDBIGLDA FIRSTOUTBRA PROGRAMENDSECONDBIG LDA SECONDOUT PROGRAMEND HLTFIRST DATSECOND DAT

  6. 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.

  7. LMC Branch Instructions (for implementing loops) Program LDA ONESTA COUNTOUTLOOPTOP LDA COUNTADD ONEOUTSTA COUNTSUB TENBRP ENDLOOPBRA LOOPTOPENDLOOP HLTONE DAT 001TEN DAT 010COUNT DAT

  8. LMC Sample Program • The triangular numbers are as follows • :    •  1     =    1 3     =    1 + 2 6     =    1 + 2 + 3 10    =    1 + 2 + 3 + 4 15    =    1 + 2 + 3 + 4 + 5 21    =    1 + 2 + 3 + 4 + 5 + 6 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 = (1 + 2 + 3) + 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).

  9. Program INP STA VALUE LDA ZEROSTA TRINUM STA NLOOP LDA TRINUMSUB VALUEBRP ENDLOOPLDA NADD ONESTA NADD TRINUMSTA TRINUMBRA LOOPENDLOOP LDA VALUESUB TRINUMBRZ EQUALLDA ZEROOUTBRA DONEEQUAL LDA NOUTDONE HLTVALUE DAT 000TRINUM DAT 000N DAT 000ZERO DAT 000ONE DAT 001 • LMC Sample Program

More Related