Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 0.99 KB | None | 0 0
  1.  
  2.     b   top
  3. calc:   stp     x29, x30, [sp, -16]!        // Allocate
  4.     mov     x29, sp
  5.  
  6.     fmov    counter, 1.0            // It's a counter
  7.     fmov    power, 1.0     
  8.     fmov    accum, 1.0          // Accumulator is 1
  9.  
  10.         fmov    numerator, d0               // Num = x
  11.        fmov    factorial, power
  12.         fdiv    quotient, numerator, factorial  // x / factorial
  13.         fadd    accum, accum, quotient      // accum + quotient
  14.  
  15. loop:   adrp    x27, value
  16.     add x27, x27, :lo12:value
  17.     ldr d3, [x27]           // d3 = 0r1.0e-10
  18.  
  19.     fmul    numerator, numerator, d0    // d0 * num
  20.     fadd    power, power, counter       // power++
  21.     fmul    factorial, factorial, power // factor * power
  22.     fdiv    quotient, numerator, factorial  // quotient = num / fact
  23.     fadd    accum, accum, quotient      // accum += quotient
  24.        
  25.     fabs    quotient, quotient
  26.     fcmp    quotient, d3            // Compare
  27.     b.ge    loop                // If quotient >= d3
  28.        
  29.     fmov    d0, accum
  30.     ldp x29, x30, [sp], 16
  31.     ret
  32.  
  33. end:    mov w0, fd_r            // 1st arg (fd)
  34.     mov x8, 57              // closing I/O
  35.     svc 0               // call sys func
  36.     mov w0, 0               // ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement