Can help me translate mips to binary?

I don’t understand how to translate the shortcut. Anyone can help me.

Suppose we have the following code:

loop: 
    add $t2,$t2,$t1 
    addi $t2,$t2,4 
    sw $t2,4($s0) 
    bne $t2,20,loop 
    jr $ra

How to translate to binary bne $t2,10,loop?

+4
source share
2 answers

A few comments.

The branch deviation is always calculated at branch address + 4 (i.e. PC + 4), therefore it refers to the instruction address jr.

Since the mips commands must be aligned with the word [four byte boundary], the rightmost two bits of the command address will [always be] zero.

The mips architecture uses this by encoding a branch offset as a word offset (i.e. a byte offset is shifted to the right by 2). This extends the 16-bit-16-bit-bit range to 18 bits.

, :

00:     loop:
00:         add     $t2,$t2,$t1
04:         addi    $t2,$t2,4
08:         sw      $t2,4($s0)
0C:         bne     $t2,20,loop
10:         jr      $ra

jr 0x10, -0x10, -0x04 0xFFFC, bne xxxxFFFC

... . bne . bne , bne.

, :

00:     loop:
00:         add     $t2,$t2,$t1
04:         addi    $t2,$t2,4
08:         sw      $t2,4($s0)
0C:         addi    $at,$zero,20
10:         bne     $at,$t2,loop
14:         jr      $ra

, bne : addi bne

jr 0x14, -0x14, -0x05 0xFFFB, bne xxxxFFFB

bne:

    bne    s,t,label

bne:

0001 01ss ssst tttt iiii iiii iiii iiii

, s $at $100001

t $t2 $1001010

, :

0001 01ss ssst tttt iiii iiii iiii iiii
       00 0010 1010
0001 0100 0010 1010 iiii iiii iiii iiii

142Ayyyy. , yyyy FFFB, : 142AFFFB

+3

bne rs,rt,label, 6 - , 5 - rs, 5 - rt, - :

BTA = PC + 4 + imm * 4

, , 4 4 . .

?

bne (I-type). 5 (000101). , .

00100100000100000000000000110000
00000000000100000010000000100001
00100100000000100000000000001011
00000000000000000000000000001100
00100010000100000000000000000011
00100100000010000000000001011101
00010110000010001111111111111010
00000000000000000000000000000000
00001000000100000000000000001000
00000000000000000000000000000000

10 (10 ). 7 00010110000010001111111111111010. 6 000101 - 5. 5 + 5 ( $16 $8, - .

,

.text
loop: 
    add $t2,$t2,$t1 
    addi $t2,$t2,4 
    sw $t2,4($s0) 
    bne $t2,20,loop 
    jr $ra

7 :

00000001010010010101000000100000
00100001010010100000000000000100
10101110000010100000000000000100
00100000000000010000000000010100
00010100001010101111111111111011
00000011111000000000000000001000

 Address    Code        Basic                     Source

0x00400000  0x01495020  add $10,$10,$9        3        add $t2,$t2,$t1 
0x00400004  0x214a0004  addi $10,$10,0x00000004        addi $t2,$t2,4 
0x00400008  0xae0a0004  sw $10,0x00000004($16)5        sw $t2,4($s0) 
0x0040000c  0x20010014  addi $1,$0,0x00000014 6        bne $t2,20,loop 
0x00400010  0x142afffb  bne $1,$10,0xfffffffb      
0x00400014  0x03e00008  jr $31                7        jr $ra

... - bne: 00010100001010101111111111111011. 6 000101 - , 5 (00001) + 5 (01010) - , (1111111111111011) - ( 1111111111111011= FFFB.

. MIPS.

0

All Articles