Copyright © XXXXXXXXXXJonathan Muckell, Ph.D. All rights reserved. Document cannot be distributed without written consent by the author. Homework #4: Mini-Compiler (Part #1 of 2) ECE233 – The HW/SW...

1 answer below »
Please check .tar file for the C code needed to complete the assignment.


Copyright © 2022. Jonathan Muckell, Ph.D. All rights reserved. Document cannot be distributed without written consent by the author. Homework #4: Mini-Compiler (Part #1 of 2) ECE233 – The HW/SW Interface Prof. Muckell Background: To understand the hardware/software interface, it is crucial to understand how higher-level programming code source code is converted into assembly language instructions. In this assignment, you will implement a small compiler that converts a simple fake programming language (that we’ll call MUCKS) into ARM assembly language instructions. Academic Integrity: Your submission must represent your own work. See course honor pledge for course policies and details. Download Code Template: To allow you to focus on the core functionality of this assignment, some code has been written for you. The existing code prompts the user for a filename. This file contains the MUCKS source code that we want to compile. Three sample test files have been provided for you. The code provided reads each line of the test file, tokenizes it, and populations an Instruction structure. Each token contains either a variable name, number or operations. Code Template: Homework Starter Code (Download from Blackboard) Extract Tar Ball Archive Command: tar -xvf hw4.tar Sample Execution of Provided Code Template: Access to the C Environment: Your code will be tested using the compiler on this environment. Submissions that do not compile on this environment (by using your make file) will not receive any credit. Access the details for logging into the course Linux Server on Blackboard. NEXT PAGE → Copyright © 2022. Jonathan Muckell, Ph.D. All rights reserved. Document cannot be distributed without written consent by the author. Code Organization: Organized and readable code is an important part of the software development process. If your code is hard to read, you will have trouble debugging issues, and (in an industry setting) annoy your coworkers. To help you get into good habits, your code must be properly formatted and commented to receive full credit. • Formatting: Proper use of indentation. Each code block should be properly indented. • Comments: Use comments to describe specific portions of your code (not every line). Make sure your name is included in the comments at the top of the program (see example below) Make sure to implement your code following proper design principles including: • Multiple Files: Your program must have a minimum of three source files (main.c, parser.c, compiler.c), and two header files (parser.c, compiler.h). The only function in the main.c file should be the main function, all other functions should be broken out into other source files. • Makefile: Your code should also include a properly built Makefile. Typing the word “make” should correctly compile your program. Typing “make clean” should remove any temporary files created when compiling the program (such as object files and the executable). Submission Instructions: • TEST YOUR SUBMISSION! You will only be able to submit once on Blackboard. • Submit your assignment as a tar ball on Blackboard. Name your tar ball archive with your netID (ex. ab123123.tar) o Creating a tar ball Example: tar -cvf ab123123.tar hw4/ • Test your tar ball by copying it to another folder and extract it using the command below o Extracting tar ball example: tar -xvf ab123123.tar • If you submitted it correctly, the only thing we need to do is extract the tarball, type make to compile your program, and run it using ./hw4 • You will need to create your own make file for this assignment. It has not been provided for you. Your make file should contain a clean operation that removes everything except the makefile, source/header files, and test files. • Your program must compile and run on the ECE233 Linux Server to receive credit MUCKS Programming Language Syntax MUCKS is a fake programming language that only supports extremely basic language with the following characteristics: • Basic Operations: Only three operations (=, +, -) are supported • Each instruction must be a on a separate line (no ; to separate instructions) • Variables must be one lowercase character a through z • Parentheses are not permitted. • The test files require a single blank line at the end of the test file. Your Task Convert the MUCKS source code read from a file into its equivalent ARM assembly language representation. Your code should generate valid ARM output. The output ARM code from your program should be executable (testable) in visUAL ARM emulator. Your mini-compiler only needs to support the following ARM instructions: MOV, ADD and SUB. To build this program incrementally, we are first going to define a data structure that keeps track of which MUCKS variables are mapped to which ARM registers. https://youtu.be/bHA_pavoVG8 https://youtu.be/W-QgOChAnAQ Copyright © 2022. Jonathan Muckell, Ph.D. All rights reserved. Document cannot be distributed without written consent by the author. Data Structure Define a data structure with global scope that maps MUCKS variables to ARM registers. Data Structure Operations (Functions) o void initialize() ▪ Action: Initializes the data structure such to indicate that all registers are available to be used by any valid variable o int getRegister(char var) ▪ Action: Search the data structure, if var is already mapped to a register, return the number of that register. If not found, return -1 ▪ Input: A MUCKS variable (e.g., {‘a’, ‘b’, … ‘x’, ‘y’, ‘z’} ) ▪ Output: The register in which it maps too {1 – 31}. o int assignRegister(char var) ▪ Action: Calls getRegister first, if var not currently assigned to a register, assign a free one and return the register number. ▪ Input: A MUCKS variable (e.g., {‘a’, ‘b’, … ‘x’, ‘y’, ‘z’} ) ▪ Output: The register in which it maps too {1 – 31}. Also include one additional function isNumber that will be extremely helpful in writing your program. o bool isNumber(char* value) ▪ Action: Checks if value is a number (all character 0 – 9). If number return true, otherwise, return false ▪ Input: A string that might be a number or alphanumeric ▪ Output: true if all characters are numeric, otherwise false. Sample Output / Test Files Two MUCKS test files have been included in your code template. Below are example outputs generated when running each of the provided test files. Your output doesn’t need to match the example output, but the result should be the sample. We’ll test your output by running it in the visUAL ARM emulator and determining if the functionality is equivalent to the MUCKs representation. TEST FILE #1 (test1.mucks) Using the data structure and operations above, the following input (MUCKS code) should generate the following output and result in x and y variables being mapped to two different registers (such as R3 and R4). MUCKS Code Generated ARM Output (Example) RESULT: At the end of the execution x=56, y=14 After executing your output ARM code in the visUAL ARM emulator, there should be two registers with those values Copyright © 2022. Jonathan Muckell, Ph.D. All rights reserved. Document cannot be distributed without written consent by the author. TEST FILE #2 (test2.mucks) MUCKS Code Generated ARM Output (Example) TEST FILE #3 (test3.mucks) MUCKS Code Generated ARM Output (Example)
Answered 1 days AfterMar 23, 2022

Answer To: Copyright © XXXXXXXXXXJonathan Muckell, Ph.D. All rights reserved. Document cannot be distributed...

Nidhi answered on Mar 25 2022
105 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here