Implementing and performing operations on a virtual stack

Assignment Help Programming Languages
Reference no: EM131952604

Task Description

In this assignment you will be implementing and performing operations on a virtual stack. You will need to emulate this virtual stack to store and reference variables and stack frame contexts before reading a set of pseudo assembly instructions that dictate the operations that should be performed on the stack. Your program will take a single command line argument being the name of the file containing your pseudo-assembly code.

Before attempting this assignment it would be a good idea to familiarise yourself with the stack, registers, stack frames, stack pointers, and program counters. Over the course of this assignment you will need to track your own stack frames, manage operations, dynamically allocate memory and handle files.

Command Format

You will be provided with a series of commands as operations taking the form: ([Address][Address_type])[Address][Address_type][Operation Code]

A series of operations form a function and will have some associated unique 4 bit label.

The second address and address type field is optional and will not be required for unary operations. The address type specifies whether it is a stack address, a value, a register address or a pointer to another stack address. Stack addresses are 7 bits long, register addresses are 3 bits long and values are 8 bits long and pointer addresses are also 7 bits long.

The address type itself is two bits long and specifies the type of the preceding address.

00 - value: 1 byte long. The value in the preceding 8 bits should be interpreted as a single byte value.

01 - register address: 3 bits long. This address refers to one of the eight fixed registers

10 - stack address: 7 bits long. This refers to an address on the stack containing a single byte.

11 - pointer valued: 7 bits long. This refers to an address on the stack containing a single byte that itself refers to another address on the stack. This is useful for accessing the stack pointer. The registers cannot be accessed using this pointer.

Note that using the stack pointer to allocate a variable should result in the value of the stack pointer being incremented.

The opcodes associated with these pseudo-assembly instructions are detailed below. Opcodes:

00 - [MOV] - Pushes the value at some point in memory to another point in memory (register or stack)

01 - [CAL] - Calls another function, the first argument is a single byte (using the '00' type) rep- resenting what function is being called, the second argument is the stack address that starts a sequence of arguments to be passed to the function. When the function returns, the return value should be placed on the next available stack address.

10 - [POP] - Pops memory from the stack, to be returned to the calling function. Your implemen- tation should manage the storage of this value.

11 - [RET] - Terminates the current function, this is guaranteed to always exist at the end of each function. There may be more than one RET in a function.

100 - [ADD] - Takes two register addresses and adds the values, storing the result in the first listed register

101 - [AND] - Takes two register addresses and ANDs their values, storing the result in the first listed register

110 - [NOT] - Takes a register address and performs a bitwise not operation on the value at that address. The result is stored in the same register

111 - [EQU] - Takes a register address and tests if it equals zero, the value in the register will be 1 if it is 0, or 0 if it is not. The result is stored in the same register.

You will need to read each of the op-codes and implement the operation on the memory specified.

Each function is defined with a one byte header dictating the label of the function and the number of arguments, and a one byte tail specifying the number of instructions in the function. The function with the label 0 is the main function and should be executed first.

[Padding bits]
[function label(4bits)]|[number of arguments(4bits)] [OPCODE]
[OPCODE]
... [RET]
[Number of instructions(1byte)]
[function label(4bits)]|[number of arguments(4bits)] [OPCODE]
[OPCODE]
... [RET]
[Number of instructions(1byte)]

The first few bits of the file are padding bits to ensure that the total number of bits in the file accu- mulates to a whole number of bytes.

The number of padding bits will always be strictly less than one byte.

The last byte in each function dictates how many operations are performed within the function

The assembly code given for each of these functions will use relative addresses and always assume that the address 0x00 will store the stack frame pointer, 0x01 will store the stack pointer, 0x02 will store the program counter and 0x03 will store any arguments to the function. If no argument exists then 0x03 will be unused.

You have a fixed set of registers, each with an associated three bit label (0-7). Each register can store a single byte at a time. You may note that some of the operations can only be performed on the registers.

Attachment:- Assignment.zip

Reference no: EM131952604

Questions Cloud

