-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmall_mult.asm
More file actions
85 lines (50 loc) · 1.1 KB
/
small_mult.asm
File metadata and controls
85 lines (50 loc) · 1.1 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
global _start
extern printf
section .text
_start:
mov rax, 2
iter_next:
mov rdi, rax
push rax
call test_divis
cmp rax, 1
pop rax
je print_result
add rax, 2
jmp iter_next
test_divis:
xor eax, eax
; It must be an even number
test edi, 01h
jnz complete_divis
mov ebx, 3 ; the current divisor we test
iter_divis:
cmp ebx, 20
jle next_trial
inc eax
jmp complete_divis
next_trial:
xor edx, edx
push rax
mov eax, edi
idiv ebx
pop rax
cmp edx, 0
jne complete_divis
add ebx, 1
jmp iter_divis
complete_divis:
ret
print_result:
mov rdi, format
mov rsi, rax
xor rax, rax
call printf
mov rax, 60
mov rdi, 0
syscall
ret
section .data
format:
db "%ld", 10, 0
; vim: ft=nasm :