Example in the class ex1 sum 1..10 without loop s = 0 i = 1 add s s i add i i #1 add s s i add i i #1 .... (repeat add s.., add i 10 times) ex2 sum 1..10 s = 0 i = 1 while i <= 10 s = s + i i = i + 1 .s stop 0 s 1 i 2 .a 0 .c :begin ld s #0 ld i #1 :loop sub r0 i #10 jmp gt exit add s s i add i i #1 jmp always loop :exit trap stop r0 .e ex3 sumarray i 1..10 a is array s = 0 i = 1 while i <= 10 s = s + a[i] i = i + 1 .s stop 0 s 1 i 2 t 3 a 100 .a 0 .c :begin ld s #0 ld i #1 :loop sub r0 i #10 jmp gt exit ld t @a i ; t = a[i] add s s t add i i #1 jmp always loop :exit trap stop r0 .e ex4 function call add1(x) {return x + 1} main a = 2 b = add1(a) .s stop 0 x 1 ; argument of add1() retval 2 ; return value link 3 ; link register a 4 b 5 .a 0 .c :begin ; main ld a #2 or x a r0 ; x = a, pass jal link add1 or b retval r0 ; get return value trap stop r0 :add1 add retval x #1 jr link .e 7 July 2006