Wednesday, 15 January 2014

SPARC Assembly array -



SPARC Assembly array -

i need translate c++ code sparc:

main () { int c[5], a; (a=0; a<5; a++) { if (a==0) { c[a] = 3; } else if (a > 3) { c[a] = / 2; } else { c[a] = * 4; } }

here's attempt:

.begin .org 2048 ! (a=0; a<5; main: ld [a], %r2 ! load register 2 top: subcc %r2, 5, %r0 bpos done ! figure out array address in memory sll %r2, 2, %r2 !multi index 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 together %r2, 1, %r2 st %r2, [a] ba top done: halt a: 0 c: 0 0 0 0 0 .end

i believe i'm doing wrong registers. in storing results. don't understand how utilize arrays in sparc.

after this:

sll %r2, 2, %r2 !multi index 4

%r2 no more index.

arrays assembly sparc

No comments:

Post a Comment