Advertisement
thixotropicfluid

ASM PRIME

Oct 18th, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.08 KB | Source Code | 0 0
  1. @ div label:
  2. /*
  3. div label
  4.  
  5. effects:
  6. R0, R1 mutated
  7.  
  8. R1 is the numerator,
  9. R2 is the denomonator ,
  10. R0 is the quotien,
  11. r1 is the remainder, at the end.
  12.  
  13.  
  14. prime program:
  15.  
  16. r2 is v, the denomintor iterator
  17. r3 is n, the numerator interator
  18. r1, acts as the numrator the the div label and as a buffer for n
  19.  
  20. to check remained:
  21.  
  22. set r1 to n (MOV r1, r3)
  23. B Div
  24. then, the remained is in r1.
  25.  
  26. */
  27.  
  28.  
  29.     .data
  30.     .align 4
  31. prime_array: .space 128
  32.  
  33.     .text
  34.     .global _start
  35. _start:
  36.  
  37.     ldr R7, =prime_array
  38.     EOR R0, R0 @ set r0 to 0
  39.     mov r3, #1 @ n = 1
  40.  
  41. n_iter_loop: @ for (int n = 0; n <= 20; n+= 2)
  42.     cmp r3, #19
  43.     BGE stop @ break if n = 20
  44.     mov r2, #3 @ v = 2
  45.     add r3, #2
  46.  
  47. v_iter_loop:
  48.     MOV R1, R3
  49.     B div
  50. divreturn:
  51. @ add break conditions
  52.     cmp r2, r3
  53.     BGE store
  54.     cmp R1, #0
  55.     BEQ n_iter_loop
  56.     add r2, #1
  57.     B v_iter_loop;
  58.  
  59.  
  60.  
  61.     B stop @ when reached end of main, infinte loop
  62. store:
  63.     str r3, [r7]
  64.     ADD r7, #4
  65.     B n_iter_loop
  66. div:
  67.     EOR R0, R0
  68.  
  69. divloop: @ r1/r2 = r0 + r1/r2
  70.     cmp r2, r1
  71.     bgt divreturn
  72.     sub r1, r2
  73.     add r0, #1
  74.     b divloop
  75.  
  76. stop:
  77.     nop
  78.     B stop
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement