decisions.pdf

# decisions.pdf - 308-273 Decisions in C/Assembly Language...

• 30

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

COMP-273 Slides From Patterson’s 61C 1 308-273 Decisions in C/Assembly Language Kaleem Siddiqi

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

COMP-273 Slides From Patterson’s 61C 2 Review (1/2) ° In MIPS Assembly Language: Registers replace C variables One Instruction (simple operation) per line Simpler is Better Smaller is Faster ° Memory is byte -addressable, but lw and sw access one word at a time. ° A pointer (used by lw and sw ) is just a memory address, so we can add to it or subtract from it (using offset).
COMP-273 Slides From Patterson’s 61C 3 Review (2/2) ° New Instructions: add, addi, sub, lw, sw ° New Registers: C Variables: \$s0 - \$s7 Temporary Variables: \$t0 - \$t9 Zero: \$zero

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

COMP-273 Slides From Patterson’s 61C 4 Overview ° C/Assembly Decisions: if , if-else ° C/Assembly Loops: while , do while , for ° Inequalities ° C Switch Statement
COMP-273 Slides From Patterson’s 61C 5 So Far... ° All instructions have allowed us to manipulate data. ° So we’ve built a calculator. ° To build a computer, we need ability to make decisions… ° Heads up: pull out some papers and pens, you’ll do some in-class exercises today!

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

COMP-273 Slides From Patterson’s 61C 6 C Decisions: if Statements ° 2 kinds of if statements in C if ( condition ) clause if ( condition ) clause1 else clause2 ° Rearrange 2nd if into following: if ( condition ) goto L1; clause2; go to L2; L1: clause1; L2: Not as elegant as if-else, but same meaning
COMP-273 Slides From Patterson’s 61C 7 MIPS Decision Instructions ° Decision instruction in MIPS: beq register1, register2, L1 beq is “Branch if (registers are) equal” Same meaning as (using C): if (register1==register2) goto L1 ° Complementary MIPS decision instruction bne register1, register2, L1 bne is “Branch if (registers are) not equal” Same meaning as (using C): if (register1!=register2) goto L1 ° Called conditional branches

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

COMP-273 Slides From Patterson’s 61C 8 MIPS Goto Instruction ° In addition to conditional branches, MIPS has an unconditional branch : j label ° Called a Jump Instruction: jump (or
This is the end of the preview. Sign up to access the rest of the document.
• Spring '09
• Vybihal

{[ 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