Created
May 31, 2016 17:19
-
-
Save mclosson/63dd438be2db002738bd8dd1779ae29f 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
# https://projecteuler.net/problem=1 | |
# sum the nautural numbers below 10 that are multiples of 3 or 5 | |
.section .text | |
.globl _start | |
_start: | |
pushl $1 # counter | |
pushl $0 # sum | |
loop_start: | |
cmpl $10, 4(%esp) | |
jge loop_end | |
xorl %edx, %edx | |
movl 4(%esp), %eax | |
movl $3, %ebx | |
idiv %ebx | |
cmpl $0, %edx | |
je add_number | |
xorl %edx, %edx | |
movl 4(%esp), %eax | |
movl $5, %ebx | |
idiv %ebx | |
cmpl $0, %edx | |
je add_number | |
incl 4(%esp) | |
jmp loop_start | |
add_number: | |
movl 4(%esp), %eax | |
addl %eax, (%esp) | |
incl 4(%esp) | |
jmp loop_start | |
loop_end: | |
movl (%esp), %ebx | |
movl $1, %eax | |
int $0x80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment