arithmem.pdf - 308-273 C/Assembler Arithmetic and Memory...

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

View Full Document Right Arrow Icon
COMP-273 Arith/Mem (1) Slides From Patterson’s 61C 308-273 C/Assembler Arithmetic and Memory Access 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 Arith/Mem (2) Slides From Patterson’s 61C Overview ° C operators, operands ° Variables in Assembly: Registers ° Addition and Subtraction in Assembly ° Memory Access in Assembly
Image of page 2
COMP-273 Arith/Mem (3) Slides From Patterson’s 61C Review C Operators/Operands ° Operators: + , - , * , / , % (mod); 7/4==1 , 7%4==3 ° Operands: Variables: fahr , celsius Constants: 0 , 1000 , -17 , 15.4 ° Assignment Statement: Variable = expression Examples: celsius = 5*(fahr-32)/9; a = b+c+d-e;
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 Arith/Mem (4) Slides From Patterson’s 61C Assembly Design: Key Concepts ° Assembly language is essentially directly supported in hardware, therefore ... ° It is kept very simple! Limit on the type of operands Limit on the set operations that can be done to absolute minimum - if an operation can be decomposed into a simpler operation, don’t include it
Image of page 4
COMP-273 Arith/Mem (5) Slides From Patterson’s 61C Assembly Variables: Registers (1/3) ° Unlike HLL, assembly cannot use variables Why not? Keep Hardware Simple ° Assembly Operands are registers limited number of special locations built directly into the hardware operations can only be performed on these! ° Benefit: Since registers are directly in hardware, they are very fast
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 Arith/Mem (6) Slides From Patterson’s 61C Assembly Variables: Registers (2/3) ° Drawback: Since registers are in hardware, there are a predetermined number of them Solution: MIPS code must be very carefully put together to efficiently use registers ° 32 registers in MIPS Why 32? Smaller is faster ° Each MIPS register is 32 bits wide Groups of 32 bits called a word in MIPS
Image of page 6
COMP-273 Arith/Mem (7) Slides From Patterson’s 61C Assembly Variables: Registers (3/3) ° Registers are numbered from 0 to 31 ° Number references: $0, $1, $2, … $30, $31 ° By convention, each register also has a name to make it easier to code: $16 - $22 è $s0 - $s7 (correspond to C variables) $8 - $15 è $t0 - $t7 (correspond to temporary variables) ° In general, use register names to make your code more readable
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 Arith/Mem (8) Slides From Patterson’s 61C Comments in Assembly ° Another way to make your code more readable: comments! ° Hash (#) is used for MIPS comments anything from hash mark to end of line is a comment and will be ignored ° Note: Different from C.
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