1. Homepage
  2. Programming
  3. CIT 593 Introduction to Computer Systems - Module 07 Assignment: TRAPs and memory-mapped devices

CIT 593 Introduction to Computer Systems - Module 07 Assignment: TRAPs and memory-mapped devices

Engage in a Conversation
UPEENCIT593Introduction to Computer SystemsTRAPsmemory-mapped devicesLC4

CIT 593 – Module 07 Assignment CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

Operating System, IO Assembly Instructions
CourseNana.COM

Contents CourseNana.COM

Assignment Overview 3 Learning Objectives 3 Advice 3 Getting Started 4 CourseNana.COM

Codio Setup 4 Run user_echo.asm in PennSim 4 CourseNana.COM

Starter Code 6 Requirements 7 CourseNana.COM

General Requirements 7 CourseNana.COM

Part 1: Echo with TRAP_GETC/TRAP_PUTC 7 CourseNana.COM

Part 3: Get Strings with TRAP_GETS
CourseNana.COM

Part 2: Print Strings with TRAP_PUTS 8 CourseNana.COM

Part 4: Draw Rectangles with TRAP_DRAW_RECT 10 CourseNana.COM

Extra Credit: Get a Character Within a Time Limit with TRAP_GETC_TIMER 11 CourseNana.COM

Extra Credit: Reset Starting Coordinates When Out of Bounds 11
CourseNana.COM

Extra Credit: Wrap the Rectangle Horizontally 11 Suggested Approach 12 High Level Overview 12 Great High Level Overview, but I really need a Slightly More Detailed Overview 13 Part 1: Echo with TRAP_GETC/TRAP_PUTC 13 CourseNana.COM

Submission 22 Where to put the files 22 Pre-Submission Test 22 The Actual Submission 22 CourseNana.COM

Codio Submission 22 Gradescope Submission 22 Academic Integrity Agreement: 22 CourseNana.COM

Grading 23 Main Assignment 23 CourseNana.COM

Part 2: Print Strings with TRAP_PUTS 14 Part 3: Get Strings with TRAP_GETS 16 Part 4: Draw Rectangles with TRAP_DRAW_RECT 18 Extra Credit: Get a Character in a Time Limit with TRAP_GETC_TIMER 20 Extra Credit: Reset Starting Coordinates When Out of Bounds 21 Extra Credit: Wrap the Rectangle Horizontally 21
CourseNana.COM

Page 1 of 24 CourseNana.COM

Extra Credit 23 An Important Note of Plagiarism 23 CourseNana.COM

FAQ
Quick Hints
CourseNana.COM

Resources CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

Page 2 of 24 CourseNana.COM

Assignment Overview CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

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.
CourseNana.COM

Learning Objectives CourseNana.COM

This assignment will cover the following topics: CourseNana.COM

● Donottrytodoitallinoneday CourseNana.COM

Page 3 of 24 CourseNana.COM

Getting Started CourseNana.COM

Codio Setup CourseNana.COM

Be sure to open Codio from the Codio Assignment page in Canvas. Refer to the Module 06 Instructions for details about how Codio works. CourseNana.COM

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 CourseNana.COM

containing the contents of the file. CourseNana.COM

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

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

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

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

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

● We can call TRAP_PUTC by using the TRAP instruction with offset x01. This will be  CourseNana.COM

done later in user_echo.asm.
c. Scroll down (approximately 115 lines or so) until you reach the lines that read:
CourseNana.COM

.CODE TRAP_PUTC CourseNana.COM

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

  1. When Penn Sim executes JMP TRAP_PUTC instruction from the vector table, the CourseNana.COM

    program counter will be advanced to the address labeled by TRAP_PUTC  CourseNana.COM

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

2. From CourseNana.COM

f. Notice that this is the program we created in lecture to write one character to the CourseNana.COM

ASCII display device on the LC4.
CourseNana.COM

the File Tree, click on user_echo.asm. CONST R0, x54 CourseNana.COM

TRAP x01 CourseNana.COM

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. CourseNana.COM

  1. 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. CourseNana.COM

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

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

b. Scroll down to about the 24th line, look for the lines that read: CourseNana.COM

Page 4 of 24 CourseNana.COM

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

    1. This file is the PennSim script that assembles and loads os.asm and CourseNana.COM

               user_echo.asm
      
    2. 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 CourseNana.COM

  2. 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. CourseNana.COM

  3. Go to the command line in the Controls section and enter CourseNana.COM

       script user_echo_script.txt
    
  4. Press the Step button and carefully go line by line until you see the letter 'T' CourseNana.COM

output to the screen. CourseNana.COM

a. Carefully watch how you start in user_echo.asm’s code (in user CourseNana.COM

program memory) and then with the call to TRAP, you enter into OS CourseNana.COM

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

7. Finally, press the Continue button to see PennSim run the program until itassignment.program memory. CourseNana.COM

encounters the END label.
8. Make certain you understand how these files work together before beginning the CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

Page 5 of 24
CourseNana.COM

Starter Code CourseNana.COM

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

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

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

user_echo.asm

- demo program from lecture CourseNana.COM

user_echo_script.txt

- demo script file for user_echo example CourseNana.COM

PennSim.jar CourseNana.COM

- Runs your programs, debugging, etc. CourseNana.COM

Page 6 of 24
CourseNana.COM

Requirements CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

General Requirements
CourseNana.COM

  • ●  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. CourseNana.COM

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

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

  • ●  Your programs MUST be written in LC4 Assembly. CourseNana.COM

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

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

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

● 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.
CourseNana.COM

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
CourseNana.COM

Tools->Code Playback.
CourseNana.COM

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

o Different operating systems handle endianness differently. Your submission CourseNana.COM

MUST work in the Codio environment, which is where we will be performing all tests.
CourseNana.COM

Part 1: Echo with TRAP_GETC/TRAP_PUTC
CourseNana.COM

● You MUST use the traps TRAP_GETC and TRAP_PUTC. CourseNana.COM

● You MUST implement the traps in os.asm, write the test program in user_echo.asm CourseNana.COM

and provide a working script user_echo_script.txt. CourseNana.COM

  • ●  TRAP_GETCMUSTtakenoargumentsasinputandreturntheread-incharacterinR0. CourseNana.COM

  • ●  TRAP_PUTCMUSTtakeasingleargumentinR0(thecharactertodisplay)asinputand not return any value. CourseNana.COM

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

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

Page 7 of 24 CourseNana.COM

Part 2: Print Strings with TRAP_PUTS  CourseNana.COM

  • ●  You MUST implement and use the trap TRAP_PUTS. CourseNana.COM

  • ●  You MUST implement the traps in os.asm, write the test program in user_string.asm, CourseNana.COM

and provide a working script user_string_script.txt. ● TRAP_PUTSMUST: CourseNana.COM

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

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

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

○ 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. CourseNana.COM

● Your test program MUST: CourseNana.COM

○ use .FILL to pre-load the NULL-terminated string I love CIT 593
CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

into User Data Memory, starting at address x4000.
CourseNana.COM

○ 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 CourseNana.COM

Page 8 of 24
CourseNana.COM

Part 3: Get Strings with TRAP_GETS  CourseNana.COM

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

● 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. CourseNana.COM

TRAP_GETSMUST: CourseNana.COM

  • ○  take a single argument in R0 (the address to start storing the string) as input and CourseNana.COM

    return the length of the string (not including the NULL terminator) in R1. CourseNana.COM

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

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

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

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

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: CourseNana.COM

Length = X
CourseNana.COM

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

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.  CourseNana.COM

Page 9 of 24 CourseNana.COM

Part 4: Draw Rectangles with TRAP_DRAW_RECT  CourseNana.COM

  • ●  You MUST implement and use the trap TRAP_DRAW_RECT. CourseNana.COM

  • ●  You MUST implement the traps in os.asm, write the test program in user_draw.asm, CourseNana.COM

and provide a working script user_draw_script.txt. ● TRAP_DRAWMUST: CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

○ ○ CourseNana.COM

○ draw the rectangle with the appropriate color, filling all interior pixels ● Your test program MUST call TRAP_DRAW_RECT for the following rectangles: CourseNana.COM

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

  • ○  a green rectangle with starting coordinates (10, 10), length 50, and width 40 CourseNana.COM

  • ○  a yellow rectangle with starting coordinates (120, 100), length 27, and width CourseNana.COM

    10 CourseNana.COM

if the starting coordinates are outside the video display, immediately CourseNana.COM

return without attempting to draw any part of the rectangle. CourseNana.COM

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.
CourseNana.COM

Page 10 of 24 CourseNana.COM

Extra Credit: Get a Character Within a Time Limit with CourseNana.COM

TRAP_GETC_TIMER
  • ●  You MUST implement and use the traps TRAP_GETC_TIMER and TRAP_PUTC. CourseNana.COM

  • ●  You MUST implement the trap in os.asm, write the test program in CourseNana.COM

    user_string_ec.asm, and provide a working script user_string_ec_script.txt. CourseNana.COM

  • ●  TRAP_GETC_TIMERMUST CourseNana.COM

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

    • ○  if a key is pressed within the time limit, return the entered character in R1. CourseNana.COM

    • ○  if a key is not pressed within the time limit, return NULL in R1. CourseNana.COM

  • ●  Your test program MUST: CourseNana.COM

Extra Credit: Reset Starting Coordinates When Out of Bounds CourseNana.COM

  • ●  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. CourseNana.COM

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

    ○ 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. CourseNana.COM

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

Extra Credit: Wrap the Rectangle Horizontally
CourseNana.COM

  • ●  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. CourseNana.COM

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

    • ○  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. CourseNana.COM

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

Page 11 of 24 CourseNana.COM

Suggested Approach CourseNana.COM

5. Complete the TRAP_GETS implementation in os.asm CourseNana.COM

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

7. Review the implementation of TRAP_DRAW_PIXEL. CourseNana.COM

8. Complete the TRAP_DRAW_RECT implementation in os.asm CourseNana.COM

  1. Implement user_draw.asm using TRAP_DRAW_RECT. CourseNana.COM

  2. (optional) Attempt the extra credits. CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

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

High Level Overview CourseNana.COM

Work on one problem at a time. CourseNana.COM

  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. CourseNana.COM

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

  3. Complete the TRAP_PUTS implementation in os.asm. CourseNana.COM

  4. Implement user_string.asm using TRAP_PUTS. CourseNana.COM

Page 12 of 24 CourseNana.COM

Great High Level Overview, but I really need a Slightly More CourseNana.COM

Detailed Overview CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

Okay, I guess we can give some more details.
CourseNana.COM

Part 1: Echo with TRAP_GETC/TRAP_PUTC File Setup CourseNana.COM

You only need to modify user_echo.asm for this part. You do not need to create any additional files. CourseNana.COM

Your Task CourseNana.COM

Use the two provided TRAPs to "echo" the user's keystrokes to the display.
Extend the user_echo.asm code to read an ASCII character from the Keyboard (using
CourseNana.COM

TRAP_GETC) and print it to the ASCII Display (using TRAP_PUTC) in a loop. Repeat this process until the user presses the Enter key. Consider which type of loop is appropriate (for, while, do-while).
CourseNana.COM

You may have noticed the hint to use .STRINGZ. This is optional and requires reading the textbook or do some outside research. This will likely be time consuming and more trouble than it is worth. Additionally, the TAs will not support you if you run into problems using .STRINGZ since this is 100% completely optional. CourseNana.COM

Page 13 of 24
CourseNana.COM

Part 2: Print Strings with TRAP_PUTS CourseNana.COM

File Setup CourseNana.COM

For this problem, you will create a new trap TRAP_PUTS and add it to the operating system file os.asm. You’ll also create a new file called user_string.asm to test your new trap, similar to how user_echo.asm tested the TRAP_GETC and TRAP_PUTC traps in the last problem. This new trap will print (or "put") a string to the screen ASCII Display. Then create user_string_script.txt with the appropriate contents. CourseNana.COM

What is a String? CourseNana.COM

A string is simply an array, or consecutive sequence, of individual ASCII characters. CourseNana.COM

To be considered a string an ASCII character array must end with the NULL character. ANULLcharacterisanon-printablecharacter. Typically,thenumber0isused.Itis never printed; it is just to mark the end of the string. CourseNana.COM

Example Address CourseNana.COM

First, create TRAP_PUTS. Open up the file os.asm and find where TRAP_PUTS is located in the vector table. Then scroll down to the label TRAP_PUTS to see the trap’s implementation. You’ll CourseNana.COM

notice it’s empty, but this is where you will be working.
CourseNana.COM

This purpose of this function is to output a NULL terminated string to the ASCII display. We can’t pass the entire "string" to a trap because we’d run out of registers quickly if we had strings with more than 8 characters. Instead, we will pass the address of the first character of a string to the trap using R0. CourseNana.COM

When TRAP_PUTS is called, register R0 must contain the address of the first character of the string where the caller has stored the string in Data Memory. Therefore, R0 is considered the argumenttothetrap. Usingtheexamplestringabove,R0wouldbesettox4000when calling the trap. CourseNana.COM

The last character in the string must be zero, which is the null terminator, to give us a null-terminated string. CourseNana.COM

This trap does not return anything to the caller CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

Consider this hypothetical example of a string containing: "Tom" in data memory. It starts at x4000 and uses four rows of Data Memory to hold each character, including the NULL terminator.
CourseNana.COM

hexadecimal translation
CourseNana.COM

Contents in ASCII CourseNana.COM

Your Task CourseNana.COM

x004F 'O'
CourseNana.COM

Page 14 of 24 CourseNana.COM

We have provided pseudocode for this TRAP: CourseNana.COM

TRAP_PUTS (R0) { CourseNana.COM

 check the value of R0, is it a valid address in User Data memory? CourseNana.COM

            if it is, continue, if not, return to caller
      load the ASCII character from the address held in R0 while (ASCII
      character != NULL) {
            check status register for ASCII Display
                  if it’s free, continue, if not, keep checking until its free
            write ASCII character to ASCII Display’s data register
            load the next ASCII character from data memory
       }
       return to caller

copy user_string.asm. Open up user_string.asm and perform the following tasks:  CourseNana.COM

1. Using the .FILL directive, populate User Data Memory starting at address x4000 with the hexadecimal code for the string: CourseNana.COM

I love CIT 593 CourseNana.COM

Look at the back cover of your book to find the hexadecimal code for each character. CourseNana.COM

Don’t forget to also set the value of the last address after your string with NULL. You CourseNana.COM

may label address x4000 if you’d like, but its not required. CourseNana.COM

  1. Populate R0 with the address of the first character in your string. CourseNana.COM

  2. Call TRAP_PUTS using the appropriate TRAP number from the TRAP Vector Table  CourseNana.COM

shown at the top of os.asm.
4. Create
user_string_script.txt by copying user_echo_script.txt and modifying CourseNana.COM

it. CourseNana.COM

  1. Test our your work, if it’s not working, debug by going Step by Step. CourseNana.COM

  2. Do not move on to the next part until this one is working correctly. CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

Once you have implemented the trap, it is time to test it. Copy user_echo.asm, and call the CourseNana.COM

Page 15 of 24 CourseNana.COM

Part 3: Get Strings with TRAP_GETS CourseNana.COM

File setup CourseNana.COM

For this problem, you will create a new trap TRAP_GETS and add it to the operating system file os.asm. You’ll also create a new file called user_string2.asm to test your new trap. This new trap will get a string from the user. Create user_string2_script.txt with the appropriate contents. CourseNana.COM

Your Task CourseNana.COM

Back in os.asm, scroll down to the label TRAP_GETS. You’ll notice under the label is where you will be working. The purpose of this function is to continually read characters from the keyboard until the enter key is pressed, storing each character into user specified location in User Data Memory as a string, then return the length of the string to the caller. CourseNana.COM

When the program calls the trap, the caller must pass the desired starting address as an CourseNana.COM

argument in R0. R0 will be the address in User Data Memory where the string that will be read from the keyboard will be stored. CourseNana.COM

The trap needs to check to ensure R0 contains a valid address in User Data Memory. If not, return immediately without attempting to read anything from the keyboard.. CourseNana.COM

Otherwise, the trap must then read in characters one by one. As it reads in each character, it
CourseNana.COM

must store them in data memory consecutively starting from the address passed in by the CourseNana.COM

caller. Once the enter key is pressed (which is hexadecimal x0D or x0A depending on your CourseNana.COM

machine) the trap must "NULL terminate" the string in data memory and finally return the length  CourseNana.COM

of the string (without including the NULL or enter) to the caller in R1. As an example, let’s say a program called the TRAP as follows: CourseNana.COM

; program sets R0=x2000
CourseNana.COM

; program calls TRAP_GETS(R0) CourseNana.COM

; R1 contain the length of the string after the TRAP returns
CourseNana.COM

For a more concrete example, let’s say that, when the program calls the TRAP, the user types in Hello on the console, followed by an enter. User Data Memory would contain the following after the TRAP returns: CourseNana.COM

Example Address CourseNana.COM

Contents in hexadecimal CourseNana.COM

ASCII translation CourseNana.COM

Page 16 of 24 CourseNana.COM

And R1 would contain the number 5 when the trap returns. The above is just an example; any valid address in data memory can be passed in by the caller and any string could be entered by the caller on the keyboard. CourseNana.COM

After you complete testing the trap, do the following in user_string2.asm: CourseNana.COM

  1. Call TRAP_GETS with address: x2020 in R0. This will allow a string to be entered by the user and it will be stored in address R0 CourseNana.COM

  2. Using TRAP_PUTS and TRAP_PUTC, print Length = X CourseNana.COM

    where X is the length of the read-in string from step 1 (you can assume length will be CourseNana.COM

    less than 10) CourseNana.COM

3. Call TRAP_PUTS with address: x2020 in R0. This will output the same string that was read in from step 1 to the Display. CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

Page 17 of 24
CourseNana.COM

Part 4: Draw Rectangles with TRAP_DRAW_RECT CourseNana.COM

When the TRAP is called the following registers must contain the following: CourseNana.COM

R0 – "x coordinate" of upper-left corner of the rectangle. CourseNana.COM

R1 – "y coordinate" of upper-left corner of the rectangle. CourseNana.COM

R2 – horizontal length of the rectangle (in number of pixels across the display).  CourseNana.COM

R3 – vertical width of the side of the rectangle (in number of pixels down the display). R4 – the color of the rectangle. Read the PennSim manual for how to generate colors. CourseNana.COM

The TRAP needs to do basic boundary Checking. The TRAP checks to see if the length and
CourseNana.COM

width are valid from the starting location of the rectangle. If the rectangle would start outside or CourseNana.COM

go outside the video display, return without attempting to draw the rectangle. CourseNana.COM

Make certain to comment the TRAP’s inputs and outputs as well as key components of your code so we can understand your work.
CourseNana.COM

Also make certain to comment the trap “test” program you write. CourseNana.COM

As an example of using the TRAP, suppose the user calls the TRAP with the values of: R0=#2, R1=#1, R2=#5, R3=#2, R4=x7C00 (red). The TRAP would then draw a red box to the video display and like this:
CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

File setup CourseNana.COM

For this problem, you create a new trap TRAP_DRAW_RECT and add it to the operating system file os.asm. You’ll also create a new file called user_draw.asm to test your new trap. This new trap will get the rectangle parameters (starting location, size, color) from the user. Finally, create a script file user_draw_script.txt with the appropriate contents. CourseNana.COM

Your Task CourseNana.COM

Review the TRAP_DRAW_PIXEL to see how to interact with the video display. CourseNana.COM

Implement TRAP_DRAW_RECT. This trap will draw a rectangle whose location and dimensions will be set by the user. The color of the rectangle will also be an argument passed in by the caller. CourseNana.COM

Page 18 of 24 CourseNana.COM

CIT 593 – Module 07 Assignment Instructions Demonstrate your mastery of this TRAP in user_draw.asm which draws the following CourseNana.COM

rectangles (coordinates are given in (x, y) order):  CourseNana.COM

  • ●  A red rectangle, upper left coordinates: (50, 5), length = 10 and width 5 CourseNana.COM

  • ●  A green ectangle, upper left coordinates: (10, 10), length = 50, width 40 CourseNana.COM

  • ●  A yellow rectangle, upper left coordinates: (120, 100), length = 27, width 10 CourseNana.COM

    These are some edge cases that students ask about all the time. Now they are in the instructions! CourseNana.COM

  1. For R0=127, R1=123, R2=R3=1 only draw 1 pixel at (127,123) (the bottom right pixel). CourseNana.COM

  2. If the starting y-coordinate R1 plus vertical width R3 would go out of bounds, then do not CourseNana.COM

    draw the rectangle ever. CourseNana.COM

  3. If the starting x- or y-coordinate is out of bounds, do not draw the rectangle, unless you CourseNana.COM

    are attempting the Reset Starting Coordinates extra credit. CourseNana.COM

  4. If the starting x-coordinate R0 plus length R2 would go out of bounds, then do not draw CourseNana.COM

    the rectangle, unless attempting be Wrapped the Rectangle Horizontally extra credit.  CourseNana.COM

Page 19 of 24 CourseNana.COM

Extra Credit: Get a Character in a Time Limit with TRAP_GETC_TIMER CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

We recommend attempting this optional extra credit after you have Part 3 working successfully. You will need to read up on the Timer Device in the PennSim manual on your own. Since this is a challenge problem, the TAs will not be able to help much. CourseNana.COM

Create a new trap called TRAP_GETC_TIMER in os.asm and create two new files: user_string_ec.asm and user_string_ec_script.txt.
Your new
TRAP_GETC_TIMER must do everything that TRAP_GETC used to do, except now it must "time out" if a user doesn’t enter a key in 2 seconds.
How to do this? Recall that
TRAP_GETC checks the status register in a loop. Before entering that loop, set a timer for 2 seconds. Once you are inside the loop that checks the status register, you could also check the timer too. If the user doesn’t press a key in 2 seconds, return back to the caller without checking the data register.
We've included a TRAP called
TRAP_TIMER to give you an example of how to work with the timer I/O device.
Your
user_string_ec.asm file must call TRAP_GETC_TIMER to get a character from the keyboard if it is entered within 2 seconds. If the user types a character within 2 seconds, print CourseNana.COM

it to the ASCII display. Otherwise, your program must end gracefully without printing anything. CourseNana.COM

Page 20 of 24 CourseNana.COM

Extra Credit: Reset Starting Coordinates When Out of Bounds CourseNana.COM

To implement the extra credit, you will be modifying the behavior of TRAP_DRAW_RECT. Once you get the TRAP working, we encourage you to make a backup of your code in case your extra credit implementation is not functional in time for submission. CourseNana.COM

The original implementation does not draw a rectangle if the rectangle would start outside the Video Display. In this extra credit implementation, reset the starting coordinates to (0,0) and draw the rectangle starting here instead, using the original length/width values. If the reset rectangle would still go outside the Video Memory bounds with the original length/width values, do not draw the rectangle.
CourseNana.COM

If you are attempting both TRAP_DRAW_RECT extra credits, you should do both this extra credit and the following extra credit in the same TRAP. CourseNana.COM

Extra Credit: Wrap the Rectangle Horizontally CourseNana.COM

To implement the extra credit, you will be modifying the behavior of TRAP_DRAW_RECT. Once you get the TRAP working, we encourage you to make a backup of your code in case your extra credit implementation is not functional in time for submission.
CourseNana.COM

The original implementation does not draw a rectangle if the rectangle would go outside the horizontal limit of the video display. In this extra credit, if the box would go outside of Video Memory horizontally, correct the rectangle and make it "wrap around" the display (see diagram below). Do not wrap rectangles if they go outside video memory vertically. CourseNana.COM

If you are attempting both TRAP_DRAW_RECT extra credits, you should do both this extra credit and the previous extra credit in the same TRAP.
CourseNana.COM

Page 21 of 24
CourseNana.COM

Submission CourseNana.COM

When you are ready (before the deadline), go to Education -> Mark Complete.
CourseNana.COM

Gradescope Submission CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

Where to put the files
CourseNana.COM

Leave all the files in the working directory where the starter code started. CourseNana.COM

Pre-Submission Test CourseNana.COM

There are no pre-submission tests. CourseNana.COM

The Actual Submission CourseNana.COM

There are two parts to submit this assignment: Codio and Gradescope. CourseNana.COM

Codio Submission CourseNana.COM

You will need to create a single page PDF and upload it to Gradescope.
CourseNana.COM

Match every question to this single page. CourseNana.COM

Do not submit a copy of your code in the PDF. CourseNana.COM

This PDF requires two things: CourseNana.COM

1. Academic Integrity statement and signature. You can use this as a template (an entire word document template is available on Canvas): CourseNana.COM

Academic Integrity Agreement: CourseNana.COM

By submitting this agreement I certify that I have completed this homework CourseNana.COM

assignment on my own (without collaboration with another student or CourseNana.COM

unauthorized outside source) and have not plagiarized on this assignment (in accordance with Penn’s Code of Academic Integrity). CourseNana.COM

___________________ (your name, just type it in)
2.
A screenshot of your Completed Codio workspace. It must show: CourseNana.COM

  1. your Codio username CourseNana.COM

  2. the Module number for this assignment (do not reuse the screenshot between assignments; you will get a 0) CourseNana.COM

  3. A screenshot of an indication that the workspace is complete: CourseNana.COM

    1. The Warning that pops up after Marking Complete and typing "yes", OR CourseNana.COM

    2. The Education dropdown menu showing that Mark as Completed is inactive (greyed out) CourseNana.COM

Page 22 of 24 CourseNana.COM

Grading CourseNana.COM

This assignment is worth 220 points, which will be normalized to 100% for gradebook purposes. All problems have partial credit.
10 points for script file correctness
10 points for comments
CourseNana.COM

10 points for Part 1: Echo with TRAP_GETC/TRAP_PUTC
50 points for Part 2: Print Strings with TRAP_PUTS
50 points for Part 3: Get Strings with TRAP_GETS
90 points for Part 4: Draw Rectangles with TRAP_DRAW_RECT Do note that we are only grading for correctness, not efficiency. CourseNana.COM

Extra Credit CourseNana.COM

Main Assignment CourseNana.COM

The extra credits are worth a total of 10 percentage points. The maximum score on this assignment is 110%. CourseNana.COM

5 percentage points for correctly implementing TRAP_GETC_TIMER.
1 percentage point for correctly implementing
TRAP_DRAW_RECT to reset the coordinates.  CourseNana.COM

An Important Note of Plagiarism CourseNana.COM

ual, the extra credit do CourseNana.COM

● We will scan your assignment files for plagiarism using an automatic plagiarism detection tool. CourseNana.COM

● If you are unaware of the plagiarism policy, make certain to check the syllabus to see the possible repercussions of submitting plagiarized work (or letting someone submit yours).
CourseNana.COM

CIT 593 – Module 07 Assignment Instructions es not havpartial credit. CourseNana.COM

Page 23 of 24 CourseNana.COM

CourseNana.COM

FAQ CourseNana.COM

Quick Hints CourseNana.COM

These are some hints provided by TAs.
CourseNana.COM

Resources CourseNana.COM

● ASCII table CourseNana.COM

https://www.asciitable.com/ CourseNana.COM

CIT 593 – Module 07 Assignment Instructions CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
UPEEN代写,CIT593代写,Introduction to Computer Systems代写,TRAPs代写,memory-mapped devices代写,LC4代写,UPEEN代编,CIT593代编,Introduction to Computer Systems代编,TRAPs代编,memory-mapped devices代编,LC4代编,UPEEN代考,CIT593代考,Introduction to Computer Systems代考,TRAPs代考,memory-mapped devices代考,LC4代考,UPEENhelp,CIT593help,Introduction to Computer Systemshelp,TRAPshelp,memory-mapped deviceshelp,LC4help,UPEEN作业代写,CIT593作业代写,Introduction to Computer Systems作业代写,TRAPs作业代写,memory-mapped devices作业代写,LC4作业代写,UPEEN编程代写,CIT593编程代写,Introduction to Computer Systems编程代写,TRAPs编程代写,memory-mapped devices编程代写,LC4编程代写,UPEENprogramming help,CIT593programming help,Introduction to Computer Systemsprogramming help,TRAPsprogramming help,memory-mapped devicesprogramming help,LC4programming help,UPEENassignment help,CIT593assignment help,Introduction to Computer Systemsassignment help,TRAPsassignment help,memory-mapped devicesassignment help,LC4assignment help,UPEENsolution,CIT593solution,Introduction to Computer Systemssolution,TRAPssolution,memory-mapped devicessolution,LC4solution,