|
@@ -147,12 +147,33 @@ mov rsi, r9
|
147
|
147
|
mov rdx, rcx
|
148
|
148
|
syscall
|
149
|
149
|
|
150
|
|
-sleep:
|
151
|
|
-mov rax, 35
|
152
|
|
-mov rdi, ts_sleep
|
153
|
|
-mov rsi, 0
|
|
150
|
+; Attempt to read from stdin
|
|
151
|
+; if something read, enter has been pressed
|
|
152
|
+mov rax, 0
|
|
153
|
+mov rdi, 0
|
|
154
|
+mov rsi, buf
|
|
155
|
+mov rdx, 1
|
154
|
156
|
syscall
|
155
|
|
-jmp print_time
|
|
157
|
+cmp rax, 0
|
|
158
|
+jge flush_stdin ; flush stdin and exit
|
|
159
|
+
|
|
160
|
+sleep:
|
|
161
|
+ mov rax, 35
|
|
162
|
+ mov rdi, ts_sleep
|
|
163
|
+ mov rsi, 0
|
|
164
|
+ syscall
|
|
165
|
+
|
|
166
|
+jmp print_time ; main loop
|
|
167
|
+
|
|
168
|
+flush_stdin:
|
|
169
|
+ mov rax, 0
|
|
170
|
+ mov rdi, 0
|
|
171
|
+ mov rsi, buf
|
|
172
|
+ mov rdx, 1
|
|
173
|
+ syscall
|
|
174
|
+ cmp rax, 0
|
|
175
|
+ je newline
|
|
176
|
+ jg flush_stdin
|
156
|
177
|
|
157
|
178
|
exit:
|
158
|
179
|
mov rax, 60 ; sys_exit
|
|
@@ -163,49 +184,17 @@ fault:
|
163
|
184
|
mov rdi, 1 ; failure
|
164
|
185
|
syscall
|
165
|
186
|
|
166
|
|
-
|
167
|
|
-dumprax:
|
168
|
|
- push rax
|
169
|
|
- loopdump:
|
170
|
|
- push rax
|
171
|
|
- mov rbx, rax
|
172
|
|
- and rbx, 0x0F
|
173
|
|
- cmp bl, 0xA
|
174
|
|
- jge hexdigit
|
175
|
|
- add bl, 0x30
|
176
|
|
- jmp loopcont
|
177
|
|
- hexdigit:
|
178
|
|
- sub bl, 10
|
179
|
|
- add bl, 0x41
|
180
|
|
- loopcont:
|
181
|
|
-dbg:
|
182
|
|
- mov byte [digit], bl
|
183
|
|
- mov rax, 1
|
184
|
|
- mov rdi, 1
|
185
|
|
- mov rsi, digit
|
186
|
|
- mov rdx, 1
|
187
|
|
- syscall
|
188
|
|
- pop rax
|
189
|
|
- mov rdi, 10
|
190
|
|
- xor rdx, rdx
|
191
|
|
- mov rsi, rax
|
192
|
|
- div rdi
|
193
|
|
- cmp rax, 10
|
194
|
|
- jge loopdump
|
195
|
|
-
|
196
|
|
- mov al, 10
|
197
|
|
- mov al, [digit]
|
|
187
|
+newline:
|
198
|
188
|
mov rax, 1
|
199
|
189
|
mov rdi, 1
|
200
|
190
|
mov rsi, nl
|
201
|
191
|
mov rdx, 1
|
202
|
192
|
syscall
|
|
193
|
+ jmp exit
|
203
|
194
|
|
204
|
|
- pop rax
|
205
|
|
-ret
|
206
|
195
|
|
207
|
196
|
section .data
|
208
|
|
-foobar: ISTRUC timespec
|
|
197
|
+
|
209
|
198
|
ts_start:
|
210
|
199
|
tv_start_s dq 0
|
211
|
200
|
tv_start_us dq 0
|
|
@@ -215,11 +204,11 @@ msg: db "0 Hello, world!", 10
|
215
|
204
|
msglen: equ $ - msg
|
216
|
205
|
|
217
|
206
|
hours: db "000000000"
|
218
|
|
-timestr: db ":00:00.0000", 0x0D
|
|
207
|
+timestr: db ":00:00.0000 ", 0x0D
|
219
|
208
|
timestrlen: equ $ - timestr
|
220
|
209
|
|
221
|
|
-digit: db "0"
|
222
|
210
|
nl: db 10
|
|
211
|
+buf: db 0
|
223
|
212
|
|
224
|
213
|
ts_cur:
|
225
|
214
|
tv_cur_s dq 0
|