CS 245 Fall 2020 Assignment 2 & 3 – Processing MARIE Instructions (in MIPS) For all assignments, be sure to: · Include file comments at the top, listing your name, the name of the program, and briefly...

I'm just working on homework 2, not 3


CS 245 Fall 2020 Assignment 2 & 3 – Processing MARIE Instructions (in MIPS) For all assignments, be sure to: · Include file comments at the top, listing your name, the name of the program, and briefly describe what the program does. · In your file comments also describe the register convention, and calling sequence for any procedures (assign 3). The register convention lists how you are using your $s registers. · Line up instruction parts in columns: 0=labels; 1tab=instruction mnemonic; 2tabs=operands; 3-4tabs=comments. · Include pseudo-code comments to the right of your assembly code. Avoid comments that tell me what the assembly does, such as: move 25 to register $s3 – I already know this. Keep your comments to the logic. We are getting into longer programs now, and you will need to see your logic. Program 2: Printing and Processing a MARIE Instruction MIPS, with its 32 registers, is a Rolls Royce of processors and would normally be used in more sophisticated systems. MARIE, introduced in the book, is an extremely simple computer with a single register: the accumulator. It may be used in a very simple device, such as a watch or digital toaster. MARIE is described in a book in section 4.8.3 (Fifth Edition). Each instruction is a halfword large, as shown in this diagram: Opcode Bits 15-12 Address Bits 11-0 The opcodes are defined as follows: 1 Load X Accum = Memory[X] 2 Store X Memory[X] = Accum 3 Add X Accum += Memory[X] 4 Subt X Accum -= Memory[X] 5 Input System.input.integer(Accum) 6 Output System.output.integer(Accum) 7 Halt System.exit() 8 Skipcond System.output.integer(Address[bits 11-10]) (Next assignment will do full instruction) 9 Jump X PC = MainM[X] Build on your program 1 to complete this program. Create an array Memory that is 20 words large. You will be interpreting and executing a MARIE program using the MIPS programming language. Process all opcodes except 8 (Skipcond) for homework 2. Your job is to: 1. Parse the two fields: opcode and address. Interpret the instruction. For example, the instruction can be interpreted as follows: MARIE instruction Decoded 0x1000 Load 0x000 0x3001 Add 0x001 0x2002 Store 0x002 0x6000 Output Accum 0x9001 Jump MainM[1] 2. Create the array of instructions and your memory. This can be done as follows: MainM: .half 0x1000, 0x3001, 0x2002, 0x6000, 0x9001, 0x7000 Memory: .half 5, 10, 0 PC: .word 0 # index or address pointing into MainM 3. Interpret the Instructions. Assuming the three instructions above are executed, and Memory has contents: 5,10,0, then your program output might be: Instruction = Load 0x000 Accum = 5 Instruction = Add 0x001 Accum = 15 Instruction = Store 0x002 Memory[002] = 15 Instruction = Output Accum Output = 15 Instruction = Jump MainM[1] Instruction = Add 0x001 Accum = 25 4. As you iterate through the instructions, keep track of the next instruction in the PC variable. Hints: To process through the machine code (binary) instructions, keep the next instruction to be executed (address or index within MainM) in the PC variable. PC stands for Program Counter, and always points to the next instruction. When you Jump, you are actually setting the PC to MainM + Jump’s Address field. There is some beginning logic at the end of this file. These are just sample instructions. I will be testing with another program and will expect it to work. Submission Turn this program in as hwk2.asm via electronic copy to Canvas. Grading Each homework assignment is worth 30 points. Be careful to include all comments and format correctly, as directed in the beginning of this file. Program 3: Extending the MARIE Interpreter In this assignment you will take your program 2 and implement procedures with it. Then you will extend your program to perform the Skip-conditional instruction. This assignment will require that you properly use: · Procedure calls and stacks; · Logic: loops, shifts, ands, advanced logic; · Documentation: Documenting stack and register usage, and pseudo-code use. You will be graded on each of these. Please start using your Homework 2 code. Add at a minimum the following procedures: AccPr or AccumPrint: This is modified from your previous main. It prints the decimal value of the accumulator. Pass one parameter on the stack: the number to print in hexadecimal. Please create other procedures where you pass arguments in the $a registers. For example, your Main might simply determine which procedure to call based on opcode: add(), load(), store(), … The Skip instruction does the following logic: Skipvar = address >> 10 # isolates bits 11-10 If (Skipvar == 0 && Accum<0) pc="" +="1;" if="" (skipvar="=1" &&="" accum="0)" pc+="1;" if="" (skipvar="=2" &&="" accum="">0) PC+=1; Example code might be: MainB: # do Load 001 # Accum=Value Output # System.output(Accum) Subtract 002 # Accum-- Skip 0x400 # while Accum !=0 Jump 0x000 Halt # exit Submission Turn this program in as hwk3.asm via electronic copy to Canvas. Grading Each homework assignment is worth 30 points. Be careful to include all header and logic comments and format correctly, as directed in the beginning of this file. Program Extra Credit: Programming in MARIE Code Program 1B in MARIE. Code the program in your Homework 3 and submit. This program is worth 15 points when perfectly done. (Can’t print text) Basic Logic for MARIE Simulator PC = (MainM) // Program counter = next instruction to be executed Do { // Process each instruction in order Instruction = (PC) // get the instruction PC += 2 // increment address to point to next instruction Opcode = instruction[bits 12-15] Immediate = instruction[bits 0-11] Switch (opcode) Case 1: // Load from address in memory Accum = (Memory+immediate); break; Case 2: // Store to address in memory (Memory+immediate) = Accum; break; … Case 8: // Skip Conditional Bits= immediate >> 10 // shift right 10 If (bits == 0x0 && Accum <0) pc="PC" +="" 2="" if="" (immediate="=" 0x1="" &&="" accum="=" 0)="" pc="PC" +2="" if="" (immediate="=" 0x2="" &&="" accum=""> 0) PC = PC + 2 … } // enddo
Nov 01, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here