Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- top: // read ints from binary file
- mov w0, fd_r // 1st arg (fd)
- mov x1, buf_base_r // 2nd arg (buf)
- mov w2, buf_size // 3rd arg (n)
- mov x8, 63 // Read I/O
- svc 0 // Call sys func
- mov nread_r, x0 // # of bytes
- // Error check
- cmp nread_r, buf_size // nread != 8
- b.ne end // read failed - exit loop
- // e^x / e^-x
- ldr d0, [buf_base_r] // d is x
- bl calculations // go to calculations
- fmov d1, d0 // Mov arg1
- ldr d0, [buf_base_r] // d is x
- fneg d0, d0 // d is -x
- bl calculations
- fmov d2, d0 // moves to arg2
- // Print
- adrp x0, fmt2 // Printing the values %13.10f
- add x0, x0, :lo12:fmt2 // print
- ldr d0, [buf_base_r] // arg
- bl printf
- b top
- end: mov w0, fd_r // 1st arg
- mov x8, 57 // close I/O
- svc 0 // call sys func
- mov w0, 0 // return 0
- done: ldp x29, x30, [sp], dealloc
- ret
- calculations: stp x29, x30, [sp, -16]! // Allocate
- mov x29, sp
- adrp x22, value
- add x22, x22, :lo12:value
- ldr d3, [x22] // d3 is now 1.0e-10
- fmov counter, 1.0 // Increments by 1
- fmov power, 1.0
- fmov accum, 1.0 // Accumulator is 1
- fmov numerator, d0 // Num = x
- fmov factorial, power
- fdiv quotient, numerator, factorial // x / factorial
- fadd accum, accum, quotient
- loop: fmul numerator, numerator, d0
- fadd power, power, counter // power++
- fmul factorial, factorial, power // factor * power
- fdiv quotient, numerator, factorial //
- fadd accum, accum, quotient // accum += term
- fabs quotient, quotient
- fcmp quotient, d3 // Compare
- b.ge loop // If quotient >= d3
- fmov d0, accum
- ldp x29, x30, [sp], 16
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement