Jan 22, 2007 13:29
I just coded my first real assignment for Computer Science 261: Computer Organization and Assembly. I had to write a program ... in assembly that would computer the sum of an integer. Like 6 = 21. (6+5+4+3+2+1 = 21). I got it done -- on my first try. I'm such a dork.
PS: Its SPARC assembly.
school,
tech
Leave a comment
Comments 3
(define sum-integer
(lambda (num acc)
(cond
((= num 0) acc)
(else (sum-integer (- num 1) (+ num acc))))))
Tail recursion ftw.
Reply
.global main
main: save %sp, -64, %sp
!clr %l1
mov 1, %l1
clr %l0
test: cmp %l1, 6
ble,a loop
add %l1, %l0, %l0
ba,a finish
loop: !add %l1, %l0, %l0 ! Here for sanity's sake
ba test ! Silly prefetching
add 1, %l1, %l1
finish: mov 1, %g1
nop
ta 0
Reply
Reply
Leave a comment