首页 > > 详细

辅导 CIT 593 – Module 07 Assignment讲解 R编程

CIT 593 – Module 07 Assignment

Operating System, IO Assembly Instructions

Assignment Overview

In this assignment, you will continue programming in LC4 Assembly.  We will be working in the Operating System portion of memory, so you will learn about TRAPs and memory-mapped devices.

Learning Objectives

This assignment will cover the following topics:

● Work with TRAPS and the Operating System

● Implement an Operating System

● Work with the Keyboard, Display, and Video devices

● (optional) Work with the Timer device

Advice

● Start early

● Ask for help early

● Do not try to do it all in one day

Getting Started

Codio Setup

Be sure to open Codio from the Codio Assignment page in Canvas.  This is necessary to link the two systems.  Refer to the Module 06 Instructions for details about how Codio works.

Run user_echo.asm in PennSim

1. From the File Tree, click on os.asm.  This will open a new Codio tab named os.asm containing the contents of the file.

a. Review the contents of the file.  This is the basic framework for the operating system, which you will be writing for this assignment.

b. Look in the TRAP vector table for the line
JMP TRAP_PUTC

Notice how this is the second instructions is after the .ADDR x8000 directive.

● When loaded into PennSim, this instruction will be placed at address x8001.

● We can call TRAP_PUTC by using the TRAP instruction with offset x01.  This will be done later in user_echo.asm.

c. Scroll down (approximately 115 lines or so) until you reach the lines that read:

.CODE TRAP_PUTC

This label marks the start of the PUTC TRAP (an OS subroutine)

d. When Penn Sim executes JMP TRAP_PUTC instruction from the vector table, the program counter will be advanced to the address labeled by TRAP_PUTC

e. Further examine the code that follows; this is the operating system subroutine (a TRAP) called TRAP_PUTC.

f. Notice that this is the program we created in lecture to write one character to the ASCII display device on the LC4.

2. From the File Tree, click on user_echo.asm.

a. This file is a program to test some of the operating systems TRAPs in os.asm

b. Scroll down to about the 24th line, look for the lines that read:
CONST R0, x54
TRAP x01

c. The CONST instruction places the number 0x54 (which represents the letter 'T' in ASCII code) into R0.  This serves as the argument to the TRAP_PUTC trap.  You can look up the ASCII code mappings in the Resources section.

d. The TRAP x01 instruction sets PC to x8001, and also sets PSR[15]=1 (OS mode).  TRAP x01 is TRAP_PUTC, so this TRAP call will have the effect of outputting a 'T' to the LC4’s ASCII display.

e. Examine the rest of this program, you’ll see that its purpose is to output Type Here> on the LC4 ASCII display.

3. From the File Tree, click on user_echo_script.txt.  This opens a new Codio tab displaying the script. contents.

a. This file is the PennSim script. that assembles and loads os.asm and user_echo.asm

b. Look carefully at the contents and compare how it differs from your last HW. Notice how it assembles and loads both os.asm and user_echo.asm

4. Open a PennSim Window and launch PennSim from the Codio command line.  Refer to the Module 6 instructions if you need a refresher on how to do this.

5. Go to the command line in the Controls section and enter
script. user_echo_script.txt

6. Press the Step button and carefully go line by line until you see the letter 'T' output to the screen.

a. Carefully watch how you start in user_echo.asm’s code (in user program memory) and then with the call to TRAP, you enter into OS program memory.

b. Understanding this process is crucial to understanding, writing, and debugging this assignment.

7. Finally, press the Continue button to see PennSim run the program until it encounters the END label.

8. Make certain you understand how these files work together before beginning the assignment.

Starter Code

We have provided some starter files.  You will need to modify some files and generate completely new files to succeed in this assignment.

os.asm

- contains the operating system framework, and the TRAP_PUTC example from lecture.  Your will write the remaining TRAPs.

user_echo.asm

- demo program from lecture

user_echo_script.txt

