{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ass4sol

ass4sol - Introduction to Computer Engineering 1 Assignment...

This preview shows pages 1–4. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Question 2 (25 points) MIPS' native assembly code only has two branch instructions, beq and bne, and only one comparison instruction, slt. Using just these three instructions (along with the ori instruction to set a to 0 or 1), write the MIPS assembly language equivalents for the following "C" code snippets, and then also translate the resulting assembly instructions into machine code explaining for each line how you worked out the machine instruction. (Assume that x is stored in register \$6, y is stored in register \$7, and z is stored in register \$8. Remember that in "C", if an expression is true, it evaluates to 1 and if false, it evaluates to 0. Refer to Appendix A of the text for descriptions of MIPS assembly language instructions and the corresponding machine codes. You are not limited to register \$6,\$7,\$8 ) Here is an example: x = (x < y); Assembly code : slt \$6,\$6,\$7 #sets x to 1 if x<y done: Machine Language : 0x00C7302A 000000 Opcode for slt 00110 Code for \$6 00111 Code for \$7 00110 Code for \$6 00000 Shamt of 0 101010 Function 0x2a NOTE THE OFFSET FOR BEQ AND BNE MAY VARY BY 1 DEPENDING ON IF YOU ADD THE OFFSET TO THE BEQ/BNE INSTRUCTION OR THE NEXT ONE. BOTH ANSWERS ARE VALID a) x = (y > z) (5 points) Assembly: slt \$6,\$8,\$7 #sets x if z<y done: Machine Language: 000000 Opcode for slt 01000 Code for \$8 00111 Code for \$7 00110 Code for \$6 00000 Shamt of 0 101010 Function 0x2a
b) x = (z != x) && (y > x) (5 points)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern