1 / 10

MIPS instructions

MIPS instructions. MIPS Assembly for if-then-else. Now it is straightforward to translate the C program into MIPS assembly Problem is how do you implement this jump. How to Encode Branch Instructions.

Download Presentation

MIPS instructions

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. MIPS instructions week04-3.ppt

  2. MIPS Assembly for if-then-else • Now it is straightforward to translate the C program into MIPS assembly • Problem is how do you implement this jump week04-3.ppt

  3. How to Encode Branch Instructions • To encode these branch instructions, we first need to figure out the value for the associated label • This will be done by the assembler • Note that the MIPS has the alignment restriction, which means all the labels will be a multiple of 4 • To increase the range, the address divided by 4 is actually encoded • In other words, the address is in terms of words (32 bits), rather than bytes week04-3.ppt

  4. Encoding Conditional Branch Instructions • It branches the number of the instructions specified by the offset if register rs equals to register rt • In the stored-program concept, we implicitly need a register to hold the address of the current instruction being executed • Which is called program counter (PC) (should be called instruction address register) • What is the value of PC after we finish executing the current instruction? week04-3.ppt

  5. Abstract View of MIPS Implementation week04-3.ppt

  6. Encoding Conditional Branch Instructions • PC-relative addressing • The offset of conditional branch instructions is relative to PC + 4 • Since all MIPS instructions are 4 bytes long, the offset refers to the number of words to the next instruction instead of the number of bytes week04-3.ppt

  7. Example • What is the encoding of • In other words, what should be the offset? week04-3.ppt

  8. Encoding bne 31 26 25 21 20 16 15 0 opcode rs rt Immediate Value rs Label/Offset bne $19, $20, Else rt 31 26 25 21 20 16 15 0 0 0 0 1 0 1 1 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 opcode rs rt Immediate Value 0 0 0 1 0 1 1 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 Encoding = 0x16740002 week04-3.ppt

  9. Compiling a while loop in C • How to translate the following to MIPS assembly? • We first translate into a C program using if and goto week04-3.ppt

  10. Compiling a while loop in C • Assume that i and k correspond to registers $s3 and $s5 and base array save is in $s6 week04-3.ppt

More Related