Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * main.s
- *
- * Created on: Dec 8, 2020
- * Author: roger
- */
- .text
- .global main
- .extern printf
- main:
- SUB sp, sp, #16
- STR x30, [sp]
- B taylor
- taylor:
- LDR x3, =x //put address of x in x3
- LDR d7, [x3] //put x in d5
- LDR x3, =n //put address of n in x3
- LDR x3, [x3] //put n in x2
- MOV x4, x3 // make the i for the taylor loop = n
- taylorloop:
- CMP x4, #0 // if i < 0
- B.LT taylorexit // then leave the loop to taylorexit
- MOV x2, x4 //input for tpart x2=x4, n=i
- FMOV d2, d7
- B tpart
- aftertpart:
- FADD d0, d0, d1
- SUB x4, x4, #1
- B taylorloop
- taylorexit:
- LDR x0, =prt_str
- BL printf
- B exit
- tpart: //finds a part of the taylor series puts in d1, d2=x and x2=n are input, uses d1-d4 and x1-x2
- B exp
- tpartafterexp:
- FMOV d5, d1 //save value returned from exp into d3
- SCVTF d2, x2 // convert x2 to a double put in d2
- B fact
- tpartafterfact:
- FMOV d6, d1 //save value returned from fact to d4
- FDIV d1, d5, d6 // d1 = d4/d5
- B aftertpart
- exp: // finds the exponential of d2 to the x2, uses d1 and x1
- MOV x1, #1 // make x1 0
- SCVTF d1, x1 // make d1 using x1 0
- MOV x1, x2 // x1 will be our i in mov
- exploop:
- CMP x1, #0 // if i <= 0
- B.LE tpartafterexp // then move to tpart with d1 as answer
- FMUL d1, d1, d2 // multiply d1 by itself and d2 factx*x
- SUB x1, x1, #1
- B exploop
- fact: // find the factorial of the value in d2 puts it in d1 uses d1-d3
- FMOV d1, #1.0 // make d1 1
- FMOV d3, #1.0 // make d3 one for comparisons in factloop
- FMOV d4, #1.0
- factloop:
- FCMP d4, d2 // if d4 >= d2 which meand d4 >= original number
- B.GE tpartafterfact // then return to tpartafter
- FADD d4, d4, d3 // d4++
- FMUL d1, d1, d4 // d1 *= d4
- B factloop // go back to factloop
- exit: // return to caller
- LDUR x30, [sp]
- ADD sp, sp, #16
- BR x30
- .data
- n:
- .quad 1
- x:
- .double 100
- prt_str:
- .ascii "the approximation is %f \n\0"
- .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement