Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 2.79 KB | None | 0 0
  1. top:    // read ints from binary file
  2.         mov     w0, fd_r                        // 1st arg (fd)
  3.         mov     x1, buf_base_r                  // 2nd arg (buf)
  4.         mov     w2, buf_size                    // 3rd arg (n)
  5.         mov     x8, 63                          // Read I/O
  6.         svc     0                               // Call sys func
  7.         mov     nread_r, x0                     // # of bytes
  8.  
  9.         // Error check
  10.         cmp     nread_r, buf_size               // nread != 8
  11.         b.ne    end                             // read failed - exit loop
  12.  
  13.         // e^x / e^-x
  14.         ldr     d0, [buf_base_r]                // d is x
  15.         bl      calculations                    // go to calculations
  16.         fmov    d1, d0                          // Mov arg1
  17.         ldr     d0, [buf_base_r]                // d is x
  18.         fneg    d0, d0                          // d is -x
  19.         bl      calculations
  20.         fmov    d2, d0                          // moves to arg2
  21.  
  22.         // Print
  23.         adrp    x0, fmt2                        // Printing the values %13.10f
  24.         add     x0, x0, :lo12:fmt2              // print
  25.         ldr     d0, [buf_base_r]                // arg
  26.         bl      printf
  27.  
  28.         b       top
  29. end:    mov     w0, fd_r                        // 1st arg
  30.         mov     x8, 57                          // close I/O
  31.         svc     0                               // call sys func
  32.         mov     w0, 0                           // return 0
  33.  
  34. done:   ldp     x29, x30, [sp], dealloc
  35.         ret
  36.  
  37. calculations:   stp     x29, x30, [sp, -16]!    // Allocate
  38.                 mov     x29, sp
  39.  
  40.                 adrp    x22, value
  41.                 add     x22, x22, :lo12:value
  42.                 ldr     d3, [x22]               // d3 is now 1.0e-10
  43.  
  44.                 fmov    counter, 1.0            // Increments by 1
  45.                 fmov    power, 1.0
  46.                 fmov    accum, 1.0              // Accumulator is 1
  47.  
  48.                 fmov    numerator, d0           // Num = x
  49.                 fmov    factorial, power
  50.                 fdiv    quotient, numerator, factorial // x / factorial
  51.                 fadd    accum, accum, quotient
  52.  
  53. loop:           fmul    numerator, numerator, d0
  54.                 fadd    power, power, counter           // power++
  55.                 fmul    factorial, factorial, power     // factor * power
  56.                 fdiv    quotient, numerator, factorial  //
  57.                 fadd    accum, accum, quotient          //  accum += term
  58.  
  59.                 fabs    quotient, quotient
  60.                 fcmp    quotient, d3                    // Compare
  61.                 b.ge    loop                            // If quotient >= d3
  62.  
  63.                 fmov    d0, accum
  64.                 ldp     x29, x30, [sp], 16
  65.                 ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement