Example Code
```asm
.data
# int array[3][4] = {
# {1,2,3,4},
# {3,4,5,6},
# {5,6,7,8},
# };
array:
.word 1,2,3,4
.word 3,4,5,6
.word 5,6,7,8
.text
# int main(void) {
# change(3, 4, array, 2);
# return 0;
# }
main:
addi $sp, $sp, -4
sw $ra, ($sp) # put $ra onto the stack
li $a0, 3
li $a1, 4
la $a2, array
li $a3, 2
jal change # change()
lw $ra, ($sp) # take $ra off the stack
addi $sp, $sp, 4
# return 0
li $v0, 0
jr $ra
# void change (int nrows, int ncols, int M[nrows][ncols], int factor)
# {
# for (int row = 0; row < nrows; row++) {
# for (int col = 0; col < ncols; col++) {
# M[row][col] = factor * M[row][col];
# }
# }
# }
change:
addi $sp, $sp, -4
sw $s2, ($sp) # put $s2 onto the stack
# ABI - app binary interface
# $a - function arguments
# $t0 is `row`
# $t1 is `col`
outter_loop_init:
li $t0, 0 # int row = 0;
outter_loop_cond:
blt $t0, $a0, outter_loop_body # row < nrows;
b outter_loop_end
outter_loop_body:
inner_loop_init:
li $t1, 0 # int col = 0;
inner_loop_cond:
blt $t1, $a1, inner_loop_body # col < ncols;
b inner_loop_end
inner_loop_body:
# M[row][col] = factor * M[row][col];
# M[row][col]
# base + offset
# base = M
# offset = sizeof(type) * index
# index = curr_row * N_COL + curr_col
# index = $t0 * $a1 + $t1
# offset = 4 * ($t0 * $a1 + $t1)
mul $s2, $t0, $a1 # curr_row * N_COL
add $s2, $s2, $t1 # + curr_col
mul $s2, $s2, 4 # * sizeof(type)
add $s2, $a2, $s2 # base + offset
lw $t3, ($s2)
mul $t3, $a3, $t3 # factor * M[row][col];
sw $t3, ($s2) # M[row][col] = factor * M[row][col];
inner_loop_incr:
addi $t1, $t1, 1 # col++
b inner_loop_cond
inner_loop_end:
outter_loop_incr:
addi $t0, $t0, 1 # row++
b outter_loop_cond
outter_loop_end:
change_funct_end:
lw $s2, ($sp) # take $s2 off the stack
addi $sp, $sp, 4
# return 0
li $v0, 0
jr $ra
```
The jal change in this code will dissemble to jal outter_loop_init
This appears to be a bug with relying on hash ordering. something that is non-deterministic for security.
Each time the file is loaded all b*/j* destination labels that have multiple labels at the same address will be randomized.
Example Code
```asm .data # int array[3][4] = { # {1,2,3,4}, # {3,4,5,6}, # {5,6,7,8}, # }; array: .word 1,2,3,4 .word 3,4,5,6 .word 5,6,7,8 .text # int main(void) { # change(3, 4, array, 2); # return 0; # } main: addi $sp, $sp, -4 sw $ra, ($sp) # put $ra onto the stack li $a0, 3 li $a1, 4 la $a2, array li $a3, 2 jal change # change() lw $ra, ($sp) # take $ra off the stack addi $sp, $sp, 4 # return 0 li $v0, 0 jr $ra # void change (int nrows, int ncols, int M[nrows][ncols], int factor) # { # for (int row = 0; row < nrows; row++) { # for (int col = 0; col < ncols; col++) { # M[row][col] = factor * M[row][col]; # } # } # } change: addi $sp, $sp, -4 sw $s2, ($sp) # put $s2 onto the stack # ABI - app binary interface # $a - function arguments # $t0 is `row` # $t1 is `col` outter_loop_init: li $t0, 0 # int row = 0; outter_loop_cond: blt $t0, $a0, outter_loop_body # row < nrows; b outter_loop_end outter_loop_body: inner_loop_init: li $t1, 0 # int col = 0; inner_loop_cond: blt $t1, $a1, inner_loop_body # col < ncols; b inner_loop_end inner_loop_body: # M[row][col] = factor * M[row][col]; # M[row][col] # base + offset # base = M # offset = sizeof(type) * index # index = curr_row * N_COL + curr_col # index = $t0 * $a1 + $t1 # offset = 4 * ($t0 * $a1 + $t1) mul $s2, $t0, $a1 # curr_row * N_COL add $s2, $s2, $t1 # + curr_col mul $s2, $s2, 4 # * sizeof(type) add $s2, $a2, $s2 # base + offset lw $t3, ($s2) mul $t3, $a3, $t3 # factor * M[row][col]; sw $t3, ($s2) # M[row][col] = factor * M[row][col]; inner_loop_incr: addi $t1, $t1, 1 # col++ b inner_loop_cond inner_loop_end: outter_loop_incr: addi $t0, $t0, 1 # row++ b outter_loop_cond outter_loop_end: change_funct_end: lw $s2, ($sp) # take $s2 off the stack addi $sp, $sp, 4 # return 0 li $v0, 0 jr $ra ```The
jal change
in this code will dissemble tojal outter_loop_init
This appears to be a bug with relying on hash ordering. something that is non-deterministic for security. Each time the file is loaded all
b*
/j*
destination labels that have multiple labels at the same address will be randomized.