Академический Документы
Профессиональный Документы
Культура Документы
Tek
Working with Arrays
Arrays
0x12340010 array[4]
0x1234800C array[3]
0x12348008 array[2]
0x12348004 array[1]
0x12348000 array[0]
Working with Arrays
Accessing Arrays
int array[5];
array[0] = array[0] * 2;
array[1] = array[1] * 2;
# array base address = $s0
lui $s0, 0x1234 # put 0x1234 in
# upper half of
# $S0
ori $s0, $s0, 0x8000 # put 0x8000 in
# lower half of
0x12340010 array[4] # $s0
0x1234800C array[3]
0x12348008 array[2] lw $t1, 0($s0) # $t1 = array[0]
0x12348004 array[1] sll $t1, $t1, 1 # $t1 = $t1 * 2
0x12348000 array[0] sw $t1, 0($s0) # array[0] = $t1
lw $t1, 4($s0) # $t1 = array[1]
sll $t1, $t1, 1 # $t1 = $t1 * 2
sw $t1, 4($s0) # array[1] = $t1
Working with Arrays
lw $a0, 0($t1) # print value at the array
li $v0, 1 # pointer
syscall
addi $t2, $t2, 1 # advance loop counter
addi $t1, $t1, 4 # advance array pointer
j print_loop # repeat the loop
print_loop_end:
.data
array: .space 24 # allocate 24 consecutive bytes with storage uninitialised
# could be used as a 24element character array, or a
# 6element integer array; a comment should indicate
# which!
Working with Arrays