2016-09-29 2 views

Antwort

1

Hiermit kann der Code-Zeile-für-Zeile verstehen:

Rechts:

.data   # static variables are defined in .data block 
A: .word 0:100 # array 100 of integers each initialized to 0 

    .text   # MIPS code block 
li $t1, 4  # loading a 16 bit constant value 4 into register $t1 

lw $t0, A($t1) # going to the memory at the address of A (address 
        # of first element of array) + $t1 (which contains 
        # value 4) and fetch it into register $t0 

Links:

.data   # static variables are defined in .data block 
A: .word 0:100 # array 100 of integers each initialized to 0 

    .text   # MIPS code block 
la $t1, A  # load the address of first element of array 
        # into register $t1 

lw $t0, 4($t1) # going to the memory at the address of $t1 + 4 
        # and fetch it into register $t0 

Hinweise: Adressen in MIPS sind in Bytes und Ganzzahlen (.word) sind 4 Bytes. Wenn wir also die Basisadressen des Arrays (Basisadresse des Arrays) um 4 erhöhen, ergibt dies die Adresse des zweiten Elements des Arrays.

Daher: Die beiden Codes sind identisch. Am Ende wird der Inhalt des zweiten Elements des Arrays (unter index = 1) in das Register $t0 geladen.

Verwandte Themen