-
Notifications
You must be signed in to change notification settings - Fork 16
/
leapyear.asm
95 lines (89 loc) · 1.22 KB
/
leapyear.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
83
84
85
86
87
88
89
90
91
92
93
94
95
segment .data
a: dq 0
b: dq 0
first: dq 0
last: dq 0
sum1: dq 0
sum2: dq 0
flag: dq 0
cnt: dq 0
cnt1:dq 0
newline: dq "",10,0
fmt: dq "%lld ",10,0
fmt_in: dq "%lld", 10,0
fmtshow: dq "%lld is leapyear" ,10,0
fmt_out: dq "total leap year between %lld and %lld is %lld", 10, 0
segment .bss
array resq 21
segment .text
global main
extern printf
extern scanf
main:
push RBP
mov RAX, 0
mov RCX, 0
mov RBX, 0
mov [a] ,rax
INPUT:
mov RAX, 0
mov RDI, fmt_in
mov RSI, first
call scanf
mov RAX, 0
mov RDI, fmt_in
mov RSI, last
call scanf
init:
mov rcx , [first]
loop:
mov rbx ,[last]
cmp rcx,rbx
jg printcount
mov [cnt] ,rcx
checkleapyear:
mov rdx ,0
mov rax ,[cnt]
mov rbx , 400
div rbx
cmp rdx ,0
jz printleapyear
mov rdx ,0
mov rax ,[cnt]
mov rbx ,100
div rbx
cmp rdx ,0
jz lastpartloop
mov rdx ,0
mov rax ,[cnt]
mov rbx , 4
div rbx
cmp rdx ,0
jz printleapyear
lastpartloop:
mov rcx ,[cnt]
inc rcx
mov [cnt] ,rcx
jmp loop
printleapyear:
mov rbx ,[a]
inc rbx
mov [a] ,rbx
mov rax ,0
mov rdi ,fmtshow
mov rsi ,[cnt]
call printf
mov rax ,0
mov rdi ,newline
call printf
jmp lastpartloop
printcount:
mov rdi ,fmt_out
mov rsi ,[first]
mov rdx ,[last]
mov rcx ,[a]
call printf
END:
mov RAX, 0
pop RBP
ret