- demo script. file for user_echo example

PennSim.jar

- Runs your programs, debugging, etc.

Requirements

General Requirements

● Your script. files MUST contain all the necessary commands to assemble and load your programs, as shown in lecture and the multiply example from Module 6.

● Your programs MUST complete the requirements of the problem when loaded into PennSim and clicking the Continue button.

● Your programs MUST NOT throw any Exception unless otherwise noted.

● Your programs MUST be written in LC4 Assembly.

● You MUST comment critical sections your code so we can grade it.  This will also help with partial credit.

● You MUST use END as the label that indicates the end of the program.

● You MUST submit to Codio and Gradescope as outlined in the Submission section.

● You SHOULD do all the work in Codio.  Do not attempt to run these programs locally.  TAs will not assist you if you are trying to do the projects outside of Codio.  

o Codio provides a standard environment to ensure consistent functionality.

o Codio backs up your code.  You can restore deleted/modified files by going to Tools->Code Playback.

o TAs can login and view your code for asynchronous debugging.

o Different operating systems handle endianness differently.  Your submission MUST work in the Codio environment, which is where we will be performing all tests.

Part 1: Echo with TRAP_GETC/TRAP_PUTC

● You MUST use the traps TRAP_GETC and TRAP_PUTC.

● You MUST implement the traps in os.asm, write the test program in user_echo.asm, and provide a working script. user_echo_script.txt.

● TRAP_GETC MUST take no arguments as input and return the read-in character in R0.

● TRAP_PUTC MUST take a single argument in R0 (the character to display) as input and not return any value.

● Your test program MUST call these two traps in a loop, to echo the user keystrokes to the display.

○ It MUST break out of the loop when the user presses the enter key.

Part 2: Print Strings with TRAP_PUTS

● You MUST implement and use the trap TRAP_PUTS.

● You MUST implement the traps in os.asm, write the test program in user_string.asm, and provide a working script. user_string_script.txt.

● TRAP_PUTS MUST:

○ take a single argument in R0 (the address of the start of the string to display) as input and not return any value.

○ check that the provided argument is a valid User Data Memory address.

○ If the address is not valid, immediately return without attempting to print the string.

○ print the entire string to the display; that is each character from the starting address through the entire array up to but not including the NULL terminator.

● Your test program MUST:

○ use .FILL to pre-load the NULL-terminated string
I love CIT 593
into User Data Memory, starting at address x4000.

○ print this string to the display by populating R0 with the starting address and then calling TRAP_PUTS with the appropriate Trap Number from the Trap Vector Table

Part 3: Get Strings with TRAP_GETS

● You MUST implement the trap TRAP_GETS and use the traps TRAP_GETS and  TRAP_PUTC.

● You MUST implement the traps in os.asm, write the test program in user_string2.asm, and provide a working script. user_string2_script.txt.

● TRAP_GETS MUST:

○ take a single argument in R0 (the address to start storing the string) as input and return the length of the string (not including the NULL terminator) in R1.

○ check that the provided argument is a valid User Data Memory address.

○ If the address is not valid, immediately return without attempting to get a string.

○ continue to read characters entered by the user until the user presses the enter key.

○ store each character typed by the user up to but not including the enter key and add the NULL terminator at the end of the string.

● Your test program MUST:

○ call TRAP_GETS with address x2020.

○ read the arbitrary user string and store it into Data Memory.

○ Print the text:
Length = X

using TRAP_PUTS for the Length =  portion and TRAP_PUTC for X, where X is the length of the string.

○ You MAY assume that the strings will be less than 10.

○ Call TRAP_PUTS with address x2020 to print the string previously entered by the user.

Part 4: Draw Rectangles with TRAP_DRAW_RECT

● You MUST implement and use the trap TRAP_DRAW_RECT.

● You MUST implement the traps in os.asm, write the test program in user_draw.asm, and provide a working script. user_draw_script.txt.

