This document provides instructions for an assignment in ECEN 350 (Summer 2011) involving translating between machine code and assembly language. Students are asked to:
1) Analyze three instructions and determine their type, translate to assembly, and show branch offsets.
2) Translate a C code snippet to MIPS assembly, filling in blanks.
3) Convert machine code to MIPS assembly instructions using register names.
4) Convert a beq instruction to machine code.
5) Determine register values after running code on little-endian and big-endian systems.
6) Translate a C function to MIPS assembly, filling in blanks.
7) Indicate whether statements about MIPS are true or false
This document provides instructions for an assignment in ECEN 350 (Summer 2011) involving translating between machine code and assembly language. Students are asked to:
1) Analyze three instructions and determine their type, translate to assembly, and show branch offsets.
2) Translate a C code snippet to MIPS assembly, filling in blanks.
3) Convert machine code to MIPS assembly instructions using register names.
4) Convert a beq instruction to machine code.
5) Determine register values after running code on little-endian and big-endian systems.
6) Translate a C function to MIPS assembly, filling in blanks.
7) Indicate whether statements about MIPS are true or false
This document provides instructions for an assignment in ECEN 350 (Summer 2011) involving translating between machine code and assembly language. Students are asked to:
1) Analyze three instructions and determine their type, translate to assembly, and show branch offsets.
2) Translate a C code snippet to MIPS assembly, filling in blanks.
3) Convert machine code to MIPS assembly instructions using register names.
4) Convert a beq instruction to machine code.
5) Determine register values after running code on little-endian and big-endian systems.
6) Translate a C function to MIPS assembly, filling in blanks.
7) Indicate whether statements about MIPS are true or false
This document provides instructions for an assignment in ECEN 350 (Summer 2011) involving translating between machine code and assembly language. Students are asked to:
1) Analyze three instructions and determine their type, translate to assembly, and show branch offsets.
2) Translate a C code snippet to MIPS assembly, filling in blanks.
3) Convert machine code to MIPS assembly instructions using register names.
4) Convert a beq instruction to machine code.
5) Determine register values after running code on little-endian and big-endian systems.
6) Translate a C function to MIPS assembly, filling in blanks.
7) Indicate whether statements about MIPS are true or false
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online from Scribd
Download as pdf or txt
You are on page 1of 6
Assignment 1 ECEN 350 (Summer 2011)
June 17, 2011
Due: Friday, 26, 2011, 11:59PM Sign the following statement: On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work I. For each of the following three instructions below: 1) Determine the type of the instruction (I,R, and J). 2) Convert the instruction to assembly language 3) For branch instructions, show offset in words 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 5 10 15 20 25 30 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 1 1 1 0 0 1 1 0 0 5 10 15 20 25 30 nstruction 1 nstruction 2 nstruction 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 1 0 0 0 1 0 5 10 15 20 25 30 1 II. Given the following C code snippet: int pow = 1; int x = 0; while (pow != 128) { pow = pow * 2; x = x + 1; } A. Explain in words what this program does. B. Fill in the blanks for the following translation of the code to the MIPS assembly language. Assume that register $s0 stores variable pow, while register $s1 stores variable x. addi $s0, __, 1 add __, $0, $0 ___ $t0, $0, ___ while: beq $s0, $t0, ___ ___ $s0, $s0, 1 addi $s1, ___, 1 j while done: 2 III. Convert this MIPS machine code into MIPS Assembly Language instructions. Your nal answers should use the register names, not the numbers (i.e. $t0, not $8). Also, values which represent addresses (if any) should be converted into the full 32 bit address. ADDRESS: Instructions: 0x10001A00 001000 11101 11101 11111 11111 111100 0x10001A04 101011 11101 11111 00000 00000 000000 0x10001A08 000011 00000 10000 01000 00000 000111 0x10001A0C 000000 00010 00010 00010 00000 100000 0x10001A10 100011 11101 11111 00000 00000 000000 0x10001A14 001000 11101 11101 00000 00000 000100 0x10001A18 000000 11111 00000 00000 00000 001000 3 IV. Convert the following beq instruction into machine code: 0x0040310c back: .... .... ... 0x00405000 beq $t9,$s7,back V. A. Suppose that $s0 initially contains 0x12345678. After the following program is run on a little-endian system, what value does $s0 contain? sw $s0, 0($0) lb $s0, 2($0) B. Suppose that $s0 initially contains 0x23456789. After the following program is run on a big-endian system, what value does $s0 contain? sw $s0, 0($0) lb $s0, 1($0) 4 VI. Consider the following C snippet: int find42( int array[], int size) { int i; // index into array for (i = 0; i < size; i = i+1) { if (array[i] == 42) return i; } return -1; } Fill the blanks in the following translation of this snippet to MIPS assembly language. Assume that in the beginning of the program the pointer to array is stored in $a0 and size is stored in $a1. find42: addi $t0, $0, 0 addi $t1, $0, 42 loop: slt $t3, $t0, $a1 beq $t3, ___, exit sll $t2, $t0, ___ add $t2, $t2, $a0 lw $t2, ___($t2) ___ $t2, $t1, done addi $t0, $t0, ___ j loop done: add ___, ___, ___ jr ___ exit: addi $v0, $0, ___ jr ___ VII. For each statement below indicate whether it is true of false. True: False: Usage conventions for register use (what registers are used for what purposes) are strictly enforced by the assembler. True: False: Every instruction in the program is accessible from a single branch statement. True: False: There is at least one MIPS assembly instruction that can perform an arithmetical computation and store the result into memory. True: False: Using $t0 instead of $a0 to pass an argument to a subprogram will generate an error. True: False: If necessary, the $at register can be used by a programmer, though certain instructions would have to be avoided. 5 VIII. Convert the following C snippet into MIPS assembly code. Assume that the register $s0 stores variable amount, while register $s1 stores variable fee. switch(amount){ case 20: fee =2; break; case 50: fee =3; break; case 100: fee =5; break; default: fee =0; } 6
ACFrOgADrA4dUBFymTmKRfSmh21uqQTorw8cNAb2SO32TbM5OlXyDt7NEwOU3AC0DhCebVN6yfJYF8ovy5as3X7Uh0-3gphEz jS67V0vcek4UTmJZ7XcPrsmaUoJLHxRRhy4wFvgkezkhnXY9ZK PDF