1 / 13

Abdulhafeez Muhammad Al-Rabi Dr. Raed Al-Qadi Lecture 15

Abdulhafeez Muhammad Al-Rabi Dr. Raed Al-Qadi Lecture 15. CS536 – Introduction to Compilers Lecture 15 – MIPS Architecture . MIPS Architecture and xspim :. Lecture examples and assignments use the MIPS R2000. Simple, clean RISC computer Easy to generate code

alpha
Download Presentation

Abdulhafeez Muhammad Al-Rabi Dr. Raed Al-Qadi Lecture 15

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Abdulhafeez Muhammad Al-Rabi Dr. Raed Al-Qadi Lecture 15

  2. CS536 – Introduction to Compilers Lecture 15 – MIPS Architecture .

  3. MIPS Architecture and xspim : • Lecture examples and assignments use the MIPS R2000. • Simple, clean RISC computer • Easy to generate code • Similar to other modern computers • Run code on xspam (simulator for the R2000). • Advantages of a simulator : • Better debugging than bare machine. • Can generate code and test programs on many machines . • Cheaper than 30 R2000's • Disadvantages : • Slower • Miss the "extement" of debugging real hardware . • Documentation on xspam is at MACC.

  4. R2000 • The R2000 is a Reduced Instruction Set (RISC) load-store architecture . • All operands must be explicitly loaded into a register before using them ( unlike the VAX). • Contains 32 general purpose (32-bit) registers. • Contains 32 single floating point (16 double floating point ) registers .

  5. Pseudo-Instructions: • The assembler on MIPS ( and xspim) provide instructions that are not implemented in hardware . • Called pseudo-instructions. • Assembler translates pseudo-instructions to 1-3 MIPS instructions • eg • bge $3 , $4 ,label ;branch on R3 >= R4 to label • sub $1 , $3 , $4 ;$1 := $3 - $4 • bgez $1 label ;branch on R1 >=0 to label • Simplifies hardware since fewer instructions needed • Renaming instructions run faster . • Pseduo-instructions simplify programming • Bare machine is extremely unpleasant • Well-balanced hardware-software trade-off.

  6. Registers: • The 32 general purpose registers have special uses (by convention) • $0 always contains a 0 (fixed by hardware) . • $1 is reserved for the assembler . • $v ($2) is used to return value from function. • $a0-$a3 (4 – 7) pass first 4 arguments to subroutines . • $t0-$t7 (8 – 15) are temporaries that may be destroyed by a call . • $s0-$s7 (16 – 23) are temporaries preserved across call. • $sp (29) is used as stack pointer . • $30 is used as a frame pointer . • $ra (31) is loaded with return address by a call instruction.

  7. Load and Store : • Load and store have the following addressing mode : • Format Address • (reg) contains of registers int value of integer int(reg) int + reg • sym address of symbol sym +- int address +- int • sym +- int(reg) address +- int +- reg • lw R, address • R = address (must be multiple of 4) • lb R, address • R = address • la R, address • R = address • similarly for store .

  8. Arithmetic: • add R1, R2, R3/const • R1 = R2 + R3 • sub R1, R2, R3/const • R1 = R2 – R3 • and R1, R2, R3/const • R1 = R2&R3 • Has the other operations : abs, div, mult, neg, nor, not, or, rem, rol, ror, sll, srl, xor • li R, Const • R = value

  9. Branching: • j label • goto label • jr R • goto (R) • beq R1, R2, label • if(R1 == R2) goto label • Has Other tests : bge, bgeu, bgt, bgtu, blt, bltu, bne

  10. Subroutines: • jal name • name() • Stores return address in $ra and jumbs to name • Return by executing • Jr $ra

  11. Example: • Add numbers from 1 to 10 • li $t0, 0 ;t0 holds sum • li $t1, 1 ;t1 hold index • b test • loop: add $t0, $t0, $t1 ;sum+ = index • addi $t1, $t1, 1 ;index += 1 • test: ble $t1, 10, loop • Compute Length Of a string (strlen) • li $t0, 0 ;t0 holds sum • loop: lb $t1,0($a0) ;a0 holds a string • beqz $t1, done ;zero byte • add $t0, $t0, $t1 ;sum += *str • addi $0, $a0, 1 ;str ++;

  12. Rest Of Course: • Will discuss code generation using the MIPS as the target machine • In each area , discuss semantics of language features and code to implement : • Subroutine calls • Local and global storage • Memory allocation • Arithmetic expressions • Flow control

  13. The End

More Related