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

  Write a complete program to calculate the angle

Write a complete program to calculate the angle, the perimeter, the area, the radius of the inscribed circle, the radius of the circumscribed circle of a polygon, and the positive difference of the two radii given the input of the length of one si..

  Write program to accept six pairs of values from user

Write a program that accepts six(6) pairs of values from the user and then calculates and stores the difference of each pair of values in an array.

  Determine the number of the nearest cross street

Write a function that uses a switch statement to determine the number of the nearest cross street for a given address and avenue number according to the preceeding alogorithm. Then write a program to test your function.

  Create prototype of function which returns integer value

Develop the C++ function which needs one integer parameter and returns the integer value. Function will double the value passed to it and return doubled value.

  Design an abstract class called shape

Design an abstract class called Shape. This class must contain a single constructor that accepts a single numeric value that can be used to calculate various values, one of which is area.

  Write a program that implements quicksort

To understand the value of recursion in a programming language, write a program that implements quicksort, first using recursion and then without recursion

  Weka answer in the file i upload and do the best this

answer in the file i upload and do the best. this assignment would need use weka on last question. please follow

  Research on dynamic arrays

Write a 2 page research paper (excluding title and reference pages) on dynamic arrays. Explain the concepts discussed in the textbook using at least an example not included in the textbook.

  Create program which computes person-s bmi

Create a program which computes a person's body mass index? Design a modular program that calculates and display a person's body mass index (BMI).

  Design and develop a unix file sharing system

Design and develop a UNIX file sharing system. For this task you will be required to develop a simple application in C programming language.

  Create artefacts to encapsulate the steps needed

How to create your own functions - Create a program named InvestmentCal, which will read and write values from the Terminal - Pass Task 2.4: My Functions

  How does the use of open source products associate to the

the use of open source products and solutions is a popular topic. what is open source? identify the open source

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