-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram.asm
51 lines (40 loc) · 2.17 KB
/
program.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
%include "Clock.inc" ; Include Clock functions
section .bss ; Global variables initialized to 0
samples: resq 48000*2 ; The audio buffer, one sample is a double between 0 and 1
clock: resq 1 ; clock device pointer
resolution: resq 1 ; Resolution of clock
range: resq 1 ; Range of clock
t1: resq 1 ; Time 1
t2: resq 1 ; Time 2
section .text ; Program data
global Program ; Make "Program" visible outside
Program: ; Start of Program
enter 0, 0 ; Start new stack frame
mov [clock], rdi ; Store clock pointer in variable
; Get clock specs
mov rdi, [clock] ; (clock, &resolution, &range)
mov rsi, resolution ; ---
mov rdi, range ; ---
call ClockSpecs ; Get clock specifications
; Get curren time
mov rdi, [clock] ; (clock, -2)
mov rax, -2 ; ---
cvtsi2sd xmm0, rax ; ---
call CurrentTime ; Get current time
movq [t1], xmm0 ; Store current time in t1
; Wait 1 second
loop:
mov rdi, [clock] ; (clock, -2)
mov rax, -2 ; ---
cvtsi2sd xmm0, rax ; ---
call CurrentTime ; Get current time
movq [t2], xmm0 ; Store current time in t1
movq xmm0, [t1] ; while t1 + 1 < t2
mov rax, 1 ; ---
cvtsi2sd xmm1, rax ; ---
addsd xmm0, xmm1 ; ---
comisd xmm0, [t2] ; ---
pause ; Spinlock pause
ja loop ; ---
leave ; Done with function
ret ; Return