Advertisement
Guest User

snoopybbt

a guest
Jan 6th, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     org $400
  2.    
  3. arr:     dc.w     1, 2, 12, 4, 21
  4. n:     dc.w     5
  5. sum:     dc.w     0
  6.  
  7.    
  8.     org $1800
  9.  
  10. START:
  11.     clr.l     d0        ; i = 0, we use the .l since i takes part in .l calculation
  12.     clr.l     d3        ; sum = 0 (temporarily sum lives in d3)
  13.     move.w    n, d1     ; d1 = n
  14.  
  15. loop:   cmp.w     d1, d0
  16.     bge       endloop   ; if (i >= n) goto endloop
  17.  
  18.     movea.l   #arr, a0  ; a0 = &arr[0]
  19.     adda.l    d0, a0  
  20.     adda.l    d0, a0    ; a0 = &arr[0] + 2 x i
  21.     add.w     (a0), d3  ; d3 = d3 + arr[i]
  22.  
  23.     addq.w    #1, d0    ; i = i + 1
  24.     bra       loop      ; repeat loop
  25.  
  26. endloop:    move.w    d3, sum   ; write the sum into memory
  27.  
  28.     END START
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement