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 :)
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
- Refreshment of knowledge in Assembly
- Don't
movbigger registers in smaller - How the
divinstruction works, but also that it's considered as slow
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.
- How to perform an integer cast in assembly
- How can I do a modulo operation without the
divinstructoin?
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.
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.
testinstruction and the difference betweencmp- Making the life easier with the
~/.gdbinitfile
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.
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.