● TRAP_DRAW_RECT MUST:

○ take five arguments:

○ R0 - x-coordinate of the upper-left corner of the rectangle, the horizontal distance from (0,0)

○ R1 - y-coordinate of the upper-left corner of the rectangle, the vertical distance from (0,0)

○ R2 - the horizontal length of the rectangle

○ R3 - the vertical width of the rectangle

○ R4 - the color of the rectangle

○ check the bounds of the rectangle compared to the video display

○ if the starting coordinates are outside the video display, immediately return without attempting to draw any part of the rectangle.

○ if the starting coordinates are inside the video display, but the values for length or width would cause the rectangle to be drawn outside the video display, immediately return without attempting to draw any part of the rectangle.

○ draw the rectangle with the appropriate color, filling all interior pixels

● Your test program MUST call TRAP_DRAW_RECT for the following rectangles:

○ a red rectangle with starting coordinates (50,5), length 10, and width 5

○ a yellow rectangle with starting coordinates (10, 10), length 50, and width 40

○ a blue rectangle with starting coordinates (120, 100), length 27, and width 10

Extra Credit: Get a Character Within a Time Limit with TRAP_GETC_TIMER

● You MUST implement and use the traps TRAP_GETC_TIMER and TRAP_PUTC.

● You MUST implement the trap in os.asm, write the test program in user_string_ec.asm, and provide a working script. user_string_ec_script.txt.

● TRAP_GETC_TIMER MUST 

○ take a single argument in R0 (the desired time to wait for a character) as input.

○ if a key is pressed within the time limit, return the entered character in R0.

○ if a key is not pressed within the time limit, return NULL in R0.

● Your test program MUST:

○ use a time limit of two seconds.

○ print the key that was entered within the time limit using TRAP_PUTC, or print nothing if a key was not entered.

Extra Credit: Reset Starting Coordinates When Out of Bounds

● You SHOULD make a copy of your TRAP_DRAW_RECT trap before working on this extra credit, in case you don't get it working before the submission deadline.

● You MUST modify TRAP_DRAW_RECT.  It MUST follow the original requirements, except:

○ If the starting coordinates are outside the video display, it MUST reset the starting coordinates to (0,0) and draw the rectangle starting here instead, using the original length/width values.

○ It MUST follow the Wrap the Rectangle Horizontally extra credit exception if attempting both extra credit options.

Extra Credit: Wrap the Rectangle Horizontally

● You SHOULD make a copy of your TRAP_DRAW_RECT trap before working on this extra credit, in case you don't get it working before the submission deadline.

● You MUST modify TRAP_DRAW_RECT.  It MUST follow the original requirements, except:

○ If the rectangle's horizontal length would take it outside the video display, it MUST wrap around the display and continue drawing the rectangle from the left side of the display at the same vertical width.  Do not wrap rectangles if they go outside video memory vertically.

○ It MUST follow the Reset Starting Coordinates When Out of Bounds extra credit exception if attempting both extra credit options.

Suggested Approach

This is a suggested approach.  You are not required to follow this approach as long as you follow all of the other requirements.

High Level Overview

Work on one problem at a time.

1. Review the starter code to see how the different files work together.  This is critical for succeeding in this assignment.  TRAP_PUTC is already written for you and you need to understand how it works.

2. Implement user_echo.asm, using TRAP_GETC and TRAP_PUTC.

3. Complete the TRAP_PUTS implementation in os.asm.

4. Implement user_string.asm using TRAP_PUTS.

5. Complete the TRAP_GETS implementation in os.asm.

6. Implement user_string2.asm using TRAP_GETS, TRAP_PUTS, and TRAP_PUTC.

7. Review the implementation of TRAP_DRAW_PIXEL.

8. Complete the TRAP_DRAW_RECT implementation in os.asm.

9. Implement user_draw.asm using TRAP_DRAW_RECT.

10. (optional) Attempt the extra credits.

 


联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!