What pain is and how it is measured : How do you understand that experience differently now that you've read about what pain is and how it is measured? Using what you learned
Preference regarding punishment philosophy : Explain your personal preference regarding punishment philosophy. You may consider concepts such as retribution, deterrence, incapacitation
What is the utilization of the machine : A single machine is used to make two components, let's call them A and B. It takes 249 seconds to switch over from A to B or from B to A.
List two goods that could have this elasticity : List two goods that could have this elasticity and explain why you chose them. Draw a picture of the new equilibrium and label the new P and Q.
Implementing and performing operations on a virtual stack : COMP2017 - Assignment - Implementing and performing operations on a virtual stack. You will need to emulate this virtual stack to store and reference variables
Meeting alcholol anonymous and its importantance : Identify the 12 step meeting alcholol anonymous and its importantance. Give your impression of what takes place at the meeting, the facilitator/leader
How does enculturation influence male and female gender role : How does enculturation influence male and female gender roles? Is there a universal division of labor based on sex?
What structure would you recommend and why : Your organization is moving away from a rigid organizational structure. As a supervisor, you're asked for your input on the changes that should be made.
What is the significance of designing a production system : What is the significance of designing a production system that has "robust" behavior? Provide an example of both robust and non-robust performance.

Reviews

len1952604

4/21/2018 8:00:40 AM

You will not be tested on the internal state of your stack and as a result you have a degree of flexibility in your implementation. Don’t forget to free any allocated memory! You will not be given invalid inputs, excepting cases where a stack overflow occurs. Evaluation and Submission You will submit your assignment using Edstem. You are encouraged to write your own test cases and files to check the validity of your program while also submitting it to Edstem. 4 Marks are based on automatic marking of the assessment, automatic test cases include test cases that are both visible and hidden on the Edstem assignment submission page.

len1952604

4/21/2018 8:00:31 AM

Start by reading in the operation code from the above examples, you will need to use bitwise oper- ations here and should refer to the relevant tutorial sheet. Switch and case statements will be useful here. You don’t know the number of padding bits at the start of the file in advance! As you do not know the sizes of some of the objects before you read the associated files, you will need to dynamically allocate memory. Spend some time working out how the stack pointer, the frame pointer and the program counter work before getting the rest of the program written.

Write a Review

Programming Languages Questions & Answers

  Prepare calculator application - mock objects for testing

Which other classes do you think will need to be stubbed with mock objects for testing the application? For each class you identify explain why you think that class needs mocking and at least three di erent mocked behaviours you will need.

  How did you create a module or method in quicklab

How did you create a ‘module' or ‘method' in QuickLab? Provide your screenshot! How did you document your program (Provide your example--codes or screenshot?

  Show tic-tac-toe game scenario diagram

The assignment is not to implement this game in Ruby. Rather, the assignment is to use scenario diagrams to discover the objects, their responsibilities, and the messages they respond to

  Determine the acceptable error for a given estimated time

Write a function that uses a switch statement to determine the acceptable error for a given estimated flight time, according to this table.

  Javascript function to verify fields if cookie is added

JavaScript function has verified that all the required fields have been filled, cookie is added to user's computer. If same user tries to fill out form second time.

  Program to prompt teacher to input assignment number

The program must prompt teacher to input the assignment number. Score for student for that assignment will be displayed.

  Data set containing an unknown number of integers

The program should use I/O redirection to accept a file defined by the user which is a data set containing an unknown number of integers. The integers should be stored in an array, and printed to an output file - also defined by the user through r..

  Create block using a loop to determine number of items

Create a block using a loop that will determine the number of items that can be purchased based on the price of the item and the total amount available to spend.

  Shell script that will count the number of files in account

Modify the script to get it to back up to "X" number of days and list the files that were modified for each day.

  Design a class named timeoff

Design a class named TimeOff. The purpose of the class is to track an employee's sick leave, vacation, and unpaid time off. It should have, as members.

  What criterion is being used to determine best estimates

What we would like to do is create similar tables in an .rtf file that produces the same statistics for any numerical value against each level of a know classification/factor from any data set we wish to inspect.

  Write an application that stores 100 movies

Write an application that stores 100 movies and displays them by category.  The user can enter any of the categories to display the films in the list that match the category.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd