MIPS: Equivalent to la instruction without using pseudo-codes?

The link says that the pseudocode for la (download address) translates to:

Pseudo : la $1, Label   

lui $1, Label[31:16]
ori $1,$1, label[15:0]

but when I try to compile code in MARS, I get an error:

"Invalid language element: 16]

and if I delete the part [31:16], I will get

Shortcut: The operand is of the wrong type

Any idea?

+3
source share
2 answers

This means that the 16 most significant tag bits are set to $ 1. Then the 16 least significant bits have the 16 most significant bits.

Here you can find a description of the lui command. It loads 16 mb bits of label address in the register and resets 16 lsb.

This way you can load the 32-bit address (in mips32) with 32-bit instructions.

" ". [31:16]/[15: 0] mips -.

: , , lui. .

.data 
my_var: .asciiz "This is a nul terminated string"

.text
        andi $a0,$a0,0x0000ffff
        lui $a0,my_var
        ori $a0,$a0,my_var
+4

, . .

, , , (, SPIM ). .data , 32- , . ( .kdata .data).

:

.data 0x10001000                 #remember this location
    .align 0
    .asciiz "MIPS IS GREAT!"     #this is at offset 0

.text
    .align 2
    .globl main
main:                            #let assume we've got no arguments
    addiu $sp, $sp, -24          #subroutine prolog
    sw $ra, 16($sp)
    sw $fp, 10($sp)
    addiu $fp, $sp, 20

    ori $v0, $0, 4
    lui $a0, 0x1000              #sole argument must be str pointer
    ori $a0, $a0, 0x1000
    syscall                      #print STR out on console

    lw $ra, 16($sp)              #subroutine epilog
    lw $fp, 10($sp)
    addiu $sp, $sp, 24
    jal

, , , ( , .. ), ( , , ).

EDIT: , - - . :

.data 0x10001000
        .word LABEL
LABEL:  .asciiz "Get LABEL to print this C string."

.text
    .align 2
    .globl main
#test if it loads LABEL
main:
    lui $4, 0x1000
    ori $4, $4, 0x1000
    lw $4, 0($4)
    ori $2, $0, 4
    syscall

SPIM ! 0x10001000 , 0x10001004 ! . , .

+1

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


All Articles