Sparc Assembly translation programmin help

hi, i tried to convert a c++ algorithm into a sparc assembly program.
i want to know if this code is actually doing wht it is supposed to do.
also how do i access in gdb the variable is before it terminates?
is it p $l5?
i am not sure if i am setting and the loading the variables x, s, and t correctly either.

this is what i have:

!factsum program to calculate n! + (n-1)! +..+ 0!
!given n!=n*(n-1)*(n-2)*...*1


.section ".data"
.align 4
x: .word 1 !x assigned value of 1
n: .word 9 !n assigned value of 9
t: .word 0 !total variable with initial value of 0

.section ".text"
.align 4
.global main

main:

save %sp, -96, %sp
set n, %l0 !n --> %l0
ld [%l0], %l2 !countin = n, countin --> %l2
ld [%l0], %l3 !countout = n, countout --> %l3

set x, %l4 !x --> %l4
ld [%l4], %l6 !%l4 --> %l6
set t, %l5 !t --> %l5
ld [%l5], %l8 !%l5 --> %l8

inloop:

mov %l2, %o0 !countin --> %o0
mov %l6, %o1 !x --> %o1
call .mul !x *= countin, x --> %o1
nop

subcc %l2, 1, %l2 !countin--, have condition code
bg inloop !if > 0 go to inloop, else continue
nop

outloop:
add %l8, %o1, %l8 !t = x + t, t --> %l8
subcc %l3, 1, %l3 !countout--, get the condition code
bg outloop
nop


set t, %l8
st %l5, [%l8] !store final answer in t

exit:

mov 1, %g1
ta 0

//this was converted from this algorithm
: temp = n;
: temp2 = n;
: while(temp2 > 0) {
: sum = 0;
: x = 1;
:
: while (temp > 0) {
: x = temp * x;
: temp--;
: }
:
: sum = x + sum;
: temp2--;
: }

thanks for any help at all
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories