Skip to content

Jeremy-Glaus/Assembly-Project-Euler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Euler in Assembly

In this repository, I will show the procress of me solving coding challenges by project euler.

The aim of this project is not to provide perfect solutions. It's about learning by doing those challenges and identifying issues within the solutions.

For each problem, I will write down some learnings I did while the process, identify issues to fix them maybe in the future, record questions and compare my code to other solutoins from project euler.

So yes, if you're not bored yet, then I wish you fun and malicious joy while I'm doing this :)

Problem 1: Multiples of 3 or 5

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. -- https://projecteuler.net/problem=1

Learnings

  • Refreshment of knowledge in Assembly
  • Don't mov bigger registers in smaller
  • How the div instruction works, but also that it's considered as slow

Issues

The sys_write syscall currently is not working as intended. The problem is that it inteprets the input as ASCII and outputs as it. Regarding to research, an integer cast for the output would be required.

A cause of this problem, the program doesn't output a solution to the console. For checking if the calculations are correct, a debugger is required.

Questions

  • How to perform an integer cast in assembly
  • How can I do a modulo operation without the div instructoin?

Comparason with other solutions

One of the shared solutions has chosen a different approach: Instead of doing the logic with conditional jumps, two loops have been used. Those these do either 3 or 5 steps and add them up.

The second solution in assembly I found doesn't use the concept of a for loop. Instead of returns as I used in my code, other sections are "jumped on". This makes the code a bit smaller.

Problem 2: Even Fibonacci numbers

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

--https://projecteuler.net/problem=2

Learnings

  • test instruction and the difference between cmp
  • Making the life easier with the ~/.gdbinit file

Issues

Due do the problem with the integer cast described in Problem 1, there is no output of the program and the value has to be red out of gdb.

Comparason with other solutions

Comparing my code with other solutions, I discovered the xadd instruction. This instruction swaps the values from the registers and adds them together in a second step. Using this, the code can be made a little smaller.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors