Problem 5 on Project Euler with x86 Assembly

In order to practice x86 Assembly (NASM especifically) I am solving some problems on Project Euler with it. Here’s problem 5:

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

And the solution:

.globl main

        pushl %ebp
        movl %esp, %ebp

        movl $50, %ecx
                movl $2, %esi
                        cmp  $21, %esi
                        je found
                        movl $0, %edx
                        movl %ecx, %eax
                        idiv %esi
                        cmp  $0, %edx
                        je noRemainder
                        add $1, %ecx
                        jmp loop
                        add $1, %esi
                        jmp divisionLoop
        pushl %ecx
        pushl $string2
        call printf

        movl %ebp, %esp
        popl %ebp

        movl $0, %eax
string2: .string "result=%dn"

Leave a Reply

Your email address will not be published. Required fields are marked *