Skip to the content.

Overview

This assignment will help you understand the impact that assembly instruction have on the registers and memory. It requires you to implement several functions within the context of a program that simulates the behavior of register and memory. The functions you need to implement focus on different instructions that we have most recently studied. In particular:

Learning Objectives

  1. To understand how each assembly instruction works with registers and memory.

  2. To understand how program counter is updated after executing each instruction.

Getting Started

To get started, follow these steps:

  1. Download the starter code.
  2. Unzip the project.zip with the following command unzip -d PROJECT project.zip. This will create a new directory called PROJECT. You can replace PROJECT with a directory name of your choice.
  3. cd into the PROJECT directory and investigate the project.

If you follow the above steps correctly, you should have the following folder structure after unzipping (assuming the project name is “PROJECT”):

PROJECT/
  include/
  lib/
  obj/
  src/
  test/
  Makefile

After you have the code extracted you should go ahead and investigate. You can run make from the command line and your project will build and produce potential error results. See more information below.

Code Structure

This exercise contains the following important folders:

Compiling The Code

To compile the code in this assignment you must run the following command:

$ make

The make command will run the C++ compiler to build a program executable and a test executable. These are often referred to as program binaries in Unix/Linux terminology.

In addition, the make command will produce a submission.zip every time you run it. The submission.zip file is what you upload to Gradescope to submit your solution. See submission instructions below.

Compiling This Project

This project will produce a couple of executables including:

Testing The Code

After you have successfully compiled the code using make you can run the test executable. Here is an example of what it looks like to run a test executable:

$ ./hello_test
[==========] Running 2 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 2 tests from sum_test
[ RUN      ] sum_test.test_sum_positive
[       OK ] sum_test.test_sum_positive (0 ms)
[ RUN      ] sum_test.test_sum_negative
[       OK ] sum_test.test_sum_negative (0 ms)
[----------] 2 tests from sum_test (0 ms total)

[----------] Global test environment tear-down
[==========] 2 tests from 1 test suite ran. (2 ms total)
[  PASSED  ] 2 tests.

The tests that are provided are a subset of the tests that the autograder will run. However, it gives you a good idea if you are on the right track.

To test assembly instruction in the test folder, you can run assembly_app with the trace.

./assembly_app test/movl_register.txt

Instructions

You already know how to deal with C code, so we’ll make things a bit easier for you – all of the modifications you have to do are going to be in src/interpreter.c!

In this project, you will need to review the course materials for each instructions to be implemented. You will also need to handle each potential error for each instructions.

Take a look in include/interpreter.h, take note of the System struct and Memory.

In the Memory struct, we use one array to store instructions and another array to store memory data.

Here is an explanation for each field of Memory:

In the System struct, there are three fields:

Part 1: Understand The Code

We provide you with starter code for this assignment. Your first task is to read through interpreter.c and interpreter.h files in detail so you understand the structure of the code.

interpreter.h

you should review those enum types and understand how to use them

interpreter.c

Part 2: Implement Functions for Each Assembly Instruction of Move/Arithmetic operation

The second part of this assignment is to write the following functions in the file src/interpreter.c.

Part 3: Implement Functions for Each Assembly Instruction of Control operation

Part 4: Implement An Execution Simulation Function

The third part of this assignment is to write the function execute_instructions in the file src/interpreter.c. Utilizing the EIP register’s value (also known as the program counter), this function is responsible for fetching and executing instructions from the instruction segment in system memory.

Debugging Help

It is important that you use the gdb debugger to debug your code when you encounter problems. You can easily start the gdb debugger from the command line:

$ gdb PROGRAM

Where PROGRAM is the program you compiled. You should look at the provided gdb cheatsheet to see some of the commands you can execute. If you need additional help you can take a look at this tutorial.

You will inevitably encounter cases when your code fails a test or worse, the test program exits with a segmentation violation (segfault). To debug the code in a test requires you to understand how the google test framework generates C++ code and how the C++ compiler generates method signatures. In short, this is what you want to do:

$ gdb TEST_PROGRAM
(gdb) b TestSuite_TestName_Test::TestBody()

The SuiteName and TestName correspond to how you write a test using the google test framework. In particular, this is the basic structure of a test:

TEST(SuiteName, TestName) {
  // the test body
}

You should also know that the b (break) command provides tab completion. So, you can type in the following:

(gdb) b TestSuite[TAB][TAB]

The [TAB] is hitting the tab key on your keyboard. You can hit it twice in rapid succession to see all the possible completions.

Autograder

The autograder is used to test your code more deeply. If you follow the specifications of this exercise exactly then you should be able to pass all of the tests that you are provided and all of the tests the autograder is using to check your solution.

To run the autograder on your solution you must upload your submission.zip file (generated by running make) to Gradescope. More information about how to do this is provided below.

General Information and Project Policies

Academic Honesty

All work that is completed in this assignment is your own. You may talk to other students about the problems you are to solve, however, you may not share code in any way. What you submit *must be your own work.

You may not use any code that is posted on the internet. If you are not sure it is in your best interest to contact the course staff. We will be using software that will compare your code to other students in the course as well as online resources. It is very easy for us to detect similar submissions and will result in a failure for the exercise or possibly a failure for the course. Please, do not do this. It is important to be academically honest and submit your work only. Please review the UMass Academic Honesty Policy and Procedures so you are aware of what this means.

Copying partial or whole solutions, obtained from other students or elsewhere, is academic dishonesty. Do not share your code with your classmates, and do not use your classmates’ code. If you are confused about what constitutes academic dishonesty you should re-read the course policies. We assume you have read the course policies in detail and by submitting this project you have provided your virtual signature in agreement with these policies.

Gradescope

We use Gradescope to run our autograding software and record your grade for these assignments. You may submit this assignment as many times as possible up to the due date. If you encounter a problem with the autograder you should contact the course staff immediately.

Submission

You must submit the generated submission.zip file that is created by running the make command to Gradescope. To do this you will need to download the submission.zip file from the EdLab environment to your local machine then upload submission.zip to Gradescope. Gradescope will run your submission in our autograder environment and give you a report of what tests passed and which did not. Again, you are welcome to submit as many times as you would like.