Thursday 26 March 2015

March 26th LMC Tasks

TASK 1 Using the following: LMC:
Complete the three programs outlined below.  Follow, the instructions carefully and make a note about what is happening.
TASK 2
In Google.doc screen dump the output and label with call-outs
Features:
  • Uses the same instruction set as theatkinsn.yorku.ca version.
  • Loads and saves assembly language programs as text files.
  • Supports labels for both branching and data.
  • Supports indentation making code easier to follow.
  • Does not remove the original code when assembly takes place.
  • Features both a STEP and a RUN mode and the ability to switch between them while a program is running.
  • In STEP mode, the 'Little Man' explains the next instruction before it is executed.
  • Allows assembly language programs to be pasted directly into the program window.
  • Allows programs to be copied from either text window for use in reports.
  • Run mode is faster than the atkinsn.yorku.ca version.
  • Allows line annotation such as: loop LDA value1    // Start of main loop.
  • Produces an assembly language version without labels or annotation, makes it easier to understand the assembled code in RAM.
A guide to the LMC screen - click to enlarge
  •  INPUT is via an 'input device' rather than the keyboard, allowing integer values in the range -999 to 999.
  • Multi-line output makes it easier to follow programs that have more than a single output.
  • 'Machine Code' instructions in RAM can be edited directly (the U button will update any changes to the current instruction).

1.     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
INP
OUT
HLT

What you should do
1.     Click on the "LMC Simulator Applet" link to start the LMC simulator.
2.     Clear the Message Box and all of the LMC mailboxes -- click the "Clear Messages" button and the "Clear" button if necessary.
3.     Copy the three-line program above and paste it into the Message Box
4.     Click on the "Compile Program" button.
5.     Click on the "Run" button.
6.     When prompted, enter a three-digit number in the "In-Box", and press the "Enter" button.
What you should see
  • After the program is compiled, you should see 901 in mailbox 0 and 902 in mailbox 1.  The Program Counter should start at 0 (click on "Reset" if necessary).
  • When you click on "Run" or "Step", the Message Box will describe the actions of each instruction.
  • After the INP instruction, the Accumulator has a copy of the value in the In Box.
  • After the OUT instruction, the Out Box has a copy of the value in the Accumulator.
  • The final value of the Program Counter is 2.  This mailbox holds 0 - the machine code instruction that tells the LMC to stop executing your program.

 

2.      LMC Load and Save Instructions

The following program will demonstrate the load and save instructions of the LMC.  

Program

INP
STA FIRST
INP
STA SECOND
LDA FIRST
OUT
LDA SECOND
OUT
HLT
FIRST DAT
SECOND DAT

What you should do

1.     Click on the "LMC Simulator Applet" link to start the LMC simulator.
2.     Clear the Message Box and all of the LMC mailboxes -- click the "Clear Messages" button and the "Clear" button if necessary.
3.     Copy the eleven line program above and paste it into the Message Box
4.     Click on the "Compile Program" button.
5.     Click on the "Run" button.
6.     When prompted, enter three-digit numbers in the "In-Box", and press the "Enter" button.



What you should see

  • After the program is compiled, you should see from mailbox 0 to 7 the instructions 901, 309, 901, 310, 509, 902, 510, 902.  The Program Counter should start at 0 (click on "Reset" if necessary).
  • DAT is the tenth and eleventh instruction of your program, so they refer to mailboxes 9 and 10 (0-indexed counting).  FIRST and SECOND are the identifiers that have been declared to represent these mailboxes in the assembly language program.
  • When you click on "Run" or "Step", the Message Box will describe the actions of each instruction.
  • After the first INP instruction, the Accumulator has a copy of the first value entered in the In Box.
  • After the STA instruction, the input value is copied from the Accumulator to mailbox 9 -- 3 means STORE and 09 refers to the mailbox to store into.
  • After the second INP instruction, the Accumulator has a copy of the second value entered into the In Box (use a different value than the first).
  • After the second STA instruction, the second input value is copied from the Accumulator to mailbox 10.
  • After the LDA instruction, the Accumulator is reset to the first input value.  This value has been retrieved from mailbox 9 -- 5 means LOAD and 09 refers to the mailbox to load from.  Note: since your Accumulator can only work on one value at a time, you have to repeatedly STORE and LOAD values from memory to keep them from getting erased by the next operation.
  • After the OUT instruction, the Out Box has a copy of the value in the Accumulator -- the first input value

3.      LMC Add and Subtract Instructions

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

INP
STA FIRST
INP
ADD FIRST
OUT
INP
SUB FIRST
OUT
HLT
FIRST DAT

What you should do

1.     Click on the "LMC Simulator Applet" link to start the LMC simulator.
2.     Clear the Message Box and all of the LMC mailboxes -- click the "Clear Messages" button and the "Clear" button if necessary.
3.     Copy the ten line program above and paste it into the Message Box
4.     Click on the "Compile Program" button.
5.     Click on the "Run" button.
6.     When prompted, enter three-digit numbers in the "In-Box", and press the "Enter" button.

What you should see

  • After the program is compiled, you should see from mailbox 0 to 7 the instructions 901, 309, 901, 109, 902, 901, 209, 902.  The Program Counter should start at 0 (click on "Reset" if necessary).
  • DAT is the tenth instruction of your program, so it refers to mailbox 9 (0-indexed counting).  FIRST is the identifier that has been declared to represent this mailbox in the assembly language program.
  • When you click on "Run" or "Step", the Message Box will describe the actions of each instruction.
  • After the first INP instruction, the Accumulator has a copy of the first value entered in the In Box.
  • After the STA instruction, the input value is copied from the Accumulator to mailbox 9.
  • After the second INP instruction, the Accumulator has a copy of the second value entered into the In Box (try values that will lead to three and four digit sums).
  • After the ADD instruction, the Accumulator value represents the sum of the two input values -- 1 means ADD and 09 refers to the mailbox where the value to be added to the Accumulator is stored.
  • After the third INP instruction, the Accumulator has a copy of the third value entered into the In Box (try values that will lead to positive and negative results).
  • After the SUB instruction, the Accumulator value represents the difference between the two input values -- 2 means SUBTRACT and 09 refers to the mailbox where the value to be subtracted from the Accumulator is stored.

EXTENSION

Complete the 4, 5 and 6 and put the output into your workbook:

http://www.yorku.ca/sychen/research/LMC/





No comments:

Post a Comment