SPARC Assembly

Anyone know much about assembly code? I need to write a program to do this:
main () {
int c[5], a;
for (a=0; a<5; a++) {
if (a==0) {
c[a] = 3;
} else if (a > 3) {
c[a] = a / 2;
} else {
c[a] = a * 4;
}
}
but I'm painfully lost. I'll post my attempt in a comment.
.begin
.org 2048
! for (a=0; a<5;
main: ld [a], %r2 ! load a into register 2
top: subcc %r2, 5, %r0
bpos done
! figure out array address in memory
sll %r2, 2, %r2 !multi index by 4
! if (a==0)
subcc %r2, 0, %r0
bne elseif
! true, c[a]=3
st %r3, %r2+3
! false, else if (a>3)
elseif: subcc %r2, 4, %r3
bpos else
! true, c[a]=a/2
srl %r2, 1, %r2
st %r3, %r2
! false, else: c[a]=a*4
else: sll %r2, 2, %r3
ba done
! Increment a=a+1
add %r2, 1, %r2
st %r2, [a]
ba top
done:
halt
a:
0
c:
0
0
0
0
0
.end
Topic archived. No new replies allowed.