Skip to content

Instantly share code, notes, and snippets.

@mshroyer
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mshroyer/9794764 to your computer and use it in GitHub Desktop.
Save mshroyer/9794764 to your computer and use it in GitHub Desktop.
;; nasm -f elf64 prog.asm && gcc -o prog prog.o
%define under 1000
section .data
output:
db "Result: %lu",10,0
section .text
extern printf
global main
main:
mov rsi, 0
mov rcx, 3
_mult_3: ; Add multiples of 3
add rsi, rcx
add rcx, 3
cmp rcx, under
jl _mult_3
mov rcx, 5
_mult_5: ; Add multiples of 5
add rsi, rcx
add rcx, 5
cmp rcx, under
jl _mult_5
mov rcx, 15
_mult_15: ; Remove multiples of 15 because they've
sub rsi, rcx ; been counted twice
add rcx, 15
cmp rcx, under
jl _mult_15
xor rax, rax
mov rdi, output
call printf
mov rax, 0
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment