CS计算机代考程序代写 assembly Pages / ZJU-UIUC: ECE 120 – Introduction to Computing / Labs

Pages / ZJU-UIUC: ECE 120 – Introduction to Computing / Labs
Lab 14
Created by Kindratenko, Volodymyr, last modified on May 09, 2021
 Lab14assignmentisdueonFriday,May14th,by9pminyoursvnrepository.Forhelp,pleasechecktheLabsFAQfirst.Specifically,pleasereadtheTerminal Troubleshooting and SVN Troubleshooting.
Please ask all questions about this assignment during the office hours or post questions on piazza.
 ThislabistobedoneonaLinuxworkstationorinVMduringanytimeoftheweek.Planyourtimeaccordinglysincelatesubmissionswillnotbeaccepted.
This lab assignment is challenging and time-consuming. Start early, plan your time accordingly. There will be no extensions to submit or correct your code.
If we find your code to be substantially similar to the code of another student, you will receive 0 for the lab and the incident will be reported to the College.
Programming in LC-3 Assembly Language – I
In this laboratory assignment, you will write a program in LC-3 assembly code to render a single ASCII character in a large (8×16-pixel) font to the monitor. The objectives for this assignment are for you:
to gain some experience with assembly language
to start to understand how data is organized in memory how such structured data can be used by a program.
In this case, the data of interest maps each ASCII character into a picture of the character. By making use of this data to print a string to the monitor, you will begin to learn how to organize data in a way that makes it easy to use in a program.
You are provided with several files in your SVN repository in the lab14 folder:
File lab14.asm is where you will write your assembly program.
File lc3-diff.sh is a script that compares output files to determine if your code passes/fails the test case.
File run_test is a script file to execute with lc3sim to run your program with a test case. Make sure to modify it to test the different cases provided to you.
Files cases/*.asm contain test cases to help you debug your code. Do not forget to use lc3as to assemble each file before the first use.
Files cases/*.sol contain the expected output solution to help you debug your code by comparing to it. They are text files that you can open in your favorite text editor.
Problem Statement
You must write a program in LC-3 assembly language to print a single ASCII character to the monitor using a large font. We have provided font data that map each extended (8-bit) ASCII character into an 8-bit-wide by 16-bit-high picture of the character. In memory, each such picture is represented using 8 bits in each of 16 contiguous memory locations, and the pictures for each of the 256 possible characters are then simply stored consecutively in memory. The complete set of font data thus occupy a total of 4096 = 16 × 256 LC-3 memory locations.
 The FONT_DATA is arranged according to their ASCII encodings. The first 16 addresses (0-15) in the FONT_DATA correspond to ASCII x00, the NULL character. The next 16 addresses (16-31) correspond to ASCII x01, the SOH character. Use the ASCII encoding of the letters you need to print to similarly find the addresses in FONT_DATA.
 TheprovidedFONT_DATAmustNOTbemodified!Donoteditthisfile.
The font data are provided to you in a file called lab14.asm. Note that the file includes only a single label, FONT_DATA, which points to the start of the data. You must add appropriate assembly code and directives to lab14.asm to print a given string to the screen that is specified in a separate file. For example, in the file cases/letter1.asm we have:
Input values to your program are stored in memory locations starting at x5000, as shown in the table above. Address x5000 contains the character that you should print for every bit set to 0 in the font data. (In the example above, we will print ‘.’ ) Address x5001 contains the character that you should print for every bit set to 1 in the font data. (In the example above, we will print ‘@’ ) The character that you must print is in address x5002. For the example values shown in the table above for the file cases/letter1.asm, your program should produce the output shown below, which you can also find in cases/letter1.sol
For your convenience, in the figure below we have added line numbers to illustrate the inclusion of all lines. (Line 0 has no number though.)
Address
Contents
Meaning
x5000
x002E
‘.’
x5001
x0040
‘@’
x5002
x0048
‘H’
1 2 3 4 5 6 7 8 9
10
11
12
13
14
15
……..
……..
@@…@@.
@@…@@.
@@…@@.
@@…@@.
@@@@@@@.
@@…@@.
@@…@@.
@@…@@.
@@…@@.
@@…@@.
……..
……..
……..
……..
The font data for the capital letter ‘H’ can be seen from the example. Remember that address x5000 contains the character that you should print for every bit set to 0 in the font data; in the example above, we will print ‘.’ Address x5001 contains the character that you should print for every bit set to 1 in the font data; in the example above, we will print ‘@’ Since we only have to store 8 bits of information, but the LC-3 has an addressability of 16 bits, we have chosen that the 8 bits of interest are stored in the upper 8 bits of the word in memory, and the lower 8 bits are simply set to zero. (We will talk more about this design choice later.) From this, we can observe that first two lines contain x0000. The next four contain xC600 (11000110 followed by eight more 0s). The seventh line contains xFE00 (11111110 followed by eight more 0s). The next five lines contain xC600. And the last four lines contain x0000.

Somewhere in FONT_DATA, you will then find the following information for the capital letter ‘H’:
.FILL x0000
.FILL x0000
.FILL xC600
.FILL xC600
.FILL xC600
.FILL xC600
.FILL xFE00
.FILL xC600
.FILL xC600
.FILL xC600
.FILL xC600
.FILL xC600
.FILL x0000
.FILL x0000
.FILL x0000
.FILL x0000
By changing the values in memory locations x5000 and x5001 your program should create different visualizations. For example, in the file cases/letter2.asm we have:
Your program should produce the output shown below, which you can also find in cases/letter2.sol
Address
Contents
Meaning
x5000
x0020
‘ ‘ (space)
x5001
x002A
‘*’
x5002
x0048
‘H’
1 2 3 4 5 6 7 8 9
10 11 12 13
** **
** **
** **
** **
*******
** **
** **
** **
** **
** **
Getting Started
Your first step should be to systematically decompose the problem to the level of LC-3 instructions. We expect that you develop your flow chart first, and we strongly advise you
not to try to write the code by simply sitting down at the computer and starting to write without having the flowchart.
We suggest that you start by coming up with an algebraic expression for the address that holds the bits needed for a particular line of a particular character. You will find the character to be printed by walking over the string (once for each of the 16 lines to be printed). You need to keep track of the line numbers yourself. You might choose to use one of the LC-3 registers as a loop counter with the line numbers shown in the example, then use the loop counter when calculating the address of the font data for a character. For your convenience, the 8 bits of interest are stored in the upper 8 bits of the word in memory. If we had used the lower 8 bits, your code would have to shift each word up after it was loaded in order to use the LC-3 condition code to check the value of each bit. Note that you can use an immediate mode ADD operation with second operand equal to 0 to set the condition codes based on the value in a given register.
Next, think about how you will structure your solution in terms of iterative constructs, conditional constructs, and sequences. Note that the grading rubric gives a few hints as to what you will need to include, if you’re having trouble starting.
 Anexampleofasolutionforasimilarbutsimplerproblemcanbefoundinsprite.asm.Youmaywanttotrytounderstandfirsttheexamplebeforeyoutrytosolvethisharder problem.
Specifics
Your program must be called lab14.asm — we will NOT grade files with any other name.
Your code must begin at memory location x3000.
The last instruction executed by your program must be a HALT (TRAP x25).
The character to be printed for 0 bits in the font data is located in memory at address x5000.
The character to be printed for 1 bits in the font data is located in memory at address x5001.
The ASCII character to be printed is stored at x5002.
Use a single line feed (x0A) character to end each line printed to the monitor.
Your program must use an iterative construct for each line in the output.
Your program must use an iteratitive construct for each bit to be printed for a given character.
You may not make assumptions about the initial contents of any register. That is, make sure to properly initialize the registers that you will use. You may assume that the values stored at x5000, x5001, and the character in x5002 are valid extended ASCII characters (x0000 to x00FF).
You may use any registers, but we recommend that you avoid using R7.
Note that you must print all ASCII characters, even if they are not visible on the monitor (as with spaces). Do not try to optimize your output, as you will make your output different from ours (and will thus lose points).
Tools

Use a text editor on a Linux machine (gedit, vi, emacs, or pico, for example) to write your program for this lab. Use the LC-3 simulator in order to execute and test the program. Your code must work in the call virtual machine (VM) to receive credit, so make sure to test it on one of those machines before handing it in.
Testing
You should test your program thoroughly before handing in your solution. Remember, when testing your program, you need to set the relevant memory contents appropriately in the simulator, and initialize the contents of registers before you first use them. Developing a good testing methodology is essential for being a good programmer. For this assignment, you should run your program multiple times for different test cases and double check the output with the tools provided to you. Although we provide you with some test cases, you are encouraged to create other ASM files to specify test inputs. When we grade your lab, we will use other test cases to make sure your code works properly.
We have given you sample test cases in the cases folder, but do not forget to assemble first the ASM files. We have also given you a script file to execute your program with a given case, run_test. For your convenience, we have also provided you with the correct version of the output for the test cases in cases/*.sol. The SOL files are text files that you can open in your favorite text editor.
Look at the run_test script: it loads first the sample test, then loads your program. Do not forget to modify this file to run different cases. The “reset” command/button will not work, since you are using more than one program. Set the PC by hand if necessary (for example, r pc 3000), or re-load both files (input and your program) whenever you need to restart a debug effort.
First you must debug—don’t assume that you can simply run the script to debug your code. Once you think that your code is working, you can execute the script by typing the following:
lc3sim -s run_test > myoutput
This command executes the LC-3 simulator on the script file and saves the output to the file myoutput; if the command does not return, your program is stuck in an infinite loop (press CTRL-C). Otherwise, you can compare your program’s output with our solution. For example, assuming you are testing with the cases/letter1.sol solution, you can type
./lc3-diff.sh myoutput cases/letter1.sol
If everything is fine, the message “Test passed” will be printed to screen, otherwise it will be printed “Test failed”. The script will give you the opportunity to see your output and our solution so you can manually compare them and see what went wrong.
 DonotforgettorunandtestyourcodeintheVMbeforesubmittingyourcode,sincewewillgradeyourlabusingasimilarVM.
Also, we will not make any changes to your code after you submitted it, no matter how small your error is, e.g., you forgot to comment a line that makes your code not to compile at all. It is your responsibility to submit a working code.
Lab Submission
Lab 14 submission is to be done via svn before the deadline for the assignment. You should double check that your file (lab14.asm) was uploaded properly.
Grading Rubric
Functionality (45 points)
40 points – program prints ASCII character stored at x5002 correctly, using character stored at x5000 to represent bits set to 0 in font and character stored at x5001 to represent bits set to 1 in font
5 points – program halts
Style (25 points)
10 points – program uses a single iterative construct to print every line of output
10 points – program uses a single iterative construct to print every bit in a character 5 points – program uses a single conditional construct to select character for printing
Comments, clarity, and write-up (15 points)
5 points – introductory paragraph clearly explaining program’s purpose and approach used
5 points – code includes table of registers that explains their meaning and contents as used by the code 5 points – code is clear, nicely formatted, and well-commented
No labels