Due: 09:30 pm Tuesday 3rd May 2022 Worth: 6% of the final mark
Introduction
This assignment is to be done using LC-3 simulator. You can download the JAVA version of the LC-3 simulator from Canvas.
You can use the simulator to compile and test the program.
Copyright By PowCoder代写 加微信 powcoder
Section 0: Getting Started (Running the Simulator)
You can execute the simulator (‘LC3sim.jar’). We need to first load some software. The first piece of software we should load is, naturally, an operating system. The LC-3 operating system is very basic: it handles simple I/O operations and is responsible for starting other programs. Download the LC-3 OS (‘LC3os.asm’) from Canvas (or from the given link in references) and you can understand what the operating system does.
The LC-3 machine doesn’t understand assembly directly; we first have to ‘assemble’ the assembly code into machine language (it is an ‘.obj’ file containing binary data). The LC-3 simulator has a built-in assembler, accessible (as is the case for most of its functionality) via the Command Line text box. To assemble the operating system, type as lc3os.asm at the command line and hit enter. Make sure that the OS file is in the same directory as the ‘.jar’ file; the as command also understands relative and absolute paths if the OS is in a different directory. Output from the assembly process is displayed in the Command Line Output Pane. After assembling the OS, you should notice that 2 new files, ‘lc3os.obj’ and ‘lc3os.sym’, have been created. The ‘.obj’ file is the machine language encoding of the assembly language file, and the ‘.sym’ file is a text file that holds symbol (or label) information so the simulator can display your symbols. Recall that symbols/labels are really just a convenience for silly humans; the machine language encoding knows only about offsets.
Now we can load the ‘lc3os.obj’ file into the simulator, either via the command load lc3os.obj or by going to the File menu and selecting Open ‘.obj’ file. Notice that the contents of the memory change when the OS is loaded. Now assemble and load the solution file for Problem 0 (Q0.asm) into the simulator. The memory has changed again, but you may not notice since the relevant memory addresses (starting at x3000) aren’t visible unless you’ve scrolled the screen. User-level programs (i.e., non-OS code) start, by convention, at x3000. If you type the command list x3000 the memory view will jump to x3000 and you can see the assembly instructions of your program.
To actually run code, you can use the 4 control buttons at the top of the simulator, or type commands into the command line interface (the command names are the same as the buttons). Note that the PC register is set to x0200, which is the entry point to the operating system by convention. You can set the value in the registers. Example: You can set the value of R2, either by double-clicking it in the Registers section, or via the command set R2 (value). Now, run the code by hitting the continue button. You can find more details of operations from [1,2].
In section 0, execute the program file (Q0.asm). This program will take two input operands and output the “addition” results of those inputs. You first assemble all the files: ‘lc3os.asm’, ‘data0.asm’ and ‘Q0.asm’. Then, you execute the following commands: load lc3os.obj, load data0.obj and load Q0.obj to load the corresponding machine code files. Click ‘Continue’ to run the program. You can see the results from the display at the bottom- left.
COMPSCI 210 S1 – Assignment 01
Computer Science
COMPSCI 210 S1, 2022
Assignment ONE
COMPSCI 210 S1 – Assignment 01
……… ;
; A subroutine to add the values from R2 and R3 (R2 + R3). The result is saved at R3. ;
; A subroutine to subtract the value of R3 from R2 (R2 – R3). The result is saved at R3. ;
; A subroutine to OR the values from R2 and R3 (R2 OR R3). The result is saved at R3. ;
; A subroutine to calculate the value stored at R2 left-shift by the value stored at R3 (R2 << R3). The result is saved at R3.
; A subroutine to XOR the values from R2 and R3 (R2 XOR R3). The result is saved at R3. ;
; A subroutine to divide the value stored at R2 (dividend) with the value stored at R3 (divisor) (R2 / R3). The result (quotient) is saved at R3.
; A subroutine to calculate the value from R2 to the power of the value from R3 (R2 ^ R3). The result is saved at R3. ;
...........
MyADD ADD R3, R2, R3
MySUB ; to be completed
MyOR ; to be completed
MySHIFT ; to be completed
MyXOR ; to be completed
MyDIV ; to be completed
MyPOW ; to be completed
Go through the program of the sample file (Q0.asm), the output will display the result of ADD operations of every two input values (after the ‘+’ character) from the “data0.asm”. The first character of the data file is used to identify which operation is going to be executed. You can save the program as the file Q1.asm. Next, you are going to complete the highlighted area of the program to finish the whole assignment. The output of executing Q0 with data file data0 is shown below.
001+009=010 007+004=011 006+004=010 000+005=005 006+005=011 009+004=013 006+006=012 001+001=002 008+000=008 009+009=018
WARNING: We will use the JAVA simulator for marking. In particular, you should make sure that your answer will produce ONLY the exact output expected. The markers simply make an exact comparison with the expected output. If you have any debug printouts or other code which produces some unexpected output, the markers will give you zero marks. If your files cannot be compiled successfully or they cannot be executed after compilation, the markers will also give you zero marks.
Section 1: Subtraction (0.5 marks)
You now complete the subroutine “MySUB”. It is a subroutine to subtract the value of R3 from R2 (R2 - R3). The result is saved at R3.
For example (data from ‘data1.asm’): 009-001=008
004-004=000
008-002=006
003-002=001 001-000=001 005-001=004 009-003=006 008-004=004 000-000=000 002-001=001
Section 2: OR Operation (0.5 marks)
You now complete the subroutine “MyOR”. It is a subroutine to “OR” the values from R2 and R3 (R2 OR R3). The result is saved at R3.
For example (data from ‘data2.asm’): 009|001=009
008|002=010
007|003=007
001|009=009 008|007=015 007|006=007 006|005=007 002|000=002 000|000=000 005|004=005
Section 3: Left Shift Operation (1 mark)
You now complete the subroutine “MySHIFT”. It is a subroutine to calculate the value stored at R2 left-shift by the value stored at R3 (R2 << R3). The result is saved at R3.
For example (data from ‘data3.asm’): 009<001=018
004<004=064
008<002=032
007<003=056 006<005=192 005<004=080 004<003=032 003<002=012 001<000=001 002<004=032
COMPSCI 210 S1 - Assignment 01
Section 4: XOR Operation (1 mark)
You now complete the subroutine “MyXOR”. It is a subroutine to XOR the values from R2 and R3 (R2 XOR R3). The result is saved at R3.
For example (data from ‘data4.asm’): 002_007=005
003_008=011
001_001=000
005_004=001 001_009=008 003_000=003 009_003=010 008_001=009 007_004=003 000_000=000
Section 5: Divide Function (1 mark)
You now complete the subroutine “MyDIV”. It is a subroutine to divide the value stored at R2 (dividend) with the value stored at R3 (divisor) (R2 / R3). The result (quotient) is saved at R3.
For example (data from ‘data5.asm’): 009/008=001
007/005=001
006/003=002
004/009=000 007/002=003 009/002=004 006/006=001 006/001=006 007/003=002 004/002=002
Section 6: Power Function (2 marks)
You now complete the subroutine “MyPOW”. It is a subroutine to calculate the value from R2 to the power of the value from R3 (R2 ^ R3). The result is saved at R3.
For example (data from ‘data6.asm’): 008^002=064
007^003=343
009^003=729
001^005=001 005^001=005 002^002=004 009^000=001 004^004=256 006^001=006 001^009=001
You can make the following assumptions:
1. All input value should be between 00010 – 00910.
2. The results of all output should be between 00010 – 99910.
3. All inputs and outputs should be positive.
4. There should not be any invalid inputs from the input data file.
COMPSCI 210 S1 - Assignment 01
Submission
You may electronically submit your assignment through Canvas submission system at any time from the first submission date up until the final date. You can make more than one submission. However, every submission that you make replaces your previous submission. Only your very latest submission will be marked. Please double check that your submitted file can compile and execute properly with the given data files on the LC3 simulator (java version).
Please include your NAME and UPI in the file you submit.
No marks will be awarded if your program does not compile and run. You are to electronically submit the following file:
Late Submission
5% penalty if submitted on 4th May 2022 10% penalty if submitted on 5th May 2022 15% penalty if submitted on 6th May 2022 20% penalty if submitted on 7th May 2022
No more submission will be allowed after that period.
Any work you submit must be your work and your work alone. To share assignment solutions and source code is not permitted under the academic integrity policy. Violation of this will result in your assignment submission attracting no marks, and you will face disciplinary actions in addition.
[1] http://www.cis.upenn.edu/~milom/cse240-Fall05/handouts/lc3guide.html (original link currently down)
[2] https://ece252.ece.wisc.edu/pennsim-guide.html
COMPSCI 210 S1 - Assignment 01
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com