lecture4 - LECTURE 4 ASSEMBLY April 7 2011 Levels of...

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

View Full Document Right Arrow Icon
1 LECTURE 4: ASSEMBLY April 7, 2011 Levels of Representation lw $t0, 0($2) lw $t1, 4($2) sw $t1, 0($2) sw $t0, 4($2) temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; 0000 1001 1100 0110 1010 1111 0101 1000 1010 1111 0101 1000 0000 1001 1100 0110 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111 High Level Language Program (e.g., C) Assembly Language Program (e.g.,MIPS) Machine Language Program (MIPS)
Image of page 1

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

View Full Document Right Arrow Icon
2 MIPS Instruction Set Each instruction executes exactly one of a short list of simple commands Instructions are divided into three kinds of format ( R, I and J format ) Common arithmetic instructions ( R format ) Memory load and store ( I format ) Branching and jump instructions ( J format ) Your First MIPS Instructions ! All R instructions have 3 operands Operand order is fixed ( destination first ) Example: C code: A = B + C MIPS code: add $s0, $s1, $s2 C code: A = B - C MIPS code: sub $s0, $s1, $s2 A,B,C in C programming are variables S0-S2 in Assembly are registers Compiler associates variables with registers
Image of page 2
3 Registers (1/4) Unlike high level language like C or Java, assembly cannot use variables Why not? Keep Hardware Simple Arithmetic (aka R) instructions operands must be registers limited number of special locations built directly into the hardware operations can only be performed on these! Compiler associates variables with registers Registers (2/4) Benefit: Since registers are directly in hardware, they are very fast (faster than 1 billionth of a second) 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
Image of page 3

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

View Full Document Right Arrow Icon
4 Registers (3/4) Each MIPS register is 32 bits wide Groups of 32 bits called a word in MIPS 32 registers in MIPS Why 32? Smaller is faster Registers are numbered from 0 to 31 Each register can be referred to by number or name Number references: $0, $1, $2, … $30, $31 By convention, each register also has a name to make it easier to code Registers (4/4) Use names to make your code more readable Register name Common name Description $16-$23 $s0-$s7 Saved registers to use freely. Preserved across function calls. (correspond to C variables) $8 -$15 $t0-$t7 Temporary registers you can use as you want. Not guaranteed to be preserved across function calls. $0 $zero Hard wired to the value zero, always has the value 0. Any writes to this register are ignored. $1,$26, $27,$29 Reserved for special purposes by the assembler, compiler and operating system. Others will be introduced later
Image of page 4
5 Register Zero One particular immediate, the number zero (0), appears very often in code. So we define register zero ($0 or $zero) to always have the value 0; add $s0,$s1,$zero (in MIPS) f = g (in C) where MIPS registers $s0,$s1 are associated with C variables f, g Immediates Immediates are numerical constants.
Image of page 5

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

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