1. Homepage
  2. Programming
  3. [2021] COMP2017/COMP9017 Systems Programming - Assignment 2 x2017 Assembly language

[2021] COMP2017/COMP9017 Systems Programming - Assignment 2 x2017 Assembly language

Engage in a Conversation
COMP2017System ProgrammingCUniversity of SydneyCOMP9017

COMP2017 / COMP9017 Assignment 2 CourseNana.COM


CourseNana.COM

This assignment is worth 15% of your final assessment CourseNana.COM

In this assignment you will be implementing and performing operations on a simple virtual machine. You will need to emulate this virtual machine to store and reference variables and stack frame con- texts 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 path to the file containing your x2017 assembly code. CourseNana.COM

Before attempting this assignment it would be a good idea to familiarise yourself with the stack, registers, stack frames, stack pointers, program counters, assembly and machine code. A strong understanding of these concepts is essential to completing this assignment. Section 3.6 and 3.7 of the course textbook provide specific detail to x86_64 architecture, however you can review these as a reference. CourseNana.COM

In order to complete this assignment at a technical level you should revise your understanding of bitwise operations, file IO, pointers and arrays. CourseNana.COM

Some implementation details are purposefully left ambiguous; you have the freedom to decide on the specifics yourself. Additionally this description does not define all possible behaviour that can be exhibited by the system; some error cases are not documented. You are expected to gracefully report and handle these errors yourself. CourseNana.COM

The Architecture CourseNana.COM

In this assignment you will be emulating an 8 bit architecture. The memory model of this architecture consists of: CourseNana.COM

• RAM - Contains 28 addresses of 1 byte each
• Register Bank -
8 registers of 1 byte each
• Program Code - Memory required to store the program to be executed.
CourseNana.COM

For full marks the total size on disk of your program’s binary should not exceed 10kb. CourseNana.COM

During execution you should not store any information about the state of the machine outside of the RAM and the register bank. CourseNana.COM

Note: A register stores a single value using a fixed bit width. It the size of a register corresponding to the processor word size, in this case 8 bits. Think of them as a primitive variable. Physical processor hardware is constrained, and the number of registers is always fixed. There are registers which serve specific purposes, and those which are general. Please identify these in the description and consider them for your solution. You need not consider special purpose registers, such as floating point, in this assignment. CourseNana.COM

Program Code: x2017 CourseNana.COM

Our virtual machine will be operating on a home brewed ‘x2017’ assembly language. You will be provided with binaries in this language to run on your virtual machine. Each operation within ‘x2017’ contains an operation specifier code (op code) and takes zero, one or two arguments. Arguments are expressed as one of four different types, while operation codes are selected from a table. The arguments of each function precede the opcode and are expressed as follows: CourseNana.COM

([Second Value][Second Type])([First Value][First Type])[Operation Code] A collection of these operations will form a function. CourseNana.COM

The type is a two bit field and specifies the type of the preceding value. CourseNana.COM

  1. 00  - value: 1 byte long. The value in the preceding 8 bits should be interpreted as a single byte value.
  2. 01  - register address: 3 bits long. This address refers to one of the eight fixed registers
  1. 10  - stack symbol: 5 bits long. This refers to a particular symbol within the current stack frame.
  2. 11  - pointer valued: 5 bits long. This treats the contents of the address referred to by a particu- lar symbol within the current stack frame as a variable. Pointers may reference variables on different stack frames.

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

A stack symbol is a value that is associated with an address on the stack; it is up to you to find a cogent method of allocating stack space to symbols. Symbols only exist within the scope of the current function; should two functions use the same symbol then they are not referencing the same region of memory. CourseNana.COM

While the exact memory layout within the stack frame is open to interpretation, four registers are reserved for special values. CourseNana.COM

·      0x07 Stores the program counter CourseNana.COM

·      0x06 Will not be referenced by the program; this register exists for your personal use. CourseNana.COM

·      0x05 Will not be referenced by the program; this register exists for your personal use. CourseNana.COM

·      0x04 Will not be referenced by the program; this register exists for your personal use. CourseNana.COM

Registers in the range 0x00-0x03 are general purpose registers and may be explicitly referenced by a program. CourseNana.COM

The opcodes associated with ‘x2017’ instructions are detailed below. You will need to read each of the op-codes and implement the operation on the memory specified. CourseNana.COM

Opcodes: CourseNana.COM

  1. 000  - [MOV A B] - Copies the value at some point B in memory to another point A in memory

(register or stack). The destination may not be value typed. CourseNana.COM

  1. 001  - [CAL A] - Calls another function the first argument is a single byte (using the VALUE type) containing the label of the calling function.
  1. 010  - [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. If this function is the entry-point, then the program terminates.
  2. 011  - [REF A B] - Takes a stack symbol B and stores its corresponding stack address in A.
  1. 100  -[ADDAB]-TakestworegisteraddressesandADDstheirvalues,storingtheresultinthefirst

listed register. CourseNana.COM

  1. 101  - [PRINT A] - Takes any address type and prints the contents to a new line of standard output as an unsigned integer.
  1. 110  - [NOT A] - Takes a register address and performs a bitwise not operation on the value at that address. The result is stored in the same register
  2. 111  - [EQU A] - Takes a register address and tests if it equals zero. The value in the register will be set to 1 if it is 0, or 0 if it is not. The result is stored in the same register.

The state of the registers is preserved between CAL and RET operations. CourseNana.COM

In the event that the execution of this program enters an undefined state; for example if the amount of stack memory required to execute the program exceeds the RAM buffer, then you should print an appropriate error to standard error and return 1 on exiting main. CourseNana.COM

  CourseNana.COM

The value of the program counter register should reference the current opcode. Your program should increment the program counter before executing the associated instruction. You may wish to consider what may happen when the program counter is modified during the execution of an instruction. CourseNana.COM

Binary File Format: CourseNana.COM

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

The file is broken up into a number of functions. Each function is defined with a three bit header dictating the ’label’ of the function and the number of arguments, and a five bit tail specifying the number of instructions in the function. The function with the label 0 is the entry point and should be executed first. CourseNana.COM

[Padding bits]
[
function label (3 bits)]
CourseNana.COM

[OPCODE]
[
OPCODE]
...
[RET]
[
Number of instructions (5 bits)]
CourseNana.COM

[function label (3 bits)] [OPCODE] CourseNana.COM

[OPCODE]
...
[RET]
[
Number of instructions (5 bits)]
CourseNana.COM

Example CourseNana.COM

The following assembly function moves the values 3 and 5 to separate registers before adding them, moving the value to the stack and returning. CourseNana.COM

Some equivalent C code might look like this: CourseNana.COM

#define BYTE unsigned char // Because all values are 1 byte void main()
{
CourseNana.COM

register BYTE reg_0 = 3; // Storing the value 3 at register 1 register BYTE reg_1 = 5; // Storing the value 5 at register 2 CourseNana.COM

reg_0 += reg_1; // ADD The two registers, save the value at r1 CourseNana.COM

BYTE A = reg_0; // Store the value from register 1 at stack symbol A CourseNana.COM

return; // Return } CourseNana.COM

We can consider some equivalent x2017 assembly: CourseNana.COM

FUNC LABEL 0
    MOV REG 0 VAL 3
    MOV REG 1 VAL 5
    ADD REG 0 REG 0
    MOV STK A REG 0
    RET

  CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
COMP2017代写,System Programming代写,C代写,University of Sydney代写,COMP9017代写,COMP2017代编,System Programming代编,C代编,University of Sydney代编,COMP9017代编,COMP2017代考,System Programming代考,C代考,University of Sydney代考,COMP9017代考,COMP2017help,System Programminghelp,Chelp,University of Sydneyhelp,COMP9017help,COMP2017作业代写,System Programming作业代写,C作业代写,University of Sydney作业代写,COMP9017作业代写,COMP2017编程代写,System Programming编程代写,C编程代写,University of Sydney编程代写,COMP9017编程代写,COMP2017programming help,System Programmingprogramming help,Cprogramming help,University of Sydneyprogramming help,COMP9017programming help,COMP2017assignment help,System Programmingassignment help,Cassignment help,University of Sydneyassignment help,COMP9017assignment help,COMP2017solution,System Programmingsolution,Csolution,University of Sydneysolution,COMP9017solution,