jump to navigation

Operation of two arrays – MIPS March 23, 2010

Posted by aghus in Assembly Language, Edukasi.

If we have pseudocode for array operation below :
int i;
for (i=0; i < 100; i=i+1)

We can make MIPS assembly
.globl __start
la $a1, array_a
la $a2, array_b
lw $a3, size #size of array
move $t0, $0 #i=0
loopl: sll $t1, $t0, 2 #$t1=i*4
sll $t3, $t0, 2 #$t3=i*4

add $t2, $a1, $t1 #$t2=&array_a[i]
add $t4, $a2, $t3 #$t4=&array_b[i]
addi $s0, $t2, -4 #$s0=&array_a[i-1]

lw $t6,0($t2) #array_a[i]
lw $t7,0($t4) #array_b[i]
lw $s1,0($s0) #array_a[i-1]
add $t6,$t7,$s1 #array_a[i]=array_b[i]+array_a[i-1]

addi $a0,$t6,0
li $v0, 1

addi $t0, $t0, 1 #i = i+1
slt $t3, $t0, $a3 #$t3 = (i<size)
bne $t3, $0, loopl #if(i<size) go to loopl

li $v0, 10

array_a: .space 400
array_b: .space 400



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: