Hello everyone! I'm very new assembly language, but not new to programming. So I'm reading This book and I'm about half way through it and I get the feeling I'm not really getting a very deep knowledge of assembly. It's teaching me how to write assembly programs, so long as I don't want to do anything tricky. So, I'm wondering if anyone knows of a book that gives a deep knowledge of assembly. To be clear, I'm not talking about what assembly does. I get that, I wrote a simple assembler for a very simple computer that I designed once. But I mean things like, Header files, what really are these? are they just (pre/ap)pended to the assembly file. Mainly just things that really let me know what's going on.
For my + one simple question:
I'm practicing the little assembly I know and I was writing a program to sum all the even numbered Fibonacci numbers up to 4,000,000. The problem is that the answer is greater that a double-word can hold. So I used a quad-word in memory but when I try to add the register(double-word) to the memory(quad-word), I can't.
I tried 'cdq' but it gave me the same error(that the sizes didn't match). How would I go about doing this?
I am 64 bit, so I could use rax, but I'd rather understand how to do this.
Thanks, I appreciate any help!
For my + one simple question:
I'm practicing the little assembly I know and I was writing a program to sum all the even numbered Fibonacci numbers up to 4,000,000. The problem is that the answer is greater that a double-word can hold. So I used a quad-word in memory but when I try to add the register(double-word) to the memory(quad-word), I can't.
I tried 'cdq' but it gave me the same error(that the sizes didn't match). How would I go about doing this?
I am 64 bit, so I could use rax, but I'd rather understand how to do this.
Thanks, I appreciate any help!
Hi Shaqy,
I'm not sure it'll give you a deeper understanding of assembly, but I've been using Professional Assembly Language by Blum, and its treatment of the integer and floating-point maths is quite good (if you can forgive the many errata).
Regards
Michael
I'm not sure it'll give you a deeper understanding of assembly, but I've been using Professional Assembly Language by Blum, and its treatment of the integer and floating-point maths is quite good (if you can forgive the many errata).
Regards
Michael
You can find many answers to questions right here on this board simply by searching.
You can also use Intel's Reference Manuals.
Unfortunately, there are little to no modern day paper books to read.
Google is your friend.
You can also use Intel's Reference Manuals.
Unfortunately, there are little to no modern day paper books to read.
Google is your friend.
Ah... just had a thought: have a look through Agner Fog's asmlib library for some great examples of optimized algorithms. Lots of amazing assembler idioms in there.
I tried 'cdq' but it gave me the same error(that the sizes didn't match). How would I go about doing this?
The beauty of assembly is that things can often be done in many different ways. Here's how I would do it using strictly 32-bit registers and memory variables.
.data
sum dd 0,0 ;you can later refer to sum as a qword
.code
;use eax and ecx to hold the last two Fibonacci numbers
xor eax,eax ;initialize them
mov ecx,1
nextfib:
add eax,ecx
cmp eax,4000000
ja finish
test eax,1
jnz noteven
add sum,eax
adc sum[4],0 ;increment the upper 32-bit if overflow of the lower 32-bit of the sum
noteven:
xchg eax,ecx
jmp nextfib
finish:
...
If I was using 64-bit instructions, it would be even easier by using another 64-bit register to accumulate the sum.
sub rax,rax
mov rcx,1
sub rdx,rdx ;initialize to hold the sum
nextfib:
add rax,rcx
cmp rax,4000000
ja finish
test rax,1
jnz noteven
add rdx,rax
noteven:
xchg rax,rcx
jmp nextfib
finish:
... ;answer in rdx