1. Homepage
  2. Programming
  3. CIT 593 Introduction to Computer Systems - Module 06 Assignment: While Loop, Subroutine, Data Memory and Pointers

CIT 593 Introduction to Computer Systems - Module 06 Assignment: While Loop, Subroutine, Data Memory and Pointers

Engage in a Conversation
UPEENCIT 593CIT593Introduction to Computer SystemsLC4Assembly

CIT 593 – Module 06 Assignment CourseNana.COM

Contents CourseNana.COM

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

Codio Setup 4 Open the PennSim Window 4 CourseNana.COM

Start PennSim in the Terminal Command Line 6 Troubleshooting Codio Issues 7 Run multiply.asm in PennSim 8
CourseNana.COM

Starter Code CourseNana.COM


CIT 593 – Module 06 Assignment Instructions CourseNana.COM

Assembly Programming Instructions
CourseNana.COM

Requirements CourseNana.COM

General Requirements 11 CourseNana.COM

Part 1: While Loops in Assembly 11 CourseNana.COM

Part 2: Subroutines in Assembly 11 CourseNana.COM

Part 3: Working with Data Memory 12 Extra Credit 
CourseNana.COM

Suggested Approach 13 CourseNana.COM

High Level Overview 13 CourseNana.COM

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

Part 1: While Loops in Assembly 14 Part 2: Subroutines in Assembly 16 Part 3: Working with Data Memory 17 Part 4: Extra Credit 18 CourseNana.COM

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

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

Grading 20 Main Assignment 20 Extra Credit 20 An Important Note of Plagiarism 20 CourseNana.COM

Page 1 of 21 CourseNana.COM

FAQ
Quick Hints
CourseNana.COM

Resources CourseNana.COM

CIT 593 – Module 06 Assignment Instructions CourseNana.COM

Page 2 of 21 CourseNana.COM

Assignment Overview CourseNana.COM

CIT 593 – Module 06 Assignment Instructions CourseNana.COM

In this assignment, we will start programming in the LC4 assembly language. We also introduce PennSim, a computer that can assemble and run LC4 programs. Finally, we introduce Codio, a remote hosted Linux platform that provides a standardized environment to ensure consistent grading.
CourseNana.COM

Learning Objectives CourseNana.COM

This assignment will cover the following topics: CourseNana.COM

● Donottrytodoitallinoneday CourseNana.COM

Page 3 of 21 CourseNana.COM

Getting Started CourseNana.COM

Codio Setup CourseNana.COM

This is the section about all the steps to get into PennSim.
Be sure to open Codio from the Codio Assignment page in Canvas.
CourseNana.COM

Open the PennSim Window CourseNana.COM

PennSim runs as a GUI, so you will need to open a window to display the GUI. CourseNana.COM

  1. Along the top menu, click the globe icon labeled as PennSim Window CourseNana.COM

  2. This should open a new Codio Tab using a fourword-randomname-3000 with a black screen. The Penn Sim Window is now open, but we still need to launch the program CourseNana.COM

3. You may find having multiple Codio tabs cumbersome. If so, select the PennSim
CourseNana.COM

CIT 593 – Module 06 Assignment Instructions CourseNana.COM

Window dropdown menu arrow, then choose New Browser Tab. Following Steps 1 and
CourseNana.COM

2 again will open PennSim Window in a new browser tab which you may find easier to navigate. CourseNana.COM

If you get error 401 (Unauthorized), you may need to accept cookies and/or switch to CourseNana.COM

  1. Google Chrome browser. Adding [*].codio.com as an allowed third-party for cookies  should be sufficient. CourseNana.COM

Start PennSim in the Terminal Command Line
CourseNana.COM

1. On the left side of the screen, you can see the File TrCodio. CourseNana.COM

2. Click on the Terminal icon CourseNana.COM

3. This will open a Linux terminal command line in the main window.
CourseNana.COM

ee. This shows all the files in
CourseNana.COM

4. Type this command to launch PennSim
CourseNana.COM

java -jar PennSim.jar

5. Go to the PennSim Window you created in the previous section. CourseNana.COM

Troubleshooting Codio Issues CourseNana.COM

In the event the PennSim freezes and refreshing Codio doesn't help, go back to the terminal and do Control+C to terminate PennSim, then run this command in the terminal CourseNana.COM

pkill -f PennSim.jar

Then rerun the launch command in Step 4. CourseNana.COM

CIT 593 – Module 06 Assignment Instructions CourseNana.COM

You may also attempt to go to Project->Restart Box to reboot the computer. Do not select Reset Box as this will delete your work.
CourseNana.COM

Page 7 of 21
CourseNana.COM

Run multiply.asm in PennSim1. CourseNana.COM

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

a. Review the contents of the file. Hopefully this looks familiar from lecture (if not, review this module's lecture content). CourseNana.COM

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

a. This file contains all the commands you must enter in PennSim to reset the simulator,assembletheprogram,andloaditintomemory. Besureto understand what each line and command does. CourseNana.COM

3. In the PennSim Window go to the command line in the Controls section and enter CourseNana.COM

   script multiply_script.txt

CIT 593 – Module 06 Assignment Instructions
CourseNana.COM

This will run all the commands in the script line-by-line, outputting the result to the CourseNana.COM

Console Log. See if you can match the commands in the script file to the messages in CourseNana.COM

the Console Log output. Note how the script file automates manually typing many CourseNana.COM

commands. The script files will save you a lot of manual work so you can focus on programming instead!
CourseNana.COM

Page 8 of 21
CourseNana.COM

CIT 593 – Module 06 Assignment Instructions 5. Press Step to run the program line-by-line. Carefully examine how each instruction CourseNana.COM

updates the registers, PC, PSR, CC, etc, and also that the yellow highlight bar moves to  CourseNana.COM

each instruction. CourseNana.COM

Page 9 of 21 CourseNana.COM

Starter Code CourseNana.COM

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

CIT 593 – Module 06 Assignment Instructions CourseNana.COM

factorial.asm

- contains the pseudocode for the While Loops in Assembly problem. Complete Part 1 here. CourseNana.COM

factorial_script.txt

- contains simple commands to assemble and load the factorial program for the While Loops in Assembly problem. Complete Part 1 here. CourseNana.COM

multiply.asm

- demo program from lecture CourseNana.COM

multiply_script.txt

- demo script file to automate commands CourseNana.COM

PennSim.jar CourseNana.COM

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

Page 10 of 21
CourseNana.COM

Requirements CourseNana.COM

CIT 593 – Module 06 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 in Codio. 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 useR0forAandR1forB. CourseNana.COM

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

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

o TAs can login and view your code for asynchronous debugging.
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: While Loops in Assembly
CourseNana.COM

  • ●  You MUST use the filenames factorial.asm and factorial_script.txt. CourseNana.COM

  • ●  You MUST implement the pseudocode algorithm as provided unless otherwise noted: CourseNana.COM

○ You MAY setBto#1forA = 0. CourseNana.COM

○ You MAY setBto#-1for values ofAless than0
● You MAY hardcode A = 5 testing purposes. We will change the value of A (and only A) CourseNana.COM

ourselves to check your work. CourseNana.COM

Part 2: Subroutines in Assembly CourseNana.COM

  • ●  You MUST use the filenames factorial_sub.asm and factorial_sub_script.txt. CourseNana.COM

  • ●  You MUST use a subroutine to calculate the factorial and it MUST be called CourseNana.COM

    SUB_FACTORIAL. CourseNana.COM

  • ●  You MUST follow the provided pseudocode (this includes the factorial algorithm from CourseNana.COM

    Part 1) unless otherwise noted. CourseNana.COM

  • ●  Your subroutine MUST only take a single argument, A. CourseNana.COM

  • ●  You MUST determine the largest value of A that your subroutine can correctly calculate the factorial (call it X for reference) CourseNana.COM

Page 11 of 21 CourseNana.COM

CIT 593 – Module 06 Assignment Instructions ● Your subroutine MUST check the value of A: CourseNana.COM

Extra Credit CourseNana.COM

○ If the value of A is less than 0, your subroutine MUST return #-1 CourseNana.COM

  • ○  If the value of A is greater than X, your subroutine MUST return #-1. CourseNana.COM

  • ○  Otherwise, your subroutine MUST return the factorial of A. CourseNana.COM

■ If the value of A is 0, your subroutine MAY return #1. CourseNana.COM

  • ●  Your subroutine MUST have the return value in R1 when it returns. CourseNana.COM

  • ●  For this Part only, you MUST NOT execute the subroutine again once you have returned from the subroutine. CourseNana.COM

    Part 3: Working with Data Memory CourseNana.COM

  • ●  You MUST use the filenames dmem_fact.asm and dmem_fact_script.txt. CourseNana.COM

  • ●  You MUST pre-load Data Memory, starting at address x4020, with the following values: CourseNana.COM

    #6, #5, #8, # CourseNana.COM

  • ●  You MAY assume that we will only test five values in Data Memory starting at this address. CourseNana.COM

  • ●  For each value in Data Memory, you MUST do the following:  CourseNana.COM

    • ○  Load Data Memory as the value of A to pass to your subroutine CourseNana.COM

    • ○  Follow the same factorial requirements in Part 2. You SHOULD NOT change the subroutine in this problem. CourseNana.COM

○ Store the returned value into the same Data Memory address, overwriting the original value. CourseNana.COM

  • ●  You MUST use the filenames dmem_fact_ec.asm and dmem_fact_ec_script.txt. CourseNana.COM

  • ●  You MUST pre-load Data Memory, starting at address x4020, with the following values: CourseNana.COM

#6, #5, #8, #10, #-5
CourseNana.COM

● You MUST modify your subroutine from Part 3 to accept an address as the input value, CourseNana.COM

rather than a number to calculate. CourseNana.COM

  • ○  Your subroutine therefore MUST perform the loading and storing steps. CourseNana.COM

  • ○  You MUST follow the other factorial requirements in Part 2. CourseNana.COM

Page 12 of 21 CourseNana.COM

Suggested Approach CourseNana.COM

5. In Subroutines in Assembly, copy your While Loops in Assembly solution into a new file and expand it to work as a subroutine. We also introduce if/then/else block constructs CourseNana.COM

here, so be sure you handle the edge cases. CourseNana.COM

6. In Working With Data Memory in Assembly, set up pre-loaded data in Data Memory, then have your program load the data and pass it to the subroutine. The subroutine does the CourseNana.COM

CIT 593 – Module 06 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. Be sure you understand how Codio works: where the File Tree is, how to use the Terminal to start PennSim, how to get the desired tab configuration CourseNana.COM

  2. Run the multiply program to get a sense of how PennSim works. CourseNana.COM

  3. Read the PennSim Manual (linked in Canvas). CourseNana.COM

  4. Get the While Loops in Assembly working. This is just a basic while loop, to introduce you to the programming construct. Be sure to test it thoroughly. CourseNana.COM

stores the calculated result back into Data Memory and does this for five different values.s the 7. Attempt the optional extra credit. CourseNana.COM

factorial calculatio nareturn result to thmain program. CourseNana.COM

The main program CourseNana.COM

Page 13 of 21 CourseNana.COM

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

Detailed Overview CourseNana.COM

CIT 593 – Module 06 Assignment Instructions
CourseNana.COM

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

Part 1: While Loops in Assembly CourseNana.COM

File Setup CourseNana.COM

You will need to modify factorial.asm and factorial_script.txt for this problem. CourseNana.COM

The pseudo-code below (and in the factorial.asm starter code) describes the mathematical operation known as a factorial. When the algorithm below is completed, the variable B will contain A! For the given positive value of A, the factorial is defined as 5 x 4 x 3 x 2 x 1 = 120. CourseNana.COM

Here is the pseudo-code for the factorial algorithm: CourseNana.COM

A = 5 ; // example to do 5!
CourseNana.COM

      B = A ; // B=A! when while loop completes

A=A-1; B=B*A;
CourseNana.COM

while (A > 1) { CourseNana.COM

Your task for this part is to implement this algorithm using LC4 Assembly. Use R0 to hold  CourseNana.COM

variable A, and R1 to hold variable B.
In your File Tree find
factorial.asm and open it. Implement the factorial algorithm within CourseNana.COM

this file. Test it using the other script file factorial_script.txt CourseNana.COM

You may hardcode A to have the value 5 for testing purposes, but when we grade your assignment, we will try out different numbers to ensure your algorithm is working. Be certain to run your program in PennSim and make sure it is working for different values of A. CourseNana.COM

For this problem, we just want you to implement the while-loop algorithm as outlined in the pseudocode. But we recognize that some students are uncomfortable returning an "incorrect" result. If you've been paying attention, you may have noticed that the algorithm would return 0! = 0. Therefore, you may, if you choose, set B = 1, but this is completely optional and not required. CourseNana.COM

Likewise, when A < 0, your program just needs to end gracefully. That is, it should stop on the END label without throwing an Exception. You may, if you choose, setup your while loop to return -1 to indicate "unable to calculate", but this is completely optional and not required in this problem. CourseNana.COM

In your program and in your script file be certain to set a breakpoint labeled END. This will ensure you program ends, instead of requiring an infinite loop to stop execution or throwing an Exception. Also, be certain to comment your code to help us understand the flow of your program as we grade. CourseNana.COM

Page 14 of 21 CourseNana.COM

CIT 593 – Module 06 Assignment Instructions Don't move on to Part 2 until your program calculates factorials correctly (aside from the one CourseNana.COM

exceptions listed here), ends on the END label, and does not throw exceptions. Be sure to  CourseNana.COM

comment your program. CourseNana.COM

Page 15 of 21
CourseNana.COM

Part 2: Subroutines in Assembly CourseNana.COM

File Setup CourseNana.COM

For this problem, you’ll convert your factorial program from Part 1 into a subroutine and call it using JSR. CourseNana.COM

You will need to create two new files: factorial_sub.asm and factorial_sub_script.txt for this problem. After you’ve completed Part 1, copy the file factorial.asm in the File Tree by right-clicking on the file, clicking copy and then right-clicking once again in the File Tree and pressing paste. Rename this copied file as factorial_sub.asm. Repeat this process with factorial_script.txt, and rename the copy as factorial_sub_script.txt. Next, you’ll need to open and edit this new script file to ensure it assembles and loads factorial_sub.asm instead of factorial.asm. CourseNana.COM

Your Task CourseNana.COM

Your task for this Part is to make your While Loop into a Subroutine. CourseNana.COM

that.
Above your subroutine code, implement the following pseudocode to call your subroutine:
CourseNana.COM

      A = 6 ; // this is the only thing a user would change

B = sub_factorial (A) ;
CourseNana.COM

// your sub_factorial subroutine you just wrote goes here

After you return from the subroutine, make certain to “jump over" your subroutine to a new END label, so that your subroutine isn’t executed twice! Make certain to set END as a breakpoint in your script file. At this point, your While Loop should be converted to a Subroutine. CourseNana.COM

Next, you will need to add some checks to test if the user has provided a value of A that your subroutine cannot perform the calculation correctly. First, determine X, the largest value of A that your factorial subroutine will calculate the correct factorial. Add an if/else statement to the start of your subroutine to ensure A is both a positive number and also is less than or equal to the largest number your assembly program can work with. If A <= 0 OR A > X, then set B = -1 and immediately return from the subroutine without attempting to find the factorial. CourseNana.COM

As a hint, first determine if we as programmers should consider A as signed or unsigned. This will help you correctly identify X for your program. CourseNana.COM

CIT 593 – Module 06 Assignment Instructions CourseNana.COM

Start by adding the label SUB_FACTORIAL to the top of your factorial program. Remove any CONST instructions you may have that would set the variable A (register R0) inside your subroutine. We want A to be an argument to your subroutine, so its value must be set before the subroutine is called. CourseNana.COM

Inside the subroutine, replace the END label with a RET instruction. If you have done this correctly, when the subroutine returns, B (R1) holding the return value of the subroutine. Of course, your program should still end after the subroutine returns, be sure to implement CourseNana.COM

Page 16 of 21 CourseNana.COM

Part 3: Working with Data Memory CourseNana.COM

For this problem, you CourseNana.COM

will have to review the exam CourseNana.COM

File setup CourseNana.COM

After you’ve completed Part 2, copy factorial_sub.asm and paste it with the new name dmem_fact.asm. Likewise, copy factorial_sub_script.txt and paste it with the new name dmem_fact_script.txt. Next, update dmem_fact_script.txt to ensure assembles and loads dmem_fact.asm instead of factorial_sub.asm. CourseNana.COM

Your Task CourseNana.COM

Use the .FILL directive to populate five rows of data memory starting address x4020 with the numbers 6, 5, 8, 10, -5. CourseNana.COM

Write a short assembly program that does the following for each of the five rows of data memory that you’ve populated: CourseNana.COM

CIT 593 – Module 06 Assignment Instructions CourseNana.COM

ple of working with data memory in lecture. CourseNana.COM

1. load the data from Data Memory into A,
2. call the subroutine you’ve created in Part 2 on each of those rows, and
CourseNana.COM

3. after the factorial subroutine returns on each row, store the calculated factorial back to the same data memory row, overwriting the original number.
CourseNana.COM

The specific implementation of the MAIN part of your program is up to you, but you must call  CourseNana.COM

your subroutine for each value of A. As an example of how the first row of data memory should look after your program completes, address x4020 should have the number #720. CourseNana.COM

Be careful with manipulating the address with .CODE, .DATA, and .ADDR.Page 17 of 21 CourseNana.COM

Part 4: Extra Credit CourseNana.COM

For this optional part dmem_fact_ec_script.txt.
CourseNana.COM

Create a new program in dmem_fact_ec.asm that allows your subroutine SUB_FACTORIAL to take in a data memory address instead of a value as its only argument. The new SUB_FACTORIAL should then load the value from data memory, find its factorial, and store the result back in data memory, and return without a return value. Do this for the same five values. CourseNana.COM

you wd files ec.asm and ill need to generate two more mem_fact_ CourseNana.COM

Page 18 of 21 CourseNana.COM

Submission CourseNana.COM

Codio Submission CourseNana.COM

Gradescope Submission CourseNana.COM

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

CIT 593 – Module 06 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

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

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 19 of 21 CourseNana.COM

CIT 593 – Module 06 Assignment Instructions CourseNana.COM

Page 20 of 21
CourseNana.COM

CourseNana.COM

Grading CourseNana.COM

Main Assignment CourseNana.COM

This assignment is worth 140 points, which will be normalized to 100% for gradebook purposes. All problems have partial credit.
20 points for script file correctness and comments
40 points for While Loops in Assembly problem
CourseNana.COM

40 points for Subroutines in Assembly problem
40 points for Working with Data Memory problem
Do note that we are only grading for correctness, not efficiency.
CourseNana.COM

Extra Credit CourseNana.COM

CIT 593 – Module 06 Assignment Instructions
CourseNana.COM

The extra credit is worth 5 percentage points. The maximum score on this assignment is 105%. As usual, the extra credit does not have partial credit.
CourseNana.COM

An Important Note of Plagiarism
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
CourseNana.COM

see the possible repercussions of submitting plagiarized work (or letting someone CourseNana.COM

submit yours). CourseNana.COM

Page 21 of 21 
CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
UPEEN代写,CIT 593代写,CIT593代写,Introduction to Computer Systems代写,LC4代写,Assembly代写,UPEEN代编,CIT 593代编,CIT593代编,Introduction to Computer Systems代编,LC4代编,Assembly代编,UPEEN代考,CIT 593代考,CIT593代考,Introduction to Computer Systems代考,LC4代考,Assembly代考,UPEENhelp,CIT 593help,CIT593help,Introduction to Computer Systemshelp,LC4help,Assemblyhelp,UPEEN作业代写,CIT 593作业代写,CIT593作业代写,Introduction to Computer Systems作业代写,LC4作业代写,Assembly作业代写,UPEEN编程代写,CIT 593编程代写,CIT593编程代写,Introduction to Computer Systems编程代写,LC4编程代写,Assembly编程代写,UPEENprogramming help,CIT 593programming help,CIT593programming help,Introduction to Computer Systemsprogramming help,LC4programming help,Assemblyprogramming help,UPEENassignment help,CIT 593assignment help,CIT593assignment help,Introduction to Computer Systemsassignment help,LC4assignment help,Assemblyassignment help,UPEENsolution,CIT 593solution,CIT593solution,Introduction to Computer Systemssolution,LC4solution,Assemblysolution,