; sumofsquares.asm
; by renzo diomedi
; to calculate the sum of square from 1 to n
;
;
section .data
;
EXIT_SUCCESS equ 0          ; successful exit
SYS_exit equ 60             ; call code to terminate
;
n dd 10
sumofsquares dq 0
;
;
section .text;
global _start
_start:
;
;  for (i=1; i<=n; i++)
;      sumofsquares += i^2;
mov rbx, 1                   ; i
mov ecx, dword [n]
;
sum_loop: 
mov rax, rbx                 ; get i
mul rax                      ; i^2
add qword [sumofsquares], rax
inc rbx
loop sum_loop
;
;
;
last:
 mov rax, SYS_exit         
 mov rdi, EXIT_SUCCESS     
 syscall
