-
Notifications
You must be signed in to change notification settings - Fork 0
/
006.asm
37 lines (31 loc) · 1.02 KB
/
006.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
section .data
msg db "%d", 10, 0 ;return string for printf (just the result)
section .text
extern printf
global main
main:
mov edi, 1 ;counter
xor ebx, ebx ;for the square of sum
xor ecx, ecx ;for the sum of squares
calc:
add ebx, edi ;add current number to sum
mov eax, edi ;put current number in eax
mul edi ;square it
add ecx, eax ;add result to sum of squares
inc edi ;increase number
cmp edi, 100 ;check if we reached 100
jle calc ;if not, continue loop
mov eax, ebx ;else put sum in eax
mul ebx ;square the sum
sub eax, ecx ;subtract sum of squares
print: ;printing routine, differs slightly from OS to OS
push rbp
mov edi, msg
mov esi, eax
call printf
pop rbp
exit: ;exit routine, dito
mov eax, 1
xor edi, edi
syscall
section .note.GNU-stack ;just for gcc