Advertisement
sarker306

SQRT TABLE FOR LOG CALCULATION

Dec 29th, 2019
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; input one single double precision number and get the table for successive square roots
  2. ; warning: no error checking options are added
  3. ; assemble using `nasm -f elf64 -o output.o file.asm`
  4. ; link using `gcc -o output output.o`
  5.     extern  printf
  6.     extern  scanf
  7.     section     .data
  8. two     dq      2.0
  9. fmt     db      "iter#%02d: sqrt(%.10lf) = %.10lf",10,0
  10. fmt2    db      "%lf"
  11.     section     .bss
  12. b   resq        1
  13.     section     .text
  14.     global  main
  15. main:
  16.     push    rbp
  17.     mov     rbp, rsp
  18.     sub     rsp, 0x30
  19.  
  20. input:
  21.     mov     rdi, fmt2
  22.     mov     rsi, b
  23.     call    scanf
  24.  
  25.     xor     r12, r12
  26.     mov     rax, qword [b]
  27.     movsd   xmm0, qword [b]
  28.  
  29.     movsd   xmm1, xmm0
  30. log_loop:
  31.     mov     ecx, 6
  32. sqrt_loop:
  33.     movsd   xmm2, xmm0
  34.     divsd   xmm2, xmm1
  35.     addsd   xmm1, xmm2
  36.     movsd   xmm2, qword [two]
  37.     divsd   xmm1, xmm2
  38.     movq    rax, xmm1
  39.     loop sqrt_loop
  40.  
  41.     inc     r12
  42.     movsd   xmm2, xmm1
  43.     mov     rdi, fmt
  44.     mov     rsi, r12
  45.     mov     rax, 2
  46.     call    printf
  47.  
  48.     movsd   xmm0, xmm2
  49.     movsd   xmm1, xmm2
  50.     cmp     r12, 34
  51.     jle     log_loop
  52.  
  53.     mov     rsp, rbp
  54.     pop     rbp
  55.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement