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

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

View Full Document Right Arrow Icon
COMP-273 Slides From Patterson’s 61C 1 308-273 Decisions in C/Assembly Language Kaleem Siddiqi
Image of page 1

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

View Full Document Right Arrow Icon
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).
Image of page 2
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
Image of page 3

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

View Full Document Right Arrow Icon
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
Image of page 4
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!
Image of page 5

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

View Full Document Right Arrow Icon
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
Image of page 6
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
Image of page 7

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

View Full Document Right Arrow Icon
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
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern