arithmem.pdf

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

• 29

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

COMP-273 Arith/Mem (1) Slides From Patterson’s 61C 308-273 C/Assembler Arithmetic and Memory Access Kaleem Siddiqi

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

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
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;

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

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

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

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

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

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.
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