Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- org $400
- arr: dc.w 1, 2, 12, 4, 21
- n: dc.w 5
- sum: dc.w 0
- org $1800
- START:
- clr.l d0 ; i = 0, we use the .l since i takes part in .l calculation
- clr.l d3 ; sum = 0 (temporarily sum lives in d3)
- move.w n, d1 ; d1 = n
- loop: cmp.w d1, d0
- bge endloop ; if (i >= n) goto endloop
- movea.l #arr, a0 ; a0 = &arr[0]
- adda.l d0, a0
- adda.l d0, a0 ; a0 = &arr[0] + 2 x i
- add.w (a0), d3 ; d3 = d3 + arr[i]
- addq.w #1, d0 ; i = i + 1
- bra loop ; repeat loop
- endloop: move.w d3, sum ; write the sum into memory
- END START
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement