; ; Computes sum from i = 1 to N, placing result in sum. ; The algorithm used is the straightforward one, not that used by Gauss. ; 0x0100 ; .org 0x0100 0x011101110101 ; 0x0100 gauss: subge sum,sum,next 0x010d010d0102 ; 0x0101 subge i,i,next 0x010d010c0103 ; 0x0102 loop: subge,i,neg1,next 0x010e010e0104 ; 0x0103 subge tmp,tmp,next 0x010e01100105 ; 0x0104 subge tmp,N,next 0x010f010f0106 ; 0x0105 subge k,k,next 0x010f010e0107 ; 0x0106 subge k,tmp,next 0x010f010d0109 ; 0x0107 subge k,i,next 0x000000000000 ; 0x0108 ret: subge 0,0,0 ; placeholder 0x010f010f010a ; 0x0109 subge k,k,next 0x010f010d010b ; 0x010a subge k,i,next 0x0111010f0102 ; 0x010b subge sum,k,loop ; sum = sum - k = sum + i; ; sum >= 0 must be true, so always ; goes to loop (unless overflow) 0xffffffffffff ; 0x010c neg1: .word -1 0x000000000000 ; 0x010d i: .word 0 0x000000000000 ; 0x010e tmp: .word 0 0x000000000000 ; 0x010f k: .word 0 0x000000000000 ; 0x0110 N: .word 0 ; (input) 0x000000000000 ; 0x0111 sum: .word 0 ; (output)