I'm such a dork. I got something right.

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

lady_of_spain January 24 2007, 23:13:25 UTC
Dude, I can write that in scheme.

(define sum-integer
(lambda (num acc)
(cond
((= num 0) acc)
(else (sum-integer (- num 1) (+ num acc))))))

Tail recursion ftw.

Reply

mighmos January 25 2007, 20:30:46 UTC
Wow. I had no idea... mine went something like this:

.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

lady_of_spain January 25 2007, 23:21:20 UTC
Hmmm....scheme definitely looks easier. I'm learning C++ next semester, though.

Reply


Leave a comment

Up