Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; input one single double precision number and get the table for successive square roots
- ; warning: no error checking options are added
- ; assemble using `nasm -f elf64 -o output.o file.asm`
- ; link using `gcc -o output output.o`
- extern printf
- extern scanf
- section .data
- two dq 2.0
- fmt db "iter#%02d: sqrt(%.10lf) = %.10lf",10,0
- fmt2 db "%lf"
- section .bss
- b resq 1
- section .text
- global main
- main:
- push rbp
- mov rbp, rsp
- sub rsp, 0x30
- input:
- mov rdi, fmt2
- mov rsi, b
- call scanf
- xor r12, r12
- mov rax, qword [b]
- movsd xmm0, qword [b]
- movsd xmm1, xmm0
- log_loop:
- mov ecx, 6
- sqrt_loop:
- movsd xmm2, xmm0
- divsd xmm2, xmm1
- addsd xmm1, xmm2
- movsd xmm2, qword [two]
- divsd xmm1, xmm2
- movq rax, xmm1
- loop sqrt_loop
- inc r12
- movsd xmm2, xmm1
- mov rdi, fmt
- mov rsi, r12
- mov rax, 2
- call printf
- movsd xmm0, xmm2
- movsd xmm1, xmm2
- cmp r12, 34
- jle log_loop
- mov rsp, rbp
- pop rbp
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement