1. Homepage
  2. Homework
  3. CS 2506 Computer Organization II - C02: Parsing MIPS32 Assembly Instructions
This question has been solved

CS 2506 Computer Organization II - C02: Parsing MIPS32 Assembly Instructions

Engage in a Conversation
USVirginia TechCS 2506Computer Organization IIParsing MIPS32 Assembly InstructionsCAssembly

MIPS Assembly Instructions Parser CourseNana.COM

  CourseNana.COM

For this assignment, you will implement a C function that parses a restricted subset of MIPS assembly instructions and prints out information relevant to translating those instructions into machine code. In particular, you will be concerned with MIPS assembly instructions, expressed in one of the following forms: CourseNana.COM

  CourseNana.COM

R-format: mnemonic reg1, reg2, reg3 (mul, sub, add) CourseNana.COM

I-format: mnemonic reg1, reg2, immediate (addi, beq) CourseNana.COM

mnemonic reg1, immediate (lui) CourseNana.COM

mnemonic reg1, offset(reg2) (lw, sw) CourseNana.COM

where mnemonic is one of the following MIPS32 mnemonics: CourseNana.COM

add addi mul beq lui lw sw sub CourseNana.COM

and reg1, reg2 and reg3 are each one of the following MIPS registers: CourseNana.COM

$t0, $t1, $t2, $t3, $s0, $s1, $s2, $s3 CourseNana.COM

  CourseNana.COM

and immediate and offset are integers in the range -32768 to 32767. The elements of each instruction are separated by whitespace and commas, as shown. Whitespace can be any mixture of spaces and tab characters. CourseNana.COM


CourseNana.COM


CourseNana.COM

The instructions you are concerned with in this assignment can be classified as shown above; but lui, lw, sw break the ideal format rules the MIPS designers proposed for the instruction set architecture. You should consult the MIPS32 Architecture Volume 2: the MIPS32 Instruction Set, which is available on the course resources page CourseNana.COM

on Canvas for details of the machine language representations of these instructions. They can be viewed as illustrating the notion that a good design often requires (hopefully good) compromises from the pure design goals you might start with. CourseNana.COM

  CourseNana.COM

In order to decide how to interpret an assembly instruction, we would need to know exactly which assembly instruction we are dealing with, since different assembly instructions follow different patterns. For example, if the mnemonic is add, we have an R-format machine instruction, and we know that the instruction has three parameters CourseNana.COM

that are all register names. CourseNana.COM

  CourseNana.COM

How do we know these things? From consulting the available MIPS32 references, chiefly the MIPS32 Architecture Volume 2: the MIPS32 Instruction Set, which is available on the course resources page on Canvas. From there, we find that add is an R-format instruction, and that the add assembly instruction CourseNana.COM

always has the form: CourseNana.COM


CourseNana.COM

add $rd, $rs, $rt CourseNana.COM


CourseNana.COM

We also find that executing this instruction results in the assignment: $rd =$rs + $rt. Moreover, we find that this is expressed in binary machine format as: CourseNana.COM

  CourseNana.COM

R CourseNana.COM

31 30 29 28 27 26 CourseNana.COM

25 24 23 22 21 CourseNana.COM

20 19 18 17 16 CourseNana.COM

15 14 13 12 11 CourseNana.COM

10 9 8 7 6 CourseNana.COM

5 4 3 2 1 0 CourseNana.COM

0 0 0 0 0 0 rs rt rd 0 0 0 0 0 1 0 0 0 0 0 CourseNana.COM

  CourseNana.COM

We also find, from other MIPS32 references, how the symbolic register names map to integer register numbers, so if we are given a specific instance of the add assembly instruction, we can determine all the components of the binary CourseNana.COM

representation. CourseNana.COM

  CourseNana.COM

A later assignment will require you to implement a C program that translates complete MIPS32 assembly programs CourseNana.COM

into machine code. For now, we will focus on the narrower problem of determining the pieces that make up the representations of a small selection of assembly instructions. CourseNana.COM

  CourseNana.COM

This assignment is, in some ways, a warm-up for the assembler project. Therefore, if you give careful thought to your design, you can produce lots of C code that can be plugged into the assembler. And, if you choose to do this in minimalist fashion, you'll gain little or nothing towards implementing the assembler. CourseNana.COM

  CourseNana.COM

Given one of the MIPS32 assembly instructions mentioned earlier, you will create a C struct variable that contains CourseNana.COM

information relevant to the specific assembly instruction and its representation in machine code. We will use the following user-defined C type to represent your analysis of the given instruction: CourseNana.COM

/** Represents the possible field values for a MIPS32 machine instruction. CourseNana.COM

* CourseNana.COM

* A ParseResult object is said to be proper iff: CourseNana.COM

* CourseNana.COM

*/ CourseNana.COM

struct _ParseResult { CourseNana.COM

// Each char* member will be NULL or point to dynamically-allocated char array CourseNana.COM

// holding a zero-terminated C string. CourseNana.COM

// The assembly code portion CourseNana.COM

char* ASMInstruction; // the assembly instruction, as a C-string CourseNana.COM

char* Mnemonic; // the symbolic name of the instruction CourseNana.COM

char* rdName; // the symbolic names of the registers, as C-strings; CourseNana.COM

char* rsName; // NULL if the register field is not specified CourseNana.COM

char* rtName; // in the assembly instruction CourseNana.COM

// The following are integer values CourseNana.COM

int16_t Imm; // the immediate field, as a signed integer; CourseNana.COM

// 0 if not relevant for the assembly instruction CourseNana.COM

uint8_t rd; // the three register fields, as small unsigned integers; CourseNana.COM

uint8_t rs; // 255 if not relevant for the assembly instruction CourseNana.COM

uint8_t rt; CourseNana.COM

}; CourseNana.COM

This type includes every possible component related to any of the assembly instructions in which we are interested. CourseNana.COM

However, no particular MIPS32 assembly instruction actually has all of the possible components defined in this type, so we will stipulate that are unused will be set to default values, given in the comments above. CourseNana.COM

  CourseNana.COM

For example, suppose you have the assembly instruction: add $s3, $t1, $t0 CourseNana.COM

The corresponding ParseResult object should contain the following information, parsed directly from the given CourseNana.COM

instruction: CourseNana.COM

ASMInstruction --> "add $s3, $t1, $t0" CourseNana.COM

Mnemonic --> "add" CourseNana.COM

rdName --> "$s3" CourseNana.COM

rsName --> "$t1" CourseNana.COM

rtName --> "$t0" CourseNana.COM

The following information can be obtained from properly-constructed static lookup tables: CourseNana.COM

rd == 19 CourseNana.COM

rs == 9 CourseNana.COM

rt == 8 CourseNana.COM

Opcode --> "000000" CourseNana.COM

Funct --> "100000" CourseNana.COM

  CourseNana.COM

Imm == 0 CourseNana.COM

IMM == NULL CourseNana.COM

Given the assembly instruction "addi $t0, $s2, -42" , we find it has the form: CourseNana.COM

addi $rt, $rs, immediate CourseNana.COM

  CourseNana.COM

Coding Requirements CourseNana.COM

You will implement the following C function: CourseNana.COM

  CourseNana.COM

ParseResult* parseASM(const char* const pASM); CourseNana.COM

  CourseNana.COM

The stated precondition will be satisfied whenever the testing code calls your implementation. Your implementation must satisfy the stated return specification and must not violate const or create memory violations of any kind. CourseNana.COM

  CourseNana.COM

You are required1 to implement static lookup tables and use them to determine instruction opcodes from mnemonics, and to map register numbers to register names. See the discussion of static lookup tables later in this specification. CourseNana.COM

  CourseNana.COM

void clearResult(ParseResult* const pPR); CourseNana.COM

  CourseNana.COM

The test harness will call clearResult() at appropriate times during testing. If you have correctly implemented the CourseNana.COM

function, and otherwise coded your solution correctly, tests run on valgrind will not indicate any memory leaks. CourseNana.COM

We will require1 your solution to achieve a "clean" run on valgrind. See the discussion of Valgrind below. CourseNana.COM

Finally, this is not a requirement, but you are strongly advised to use calloc() when you allocate dynamically, rather CourseNana.COM

than malloc(). This will guarantee your dynamically-allocated memory is zeroed when it's allocated, and that may help prevent certain errors. CourseNana.COM

  CourseNana.COM

Static Lookup Tables in C CourseNana.COM

Consider implementing a program that will organize and support searches of a fixed collection of data records. For CourseNana.COM

example, if the data records involve geographic features, we might employ a struct type: CourseNana.COM

// GData.h CourseNana.COM

enum _FeatureType {CITY, RIVER, MOUNTAIN, BUILDING, . . . , ISLAND}; CourseNana.COM

typedef enum _FeatureType FeatureType; CourseNana.COM

... CourseNana.COM

struct _GData { CourseNana.COM

char* Name; CourseNana.COM

char* State; CourseNana.COM

... CourseNana.COM

FeatureType FType; CourseNana.COM

uint16_t Elevation; CourseNana.COM

}; CourseNana.COM

typedef struct _GData GData; CourseNana.COM

... CourseNana.COM

We might then initialize an array of GData objects by taking advantage of the ability to initialize struct variables at the CourseNana.COM

point they are declared: CourseNana.COM

// GData.c CourseNana.COM

#define NUMRECORDS 50 CourseNana.COM

static GData GISTable[NUMRECORDS] = { CourseNana.COM

{"New York", "NY", ..., CITY, 33}, CourseNana.COM

{"Pikes Peak", "CO", ..., MOUNTAIN, 14115}, CourseNana.COM

... CourseNana.COM

{"McBryde Hall", "VA", ..., BUILDING, 2080} CourseNana.COM

}; CourseNana.COM

  CourseNana.COM

Memory Management Requirements and Valgrind CourseNana.COM

Valgrind is a tool for detecting certain memory-related errors, including out of bounds accessed to dynamically-allocated CourseNana.COM

arrays and memory leaks (failure to deallocate memory that was allocated dynamically). A short introduction to Valgrind is CourseNana.COM

posted on the Resources page, and an extensive manual is available at the Valgrind project site (www.valgrind.org). CourseNana.COM

For best results, you should compile your C program with a debugging switch (-g or –ggdb3); this allows Valgrind to CourseNana.COM

provide more precise information about the sources of errors it detects. For example, we ran our solution for this project, with CourseNana.COM

one of the test cases, on Valgrind: CourseNana.COM

[dsn@centosvm parseMI]$ valgrind --leak-check=full --show-leak-kinds=all --log-file=vlog.txt CourseNana.COM

--track-origins=yes -v driver instr.txt parse.txt –rand CourseNana.COM

And, we got good news... there were no detected memory-related issues with my code: CourseNana.COM

==10669== Memcheck, a memory error detector CourseNana.COM

==10669== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. CourseNana.COM

==10669== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info CourseNana.COM

==10669== Command: driver instr.txt parse.txt -rand CourseNana.COM

==10669== CourseNana.COM

==10669== HEAP SUMMARY: CourseNana.COM

==10669== in use at exit: 0 bytes in 0 blocks CourseNana.COM

==10669== total heap usage: 275 allocs, 275 frees, 6,904 bytes allocated CourseNana.COM

==10669== CourseNana.COM

==10669== All heap blocks were freed -- no leaks are possible CourseNana.COM

==10669== CourseNana.COM

==10669== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2) CourseNana.COM

==10669== CourseNana.COM

==10669== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2) CourseNana.COM

And, we got good news... there were no detected memory-related issues with my code. That's the sort of result you want CourseNana.COM

to see when you try your solution with Valgrind. CourseNana.COM

On the other hand, here’s what we got from a student submission: CourseNana.COM

==8596== Memcheck, a memory error detector CourseNana.COM

==8596== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. CourseNana.COM

==8596== Using Valgrind-3.14.0-353a3587bb-20181007X and LibVEX; rerun with -h for copyright info CourseNana.COM

==8596== Command: c02driver tests.txt results.txt -rand CourseNana.COM

==8596== Parent PID: 8595 CourseNana.COM

Testing and Grading CourseNana.COM

Download the posted tar file, c02Files.tar from the course website and unpack it on a CentOS 8 system. You should CourseNana.COM

receive the following files, organized in two subdirectories: CourseNana.COM

README - usage instructions CourseNana.COM

dev: CourseNana.COM

c02driver.c - test driver CourseNana.COM

ASMParser.h - "public" interface for parser; do not modify! CourseNana.COM

ASMParser.c - implement the functions here, as needed CourseNana.COM

ParseResult.h - "public" interface for results type; do not modify! CourseNana.COM

ParseResult.c - implement the functions here, as needed CourseNana.COM

Grader.h - declaration for grading function CourseNana.COM

Grader.o - 64-bit CentOS binary for grading function CourseNana.COM

Generate.h - declaration for test data generator CourseNana.COM

Generate.o - 64-bit CentOS binary for test data generator CourseNana.COM

grading: CourseNana.COM

gradeC02.sh - this script file CourseNana.COM

c02Grader.tar - grading code, including: CourseNana.COM

c02driver.c - test driver CourseNana.COM

ASMParser.h - supplied C header file CourseNana.COM

ParseResult.h - supplied C header file CourseNana.COM

Grader.h - declaration for grading function CourseNana.COM

Grader.o - 64-bit CentOS binary for grading function CourseNana.COM

  CourseNana.COM

What to submit CourseNana.COM

  CourseNana.COM

You will submit an uncompressed tar file containing your completed C implementation files (ASMParser.c and CourseNana.COM

ParseResult.c and any supporting .c and .h files you have written), and nothing else. Do not include any of the CourseNana.COM

supplied files from C02Grader.tar (see above), object files, or executable files. CourseNana.COM

  CourseNana.COM

We will grade your submission with the posted test/grading harness, and we will make no allowances for submissions that do not operate correctly with that. Be warned: we will use the original, posted versions of the header and .o files in grading your submission, so you may encounter problems if you’ve modified any of those. CourseNana.COM

Make your submission to Canvas. Late submissions will be assessed a penalty of 10% per diem. CourseNana.COM

  CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
US代写,Virginia Tech代写,CS 2506代写,Computer Organization II代写,Parsing MIPS32 Assembly Instructions代写,C代写,Assembly代写,US代编,Virginia Tech代编,CS 2506代编,Computer Organization II代编,Parsing MIPS32 Assembly Instructions代编,C代编,Assembly代编,US代考,Virginia Tech代考,CS 2506代考,Computer Organization II代考,Parsing MIPS32 Assembly Instructions代考,C代考,Assembly代考,UShelp,Virginia Techhelp,CS 2506help,Computer Organization IIhelp,Parsing MIPS32 Assembly Instructionshelp,Chelp,Assemblyhelp,US作业代写,Virginia Tech作业代写,CS 2506作业代写,Computer Organization II作业代写,Parsing MIPS32 Assembly Instructions作业代写,C作业代写,Assembly作业代写,US编程代写,Virginia Tech编程代写,CS 2506编程代写,Computer Organization II编程代写,Parsing MIPS32 Assembly Instructions编程代写,C编程代写,Assembly编程代写,USprogramming help,Virginia Techprogramming help,CS 2506programming help,Computer Organization IIprogramming help,Parsing MIPS32 Assembly Instructionsprogramming help,Cprogramming help,Assemblyprogramming help,USassignment help,Virginia Techassignment help,CS 2506assignment help,Computer Organization IIassignment help,Parsing MIPS32 Assembly Instructionsassignment help,Cassignment help,Assemblyassignment help,USsolution,Virginia Techsolution,CS 2506solution,Computer Organization IIsolution,Parsing MIPS32 Assembly Instructionssolution,Csolution,Assemblysolution,