Continue on - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Continue on

Description:

op field (opcode) in I-type layout has unique code for each instruction. ... op field (opcode field) by looking at instruction code table, is 8 ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 19
Provided by: ahmadrh
Category:
Tags: continue | opcode

less

Transcript and Presenter's Notes

Title: Continue on


1
Continue on Machine Language Representation of
Instruction
2
  • What happens if we have immediate in the
    instruction
  • I-Type layout is used for instruction that uses
    one of the following
  • registers with an immediate value .
  • registers with offset
  • Such instructions are addi, lw, sw, bne, beq
  • The format and fields for I-Type layout is

op rs rt Immediate
6 bit 5bit 5 bit
16 bit
3
  • op field (opcode) in I-type layout has unique
    code for each instruction.
  • rs field (source register) generally used to
    specify the register containing first operand
  • rt field (target register) generally used to
    specify register that receives the result of
    computation.
  • Immediate has immediate value. This value is a
    signed number and is signed extended.
  • This immediate field is large enough to handle
    the offset in lw and sw instruction

4
  • Example
  • Write the machine instruction for this assembly
    instruction
  • addi s5, s6, -50
  • op field (opcode field) by looking at instruction
    code table, is 8
  • rs field that contains s6 and corresponds to
    22nd register in the processor
  • rt field that contains s5 and corresponds to
    21st register.
  • Immediate has immediate value of -50

5
  • Using this information
  • addi s5, s6, -50

op rs rt Immediate
6 bit 5bit 5 bit 16bit
decimal representation
8 22 21 -50
6 bit 5bit 5 bit 16bit
Machine language instruction representation
001000 10110 10101 1111111111001110
6 bit 5bit 5 bit
16bit
6
  • Example
  • Write the machine instruction for this assembly
    instruction
  • lw t0, 32(s3)
  • op field (opcode field) by looking at instruction
    code table, is 35
  • rs field (source field) that contains s3 and
    corresponds to 19th register in the processor
  • rt field (target field) that gets the value
    from the address in memory.t0 corresponds to 8th
    register.
  • Immediate has the offset value of 32.

7
  • Using this information
  • lw t0, 32(s3)

op rs rt Immediate
6 bit 5bit 5 bit 16bit
decimal representation
35 19 8 32
6 bit 5bit 5 bit 16bit
machine language instruction representation
100011 10011 01000 0000000000100000
6 bit 5bit 5 bit
16bit
8
  • Example
  • Write the machine instruction for this assembly
    instruction
  • sw t0, 32(s3)
  • op field (opcode field) by looking at instruction
    code table, is 43
  • rs field (source field) contains s3 and
    corresponds to 19th register in the processor
  • rt field (target field) represents the t0 that
    its value needs to be stored in memory.t0
    corresponds to 8th register
  • Immediate has the offset value of 32.

9
  • Using this information
  • sw t0, 32(s3)

op rs rt Immediate
6 bit 5bit 5 bit 16bit
decimal representation
43 19 8 32
6 bit 5bit 5 bit 16bit
machine language instruction representation
101011 10011 01000 0000000000100000
6 bit 5bit 5 bit 16bit
10
  • Example
  • In this C segment Find the machine language for
    branch instruction (beq).
  • loop add t0, t0, t1
  • addi t0, t0, 4
  • beq s1 , s2, loop
  • op field (opcode field) by looking at instruction
    code table , is 4
  • rs field (source field) contains s1 and
    corresponds to 17th register in the processor
  • rt field (target field) represents s2 that its
    value need to be compare and corresponds to 18st
    register.
  • Immediate a positive or negative value that
    shows the number of instructions a way from
    branch instruction.

11
  • We know that PC (program counter) is a register
    that will increment as each instruction executed.
    It always shows the address of one instruction
    after current executing instruction.
  • The 16-bit immediate field is a 16 bits signed
    integer that represents the number of words away
    from one instruction after branch instruction (PC
    shows one instruction after branch instruction).
    The number can be negative if the label in the
    branch instruction is referring to the
    instruction above the current Executing
    instruction or could be positive if the label is
    referring to the instruction under the current
    Executing instruction.
  • Processor will add this immediate value to PC in
    order to find the exact address of label.
  • In the last slide example, loop label is above
    the beq instruction, the immediate should be a 16
    bits negative value, and loop is 3 instruction
    away from the instruction after beq, therefore
    -3 will be placed in the immediate field

12
  • In this C segment Find the machine language for
    branch instruction (beq).
  • loop add t0, t0, t1
  • addi t0, t0, 4
  • bnq s1 , s2, loop
  • op field op code is 4 by looking at table
  • rs (source register field) s1 which corresponds
    to 17 register in the processor
  • rt (target field)s2 corresponds to 18 register
    in the processor
  • Immediate field is -3 which shows the number of
    words to the instruction after bnq.

op rs rt Immediate
6 bit 5bit 5 bit 16 bit
4 17 18 -3
10001 10010 1111111111111101
000100
6 bit 5bit 5 bit
16 bit
13
  • Problem With Small Immediate Field
  • In I-type Format
  • MIPS has a computer architecture that supports a
    32 bit data path, (transfers 32 bit data from
    register to memory and vice versa.)
  • It has 232 memory locations and each location has
    a 32 bit address.
  • Now what will happen if, in the immediate field
    of I-Type layout, we have a big immediate number
    that need to be used in the calculation and dose
    not fit in the 16 bits immediate field of I-Type
    format
  • Chances are that addi, lw, and sw will use
    an immediate that is small enough to fit in the
    immediate field, but we have to find a way to
    represent the big immediate in machine language.

14
  • How to solve this problem
  • Solution to use big immediate for addition is to
    use new instruction.
  • lui register(at) immediate
  • lui loads upper bits of immediate , it takes 16
    bit of immediate and puts them in the upper half
    of the specified register (at) and sets lower
    half to 0
  • register that takes the upper half of immediate
    .Use at, it is specifically used for assembler.
    (by convention)
  • Big immediate value

1
2
3
15
  • Example
  • Using big immediate number in addition
  • addi t0 , t0, 0xABABCDCD (A big decimal
    number in hex)
  • It will be implemented as follow
  • lui at, 0xABAB
  • ori at, at, 0xCDCD
  • add t0, t0, at

16
  • J-Type format
  • Jump instructions such as j label and jal
    label use this instruction format.
  • op field hold the unique value for each one of
    these instruction
  • address field hold the address of the label.

op Address
6 bit 26 bit
17
  • Example
  • Write the machine instruction for this assembly
    instruction assume the label has address 0xC1C4
  • j label_1
  • op field (opcode field) by looking at instruction
    code table, is 2
  • address field, contains the address of the label
    (0xC1C4)

op Address
6 bit 26 bit
2 C1C4(in hex)
6 bit 26 bit
machine language instruction representation
000010 00000000001100000111000100
6 bit 26 bit
18
  • Example
  • Write the machine instruction for this assembly
    instruction assume the label has address 0xC1C8
  • jal label_2
  • op field (opcode field) by looking at instruction
    code table ,is 3
  • address field that contain the address of the
    label (0xC1C8)

op Address
6 bit 26 bit
decimal representation
3 C1C8(in hex)
6 bit 26 bit
machine language instruction representation
000011 00000000001100000111001000
6 bit 26 bit
Write a Comment
User Comments (0)
About PowerShow.com