.Word directives in MIPS assembly

       .data
VALS:  .half 0xbead, 0xface
RES:   .space 4
    .text
    la     $t0,VALS
    lh    $t1,($t0)
    lhu    $t2,2($t0)
    sll    $t2,$t2,16
    or    $t2,$t1,$t2
    jal    AVG
    .word  -2
    .word  -6
    la    $t4,RES
       sw  $v0,($t4)
       li     $v0,10
    syscall
AVG:   lw  $v0,($ra)
    lw    $t3,4($ra)
    add    $v0,$v0,$t3
    sra    $v0,$v0,1
    addi   $ra,$ra,8
    jr     $ra

In this MIPS code, what do the .word parts do? My emulator cannot process data directives in a text section. What do directives do? And what's the point of making the words .word -2 and .word -6, not .word -8?

+3
source share
1 answer

the directive puts the word word -2 and -6 into the code stream. if you look at the actual binary representation of this fragment, you will find in the middle of the command encoding some FFFFFFFEFFFFFFFA or FEFFFFFFFAFFFFFF depending on the entity.

The assembler will emit 2 words worth the data -2 and -6, respectively, nothing like a single word -8.

, AVG: ,

lw $v0, ($ra)
lw $t3, 4($ra)

2 v0 t3 (.. , .. , ). ... v0 -2 , t3 -6. , 8 $ra , .

, .

, , , 2 , , ( , Average). ​​, ( asm , ). , AVG , , ( ), .

+4

Source: https://habr.com/ru/post/1735365/


All Articles