CDA3101 Project 1: MIPS Assembler Due 2/5. I. Purpose

Similar documents
CDA 3101: Summer 2018 Project 2 - Pipeline Simulator

Problem maximum score 1 35pts 2 22pts 3 23pts 4 15pts Total 95pts

Your submitted proj3.c must compile and run on linprog as in the following example:

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

Lecture 4: MIPS Instruction Set

Your submitted proj3.c must compile and run on linprog as in the following example:

ECE 30 Introduction to Computer Engineering

- b: size of block in bytes. - s: number of sets in the cache (or total number of sets between split caches). - n: associativity of cache.

MIPS Assembly: More about Memory and Instructions CS 64: Computer Organization and Design Logic Lecture #7

MIPS Coding Continued

8*4 + 4 = 36 each int is 4 bytes

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

MACHINE LANGUAGE. To work with the machine, we need a translator.

MIPS%Assembly% E155%

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

Unsigned Binary Integers

Unsigned Binary Integers

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College

Chapter 2. Instruction Set Architecture (ISA)

CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Formats

Today s topics. MIPS operations and operands. MIPS arithmetic. CS/COE1541: Introduction to Computer Architecture. A Review of MIPS ISA.

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

Assembler. Lecture 8 CS301

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

University of California, Berkeley College of Engineering

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

CS 61c: Great Ideas in Computer Architecture

Lecture 5: Procedure Calls

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

3. (5 points) Name the 5 components of a computer

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

Midterm. CS64 Spring Midterm Exam

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: MIPS Programming

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

Review of Last Lecture. CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Representation II. Agenda. Dealing With Large Immediates

Lecture 9: Disassembly

Computer Organization MIPS ISA

University of California, Berkeley College of Engineering

CS3350B Computer Architecture MIPS Instruction Representation

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

ECE 15B COMPUTER ORGANIZATION

Lecture 7: Examples, MARS, Arithmetic

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

Part 1 (70% of grade for homework 2): MIPS Programming: Simulating a simple computer

Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Topic Notes: MIPS Instruction Set Architecture

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Chapter 2: Instructions:

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Sheet For the following C code: a = b + c; b = a + c; d = a b; Write an equivalent assembly MIPS program. Solution:

1 5. Addressing Modes COMP2611 Fall 2015 Instruction: Language of the Computer

Chapter 2. Instructions:

EEC 581 Computer Architecture Lecture 1 Review MIPS

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

Instructions: MIPS arithmetic. MIPS arithmetic. Chapter 3 : MIPS Downloaded from:

CS 351 Exam 2 Mon. 11/2/2015

CS61C - Machine Structures. Lecture 6 - Instruction Representation. September 15, 2000 David Patterson.

ECE232: Hardware Organization and Design

ECE 473 Computer Architecture and Organization Project: Design of a Five Stage Pipelined MIPS-like Processor Project Team TWO Objectives

We will study the MIPS assembly language as an exemplar of the concept.

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

MIPS (SPIM) Assembler Syntax

ECE260: Fundamentals of Computer Engineering

2) Using the same instruction set for the TinyProc2, convert the following hex values to assembly language: x0f

CS61C : Machine Structures

From Code to Program: CALL Con'nued (Linking, and Loading)

CS 61C: Great Ideas in Computer Architecture. MIPS Instruc,on Representa,on II. Dan Garcia

ECE260: Fundamentals of Computer Engineering

Instructions: Language of the Computer

MIPS Instruction Set Architecture (2)

Lectures 3-4: MIPS instructions

Instructions: Assembly Language

CS 2504 Intro Computer Organization Test 1

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

I-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits

Operands and Addressing Modes

CS2630: Computer Organization Project 1 MiniMa: (mini) assembler written in MIPS Due September 26, 2016, 11:59pm corrections in red

Chapter 3 MIPS Assembly Language. Ó1998 Morgan Kaufmann Publishers 1

CS61C : Machine Structures

Operands and Addressing Modes

Lecture 6 Decision + Shift + I/O

Computer Architecture

CS 110 Computer Architecture MIPS Instruction Formats

Field 6-Bit Op Code rs Field rt Field 16-bit Immediate field

CSSE232 Computer Architecture. Logic and Decision Opera:ons

1/26/2014. Previously. CSE 2021: Computer Organization. The Load/Store Family (1) Memory Organization. The Load/Store Family (2)

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

MIPS Assembly Programming

Instruction encoding. MIPS Instruction encoding

SPIM & MIPS Programming

Computer Architecture

CS 2506 Computer Organization II

Machine Instructions - II. Hwansoo Han

Mips Code Examples Peter Rounce

CS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Transcription:

CDA3101 Project 1: MIPS Assembler Due 2/5 I. Purpose The primary purpose of this project is to help cement the concepts of the MIPS instruction set and give you insight into how MIPS assembly programs are translated into machine code. The secondary purpose of this project is to give you some experience with C programming. II. Basic Description Your job is to create a program, contained in a single C file called proj1.c, which takes as input (from standard input) a small simplified MIPS assembly program and prints to standard output the corresponding machine code instructions and their associated addresses. Your submitted C program will be compiled and run on linprog with the following commands, where test.asm is an assembly file as described below. $ gcc proj1.c $./a.out < test.asm You should not rely on any special compilation flags or other input methods. If your program does not compile and execute as expected with the above commands, points will be deducted from your project grade. A sample executable (to be executed on linprog) is provided on the course website, as well as some test cases. Make use of the sample executable to help verify your output. The sample executable is not guaranteed to be bug-free and there is extra credit available for students who find any errors in the sample executable. Also, please be aware that passing all of the test cases does not guarantee a perfect score take the time to come up with your own additional test cases to verify that your program works in all scenarios. III. Assembly Input File You should be able to read and parse the contents of a simple MIPS assembly program, which will be redirected through standard input (i.e. do not try to open a file in your program). You can assume that every line of the program will contain either a directive or an instruction. No lines will be blank and a label will not appear on a line by itself. You may also assume that there are no more than 100 lines in an assembly file. Lines containing directives have the following format (where brackets indicate an optional element): [optional_label:]<tab>directive[<tab>operand]

Lines containing instructions have the following format: [optional_label:]<tab>instruction<tab>operands Operands are always comma-separated with no whitespace appearing between operands. The supported directives are listed in the following table. You may assume that the entire.text segment always precedes the.data segment. You may also assume that the memory allocation directives only ever have a single operand. Directive Meaning.data Indicates the start of the data section..text Indicates the start of the text section..space n Allocate n bytes of memory..word w Allocate a word in memory and initialize with w. The supported instructions include the following. You may wish to consult an additional MIPS reference page for more specific information about the instructions and their machine code formats. Instruction Type Opcode/Funct (decimal) Syntax ADD R 32 add $rd,$rs,$rt ADDI I 8 addi $rt,$rs,immed NOR R 39 nor $rd,$rs,$rt ORI I 13 ori $rt, $rs, immed SLL R 0 sll $rd, $rt, shamt LUI I 15 lui $rt, immed SW I 43 sw $rt,immed($rs) LW I 35 lw $rt,immed($rs) BNE I 5 bne $rs,$rt,label J J 2 j label LA - - la $rx,label The registers to be recognized include the following. Registers Decimal Representation $t0-$t7 8-15 $s0-$s7 16-23 $0 0 Registers will always be expressed as $[letter][number] or $0.

Note the use of labels in the branch and jump instructions. You will need to calculate the appropriate immediate and targaddr fields for the machine code based on the layout of your assembly file. Note an important detail here: typically pseudo-direct and PC-relative addressing are relative to PC+4, not PC. That is, for architectural reasons, we define these addressing modes with the address of the next instruction, not the address of the current instruction. Here, we will simply be using PC. The immediate field of a branch instruction will be defined using PC-relative addressing where the address of the destination is defined as Addr(dest) = Addr(branch) + immed*4 That is, the immediate field represents the distance, in instructions rather than bytes, between the branching instruction and the destination instruction. The targaddr field of the jump instruction will be defined using pseudo-direct addressing where the address of the destination is defined as Addr(dest) = Addr(jump)[31-28] targaddr 00 Where Addr(jump)[31-28] is the 4 most significant bits of the jump instruction, and denotes concatenation. Also note the use of the load address instruction. The load address instruction is a MIPS pseudoinstruction which is supported by many MIPS assemblers, but does not directly correspond to a MIPS instruction. Our assembler must replace any use of the load address instruction with a lui instruction, followed by an ori instruction. For example, la $t0,_a _a:.space 100 should be translated to lui $1,_a[31-16] ori $t0,$1,_a[15-0] _a:.space 100 Where _a[31-16] is the upper 16 bits of the address corresponding to label _a, and _a[15-0] is the lower 16 bits of the address corresponding to label _a, and $1 is the assembler temporary register $at (00001). Although this is not realistic, for consistency, we will zero-out all fields which are not welldefined for an instruction. These include the rs field for lui and sll as well as shamt for most R- type instructions.

IV. Suggested Development Approach Your assembler, just like a real assembler, will need to make two passes over the assembly file. During the first pass, the assembler should associate each symbolic label with an address. You may assume that the first instruction starts at address 0. You may also assume that memory allocations occur directly after the instructions in the process space. During the second pass, you should translate the symbolic assembly instructions into their corresponding machine code. You should print the address, followed by a space, and then the instruction. Both the address and the instruction should be in hexadecimal format and every instruction should appear on its own line. You may find the functions fgets and sscanf to be particularly useful for this assignment. The fgets function has the following prototype: char *fgets(char *str, int n, FILE *stream); The fgets function reads n characters from stream and writes them to the str buffer. On success, the function returns the same str parameter. If the end-of-file is encountered, a null pointer is returned. The sscanf function has the following prototype: int sscanf(const char *str, const char *format,...); The sscanf function scans the str buffer to try to match the format specifiers in the format string. Additional pointer arguments may be supplied to indicate variables that should be filled with elements found in the str buffer. You may need to consult some documentation to use these functions properly. Do not ask me what the format strings should look like this is part of the assignment! You must be able to read the documentation on these functions and figure out how to use them if you choose to do so. You may also want to make use of some bitwise operators (&,, << and >>) or the union construct to manage the instruction fields easily. There is no need to translate decimal values of the instruction fields into binary manually they are already represented as binary numbers in memory! Also, watch out for signed-ness. Lastly, no error checking is required. You may assume that the assembly input will be correctly formed. V. Sample Output A sample executable is provided, but here is quick run-through. Let s assume the test case test2.asm contains the following:

.text main: la $s0,_a lw $t6,0($s0) addi $t7,$t6,1 sw $t7,0($s0).data _a:.space 4 Then running the sample executable with test2.asm as input yields the following output. >./proj1_linprog < tests/test2.asm 0x000000: 0x3C010000 0x000004: 0x34300014 0x000008: 0x8E0E0000 0x00000C: 0x21CF0001 0x000010: 0xAE0F0000 VI. Miscellaneous Submissions may be made through Blackboard in the Assignments section. You must submit before 11:59 PM on February 5 to receive full credit. Late submissions will be accepted for 10% off each day they are late, for up to two days. The first person to report any errors in the provided materials will be given 5% extra credit. Automatic plagiarism detection software will be used on all submissions any cases detected will result in a grade of 0 for those involved.