-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswap.s
53 lines (40 loc) · 998 Bytes
/
swap.s
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
51
52
53
## Tested against Debian Jessie.
.text
.globl main
main:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movl $0, %r8d
movl $1, %r9d
rdtscp ## writes processor time into edx:eax
movl %edx, %r11d # high order bits
movl %eax, %r12d
# movl $10000, %ecx # loop counter
start:
# actual work
movl %r8d, %r10d # r10 is tmp
movl %r9d, %r8d
movl %r10d, %r9d
#end actual work
#loop start ## uncomment to do with looping to sanity check. Overstates time of course due to the jump time
rdtscp
# move original readings onto stack
movl %r11d, -4(%rbp) ## high order bits
movl %r12d, -8(%rbp) ## low order
# new reading
movl %edx, -12(%rbp) ## again, high order
movl %eax, -16(%rbp) ## low order
movq -8(%rbp), %rdx # load back as 64bit
movq -16(%rbp), %rsi
subq %rdx, %rsi #into rsi since we'll print it next
leaq runtime(%rip), %rdi
xorl %eax, %eax
callq printf
addq $16, %rsp
popq %rbp
retq
.section .data
runtime:
.asciz "Processor time elapsed %lld\n"
# vim: ft=gas