Created
August 16, 2012 13:00
-
-
Save haileys/3369946 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| global _main | |
| extern _printf | |
| extern _exit | |
| extern _pthread_create | |
| extern _pthread_exit | |
| extern _pthread_join | |
| %define WORKERS 4 | |
| worker: | |
| and rsp, ~15 | |
| mov rax, rdi | |
| .loop: | |
| add rdi, WORKERS | |
| cmp rdi, 100000000 | |
| jg .end | |
| add rax, rdi | |
| jmp .loop | |
| .end | |
| mov rdi, rax | |
| call _pthread_exit | |
| fmt: db "%ld", 10, 0 | |
| _main: | |
| and rsp, ~15 | |
| xor rbx, rbx | |
| .spawn_workers: | |
| mov rdi, rbx | |
| sal rdi, 4 | |
| mov rsi, threads | |
| add rdi, rsi | |
| xor rsi, rsi | |
| mov rdx, worker | |
| mov rcx, rbx | |
| call _pthread_create | |
| inc rbx | |
| cmp rbx, WORKERS | |
| jl .spawn_workers | |
| xor rbx, rbx | |
| .join_workers: | |
| mov rdi, rbx | |
| sal rdi, 4 | |
| mov rsi, threads | |
| add rdi, rsi | |
| mov rsi, rdi | |
| add rsi, 8 | |
| mov rbp, rsi | |
| mov rdi, [rdi] | |
| call _pthread_join | |
| mov rax, [rbp] | |
| mov rsi, sum | |
| add [rsi], rax | |
| inc rbx | |
| cmp rbx, WORKERS | |
| jl .join_workers | |
| mov rdi, fmt | |
| mov rsi, sum | |
| mov rsi, [rsi] | |
| call _printf | |
| xor rdi, rdi | |
| call _exit | |
| section .data | |
| sum: dq 0 | |
| tmp: dq 0 | |
| threads: | |
| times (WORKERS * 2) dq 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment