-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.s
More file actions
128 lines (120 loc) · 3.79 KB
/
main.s
File metadata and controls
128 lines (120 loc) · 3.79 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
BITS 64
GLOBAL main
SECTION .text
_start:
.setUpStart:
push r12 ; We want to use r12 for ourself
sub rsp, 16
mov word [rsp], 1
mov word [rsp + 8], 0
.printHeaderInfo:
mov ax, 1 ; write(
mov di, 1 ; STDOUT_FILENO,
mov rsi, msg ; message,
mov dx, msglen ; sizeof(message)
syscall ; );
; Time to begin the timer work, Do note we shouldnt get to end
; r12 = time left (seconds)
.cycleStart:
.workBegin:
mov r12, 1500 ; 25 minutes * 60 seconds == 1500
.workLoopStart:
mov ax, 1 ; write(
mov rdi, 1 ; STDOUT_FILENO,
mov rsi, workmsg ; "Time to work, you have "
mov dx, workmsglen ; sizeof(message)
syscall
call printR12
mov ax, 1 ; write(
mov di, 1 ; STDOUT_FILENO,
mov rsi, trailmsg ; " seconds remaining \n",
mov dx, trailmsglen ; sizeof(message)
syscall
; Now we have to sleep
mov ax, 35 ; Nanosleep syscall number
lea rdi, [rsp]
lea rsi, [rsp + 8]
syscall
dec r12
jge .workLoopStart
.workEnd:
mov ax, 1 ; write(
mov rdi, 1 ; STDOUT_FILENO,
mov rsi, beepmsg ; "beep",
mov dx, beepmsglen ; sizeof(message)
syscall
.funBegin:
mov r12, 300 ; 5 minutes * 60 seconds == 300
.funLoopStart:
mov ax, 1 ; write(
mov rdi, 1 ; STDOUT_FILENO,
mov rsi, breakmsg ; "Time to work, you have "",
mov dx, breakmsglen ; sizeof(message)
syscall
call printR12
mov ax, 1 ; write(
mov di, 1 ; STDOUT_FILENO,
mov rsi, trailmsg ; " seconds remaining \n",
mov dx, trailmsglen ; sizeof(message)
syscall
mov rax, 35 ; Nanosleep syscall number
lea rdi, [rsp]
lea rsi, [rsp + 8]
syscall
dec r12
jge .funLoopStart
.funEnd:
mov ax, 1 ; write(
mov rdi, 1 ; STDOUT_FILENO,
mov rsi, beepmsg ; "beep",
mov dx, beepmsglen ; sizeof(message)
syscall
jmp .workBegin
printR12:
.printR12Prolouge:
sub rsp, 5
.printR12Start:
; dx = upper bits of dividend so first bits of x
; ax = lower bits of dividend so last bits of x
; ax = result
; dx = remainder
mov cx, 1000
mov rax, r12
mov dx, 0
div cx
add ax, 48
mov [rsp], al
mov cx, 100
mov ax, dx
mov dx, 0
div cx
add ax, 48
mov [rsp + 1], al
mov cx, 10
mov ax, dx
mov dx, 0
div cx
add ax, 48
add dx, 48
mov [rsp + 2], al
mov [rsp + 3], dl
.printR12ActuallyPrint:
mov rax, 1 ; write(
mov rdi, 1 ; STDOUT_FILENO,
mov rsi, rsp ; "{number},
mov rdx, 5 ; sizeof(message)
syscall
.printR12Epilouge:
add rsp, 5
ret
section .rodata
workmsg: db 13, "Time to work, you have "
workmsglen: equ $ - workmsg
breakmsg: db 13, "Time to relax, you have "
breakmsglen: equ $ - breakmsg
trailmsg: db " seconds remaining. "
trailmsglen: equ $ - trailmsg
msg: db "MIT Licenced, see https://github.com/joecwilson/tinyTimer for details.", 10
msglen: equ $ - msg
beepmsg: db 13 ,"Finished a cylcle, Notifing", 7
beepmsglen: equ $ - beepmsg