Posts Tags Categories About
x86-64汇编

求平方和

用汇编计算: $1^2 + 2^2 + \cdots + 10^2$

section .data

SUCCESS  equ 0  ; Successful operation
SYS_EXIT equ 60 ; call code for terminate

n   dd 10
sum dd 0

section .text

global _start

_start:
    mov ebx, 1
    mov ecx, dword [n]

sum_loop:
    mov eax, ebx
    mul eax
    add dword [sum], eax
    inc ebx
    loop sum_loop

last:
    mov rax, SYS_EXIT
    mov rdi, SUCCESS
    syscall