Unformatted text preview:

Registers vs. MemoryProcessor I/OControlDatapathMemoryInputOutput• Arithmetic instructions operands must be registers, ! — only 32 registers provided•Each register: 32 bits = 4 bytes = 1 word• Compiler associates variables with registers• What about programs with lots of variablesMemory Organization• Viewed as a large, single-dimension array, with an address.• A memory address is an index into the array• "Byte addressing" means that the index points to a byte of memory.0123456...8 bits of data8 bits of data8 bits of data8 bits of data8 bits of data8 bits of data8 bits of dataByte Addresses• Since 8-bit bytes are so useful, most architectures address individual bytes in memory• MIPS: memory address of a word must be multiple of 4 (alignment restriction)• Big Endian:" leftmost byte is word address IBM 360/370, Motorola 68k, MIPS, Sparc, HP PA• Little Endian:" rightmost byte is word addressIntel 80x86, DEC Vax, DEC Alpha (Windows NT)msb lsb3 2 1 0little endian byte 00 1 2 3big endian byte 0Instructions: a simple example• A C statement•f, g, h, i, j are assigned to $s0, $s1, $s2, $s3, $s4f = (g +h) - (i + j)add $t0, $s1, $s2add $t1, $s3, $s4sub $s0, $t0, $t111Load and store instructions•Load and store instructions•lw $tn, c_off($S_base)•sw $tn, c_off($S_base)•Example:! C code:!! g = h + A[8];! MIPS code:! lw $t0, 32($s3) add $s1, $s2, $t0•Spilling registers•doubly slowg : $s1h : $s2base address of A : $s3$tn : destination register$S_base : register with base addressc_off : offset from baseLoad and store instructions•Example:! C code:!! A[12] = h + A[8];!•Store word has destination last•Remember: arithmetic operands are registers, not memory!! Can’t write: !add 48($s3), $s2, 32($s3)MIPS code:! lw $t0, 32($s3) add $t0, $s2, $t0 sw $t0, 48($s3)13So far we’ve learned:•MIPS! — loading words but addressing bytes! — arithmetic on registers only•Instruction! ! ! Meaningadd $s1, $s2, $s3 $s1 = $s2 + $s3sub $s1, $s2, $s3 $s1 = $s2 – $s3lw $s1, 100($s2) $s1 = Memory[$s2+100] sw $s1, 100($s2) Memory[$s2+100] = $s1Constants• To use a constant, have to use memory, just like for variables•Example: add 4 to register $s3•Quick add instruction: addi• Design principle: make the common case fastlw $t0, AddrConstant4($s1) # t0 is the constant 4 add $s3, $s3, $t0 addi $s3, $s3, 415•Instructions, like registers and words of data, are also 32 bits long–Example: add $t0, $s1, $s2–registers must have numbers (why?) $t0=8, $s1=17, $s2=18•Instruction Format:! 000000 10001 10010! 01000! 00000! 100000! op! rs! rt! rd! shamt! functRepresenting Instructions in the ComputerMachine Languageop 6-bits opcode that specifies the operationrs 5-bits register file address of the first source operandrt 5-bits register file address of the second source operandrd 5-bits register file address of the result’s destinationshamt 5-bits shift amount (for shift instructions)funct 6-bits function code augmenting the opcode0171880 32Aside: MIPS Register ConventionNameRegister NumberUsagePreserve on call?$zero0constant 0 (hardware)n.a.$at1reserved for assemblern.a.$v0 - $v12-3returned valuesno$a0 - $a34-7argumentsyes$t0 - $t78-15temporariesno$s0 - $s716-23saved valuesyes$t8 - $t924-25temporariesno$gp28global pointeryes$sp29stack pointeryes$fp30frame pointeryes$ra31return addr (hardware)yes17• What if an instruction needs longer fields•e.g.: in lw, address of constant may be more than 32 (25)• conflict: keep instruction length same vs. have a single instruction format• New principle: Good design demands a compromise• Here: different formats for different instructions (keep length same)•Introduce a new type of instruction format–I-format for data transfer instructions and immediate instructions–other format was R-format for register•Example: lw $t0, 32($s3)! 35! 19! 9! 32! op! rs! rt! 16 bit numberMachine Language18•Instructions are bits•Programs are stored in memory ! — to be read or written just like data•Fetch & Execute Cycle–Instructions are fetched and put into a special register–Bits in the register "control" the subsequent actions–Fetch the “next” instruction and continueMemory memory for data, programs, compilers, editors, etc.Stored Program


View Full Document

MU CPTR 308 - Registers vs. Memory

Download Registers vs. Memory
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Registers vs. Memory and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Registers vs. Memory 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?