-
Notifications
You must be signed in to change notification settings - Fork 0
/
028.asm
35 lines (29 loc) · 911 Bytes
/
028.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
section .data
msg db "%lld", 10, 0 ;return string for printf (just the result)
section .text
extern printf
global main
main:
mov edi, 4 ;init edi (loop counter)
mov ebx, 1 ;init total
mov esi, 1 ;intermediate sum
sum:
mov eax, edi ;copy counter
shr eax, 2 ;divide by 4
shl eax, 1 ;multiply by 2
add esi, eax ;intermediate sum += result
add ebx, esi ;add to total
inc edi ;increase counter
cmp edi, 2004 ;limit = 2 * size + 2
jl sum ;if lower, repeat
print: ;printing routine, differs slightly from OS to OS
push rbp
mov edi, msg
mov esi, ebx
call printf
pop rbp
exit: ;exit routine, dito
mov eax, 1
xor edi, edi
syscall
section .note.GNU-stack ;just for gcc