Instruction fetch Bring the instruction the processor should execute next from

Instruction fetch bring the instruction the processor

This preview shows page 22 - 27 out of 27 pages.

Instruction fetchBring the instruction the processor should execute next from memory and place it into the instruction register - Operation: read from memory - use memory address as content of PC register - data read out: - instruction we need to execute - load instruction into instruction registerDecoding instructionmeaning of instruction specified in Instruction Set Architecture (ISA) - We will be using MIPS illustrateR-type MIPS instruction have 3-operands: - 2 source register - acting as data input - 1 destination register - acting as data outputLoad-store architecture - only specific instruction allow memory access - cannot adda value with a present value in the memory. need to load that into a register firstExample: unsigned subtraction (subu $d, $s, $t)00000000 00000001 00111000 00100011000000ss sssttttt ddddd000 00100011First 6 bits are opcode, specifies the instruction type
Image of page 22
Assembly LanguageMIPS instruction typesR-type (register-type) operates on registersthree regs: two source regs (rs& rt) and one destination reg (rd)field coded with all 0 bits when not usedopcode is 000000function field (last 6 digit) specifies type of operation being performedI-type (immediate?)a 16-bit immediate field, used for immediate operand, a branch target offset or a displacement for a memory operandJ-typeonly two instructions:jump (j)jump and link (jal)use 26-bit coded address field to specify target of the jump
Image of page 23
Control flowSome operations require the code to branch to one section of code or another (if/else)m and some require the code to jump back and repeat a section of code again (for/while).Branch instructionsinstructionbeqbgtzblezbnekey for if statement and loopslabels are memory locationsaddresses are assigned to each label at compile timeif branch cond is true, CMP output of ALU is set to 1an input to and AND gate in our datapath along with PCWriteCondiis an offset in # of instructions between the location of the current instructionsinstruction the processor should fetch next iinstructions before (if i < 0) or after (if i > 0) from current branch instructionLoop in MIPSLoop in Cfor( <init>; <cond>; <update> ) {<forbody>}Loop in asm<init>START:if (!<cond>) branch to END<for body>UPDATE:<update>jump to STARTEND:example:# $t0 = i, $t1 = jadd$t1, $zero, $zero # set t1 to 0addi $t0, $zero, 1# set t0 to 1addi $t9, $zero, 100# set $t9 to 100
Image of page 24
START:slt $t7, $t0, $t9 # set t7 to 1if i < 100beq $t7, $zero, END # branch if !(i < 100)add$t1, $t1, $t0 # j = j + 1UPDATE:addi $t0, $t0, 1# i++j STARTEND:Load & Store instructionsinstructionlblbulhlhulwsbshswb: byteh: half wordw: wordSE: Sign-ExtensionZE: Zero-ExtensionMemory Segments.data- Indicates the start of all static data declarations - usually placed above .textsegment in .asmfile - Form: label type value- Example: - var1: .word 3- array1: .byte 'a', 'b'- array2: .space 40
Image of page 25
.text- Indicates the start of the program instructions - label for the first instruction to run when executing the program is called main - la $d, labelloads data from labelto $dcall functionjal FUNCTION_LABEL- jal
Image of page 26
Image of page 27

You've reached the end of your free preview.

Want to read all 27 pages?

  • Fall '09
  • Central processing unit, Flip-flop

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes