Last active
August 29, 2015 13:57
-
-
Save mshroyer/9794764 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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