Comp2017 - assignment - implementing and performing


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

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: Comp2017 - assignment - implementing and performing
Reference No:- TGS02747078

Expected delivery within 24 Hours