Advertisement
KillianMills

prime.s

Oct 24th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. .data
  2. CONTROL: .word 0x10000
  3. DATA: .word 0x10008
  4. A: .word 17; N value
  5. B: .word 2 ; i value
  6.  
  7. .text
  8. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9. ; load memory-mapped IO addresses
  10. ld r20,CONTROL(r0) ; load CONTROL address
  11. ld r21,DATA(r0) ; load DATA address
  12. ld r10,A(r0) ; loads r10 as 17, n value
  13. ld r11,B(r0) ; loads r11 as 2, i value
  14. daddi r2,r0,0
  15. daddi r3,r0,1
  16. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17.  
  18.  
  19. isPrime:
  20. beq r11,r10,prime ; if r11 hits r10,it is prime then jump to prime, e.g: 17 = 17
  21.  
  22. ; N i
  23. ddiv r2,r10,r11 ;divide r10 by r11, put value into r2 17 / 2 = r2
  24. dmul r2,r2,r11 ;multiply r2 by r11, put value into r2 r2 * 2 = r2
  25.  
  26. ; if r2 = r10 , number is prime
  27. beq r2,r10,done ; if r2 hits r10, stop if a number before r11=r10 can divide in once successfully then end program
  28.  
  29. daddi r11,r11,1 ; i++ / B++
  30.  
  31. j isPrime
  32.  
  33. prime:
  34. dadd r1,r0,r11
  35. sd r1,0(r21) ; set DATA to output value
  36.  
  37. daddi r1,r0,2
  38. sd r1,0(r20) ; write CONTROL
  39.  
  40. done:
  41. halt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement