Pages

Thursday, 20 November 2014

LANGUAGES OF THE COMPUTER 2 PART 1

32-bit Constants

Most constant are small.

• Using I format for arithmetic instructions with immediate operands

– Only 16 bits for immediate field

– Constants have to fit in 16 bits


• Using I format for branch address
– Only 16 bits in immediate field
– But 32 bits needed for branch address

Jump adressing
– Only 26 bits for address field
– But 32 bits needed for Jump address



Branch Addressing

  • Branch instruction specify
           - Opcode ,two registers , target address
  • Most branch targets are near branch
           - Forward or Backward


op
rs
rt
Constant or address
           
  6 bits           5 bits            5 bits         16 bits

---->     6+5+5+16=32 bits
• opcode = control instruction
• rs, rt = source operands
• address= address offset in words, ± 215
       - hardware sign-extends when uses (replicate msb)
        -target address = PC + (immed*4)


So step by step :
  • Sign extend the 16 bit offset value to preserve its value.
  • Multiply resulting value with 4. The reason behind this is that If we are going to branch some address, and PC is already word aligned, then the immediate value has to be word-aligned as well. However, it makes no sense to make the immediate word-aligned because we would be wasting low two bits by forcing them to be 00.
  • Now we have 32 bit address. Add this value to PC + 4 and that is your branch address.
Branch address calculation


Pc-relative addressing

PC-relative addressing: the value in the immediate 
field is interpreted as an offset of the next 
instruction (PC+4 of current instruction) 

Example: beq $0,$3,Label
sources:

Jump addressing


op
address
·                         6 bits                        26 address

------->6 + 26 =32 bits


• J format has 26 bits in address field
– How to get 32 bits?
• Assume that jump address is a word address
* 1 word = 32 bits = 4 byte
• 26 + 2 (least significant bits) = 28
• Get 4 most significant bits from PC
– 4 + 26 + 2 = 32
– Implication: can only jump within a 228 = 256 MB block of 
addresses
– Loader and linker must be careful to avoid placing a program 

across an address boundary of 256 MB

(Pseudo)Directjump addressing


• an instruction provided by the assembler but not implemented in
the hardware
• used as a shortcut by assembly language programmers
• blt $t1, $t2, L1 # pseudoinstruction for branch to L1
# if $t1 < $t2
assembler expands to: slt $at, $t1, $t2
bne $at, $0, L1
(note the use of $at ($1) by the assembler)
also bgt, bge, ble




source:




post by:

Nursyahirah Syafiqah binti Baharim














2 comments: