-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuse_ctime.asm
82 lines (70 loc) · 1.37 KB
/
use_ctime.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
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
; -----------------------------------------------------------------------------
; name:
; use_ctime
; author:
; zxsvrx
; copyright:
; Copyright (c) 2024 zxsvrx
; license:
; MIT License (see LICENSE in /main)
; platform:
; macOS
; architecture:
; x86_64
; syntax:
; nasm
; compiler:
; nasm 2.16.01
; build tool:
; gcc (Apple clang version 15.0.0)
;
; build with:
; nasm -f macho64 -o use_ctime.o use_ctime.asm && gcc -o use_ctime use_ctime.o
;
; A program that calls c functions from libc.
; -----------------------------------------------------------------------------
%define SYS_exit 0x2000001
section .text
extern _puts
extern _printf
extern _time
global _main
_main:
push rbp
mov rbp, rsp
mov rdi, 0x0
call _time
; seconds
mov [rbp - 8], QWORD rax
; minutes
cqo
mov rcx, 60
div rcx
mov [rbp - 16], QWORD rax
; hours
cqo
mov rcx, 60
div rcx
mov [rbp - 24], QWORD rax
; days
cqo
mov rcx, 24
div rcx
mov [rbp - 32], QWORD rax
; years
cqo
mov rcx, 365
div rcx
mov [rbp - 40], QWORD rax
mov rsi, QWORD [rbp - 8]
mov rdx, QWORD [rbp - 16]
mov rcx, QWORD [rbp - 24]
mov r8, QWORD [rbp - 32]
mov r9, QWORD [rbp - 40]
lea rdi, [rel format]
call _printf
mov rax, SYS_exit
mov rdi, 0
syscall
section .data
format: db "%lu seconds", 10, "%lu minutes", 10, "%lu hours", 10, "%lu days", 10, "%lu years", 10, "since the Epoch (01-01-1970 00:00:00 UTC).", 10