Advertisement
rogershagawat

project2

Dec 10th, 2020
3,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.94 KB | None | 0 0
  1. /*
  2.  * main.s
  3.  *
  4.  *  Created on: Dec 8, 2020
  5.  *      Author: roger
  6.  */
  7. .text
  8. .global main
  9. .extern printf
  10.  
  11. main:
  12.     SUB sp, sp, #16
  13.     STR x30, [sp]
  14.     B taylor
  15.  
  16. taylor:
  17.     LDR x3, =x      //put address of x in x3
  18.     LDR d7, [x3]    //put x in d5
  19.     LDR x3, =n      //put address of n in x3
  20.     LDR x3, [x3]    //put n in x2
  21.     MOV x4, x3      // make the i for the taylor loop = n
  22. taylorloop:
  23.     CMP x4, #0          // if i < 0
  24.     B.LT taylorexit     // then leave the loop to taylorexit
  25.     MOV x2, x4          //input for tpart x2=x4, n=i
  26.     FMOV d2, d7
  27.     B tpart
  28. aftertpart:
  29.     FADD d0, d0, d1
  30.     SUB x4, x4, #1
  31.     B taylorloop
  32.  
  33. taylorexit:
  34.     LDR x0, =prt_str
  35.     BL printf
  36.     B exit
  37.  
  38. tpart:                      //finds a part of the taylor series puts in d1, d2=x and x2=n are input, uses d1-d4 and x1-x2
  39.     B exp
  40. tpartafterexp:
  41.     FMOV d5, d1             //save value returned from exp into d3
  42.     SCVTF d2, x2            // convert x2 to a double put in d2
  43.     B fact
  44. tpartafterfact:
  45.     FMOV d6, d1             //save value returned from fact to d4
  46.     FDIV d1, d5, d6         // d1 = d4/d5
  47.     B aftertpart
  48.  
  49. exp:                        // finds the exponential of d2 to the x2, uses d1 and x1
  50.     MOV x1, #1              // make x1 0
  51.     SCVTF d1, x1            // make d1 using x1 0
  52.     MOV x1, x2              // x1 will be our i in mov
  53. exploop:
  54.     CMP x1, #0              // if i <= 0
  55.     B.LE tpartafterexp      // then move to tpart with d1 as answer
  56.     FMUL d1, d1, d2         // multiply d1 by itself and d2 factx*x
  57.     SUB x1, x1, #1
  58.     B exploop
  59.  
  60. fact:                       // find the factorial of the value in d2 puts it in d1 uses d1-d3
  61.     FMOV d1, #1.0           // make d1 1
  62.     FMOV d3, #1.0           // make d3 one for comparisons in factloop
  63.     FMOV d4, #1.0
  64. factloop:
  65.     FCMP d4, d2             // if d4 >= d2 which meand d4 >= original number
  66.     B.GE tpartafterfact     // then return to tpartafter
  67.     FADD d4, d4, d3         // d4++
  68.     FMUL d1, d1, d4         // d1 *= d4
  69.     B factloop              // go back to factloop
  70.  
  71. exit:                       // return to caller
  72.     LDUR x30, [sp]
  73.     ADD sp, sp, #16
  74.     BR x30
  75.  
  76. .data
  77.     n:
  78.         .quad 1
  79.     x:
  80.         .double 100
  81.     prt_str:
  82.     .ascii "the approximation is %f \n\0"
  83.     .end
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement