I just started learning assembly programming. I am using NASM on Linux.
I wrote this code that's basically meant to calculate the somethingth power of something and I know it's probably not exactly good, but I really don't care at this point, all I want is just SOME idea why I keep getting that error, because I have tried to modify and switch operands and operations and everything in the section where the problem is, but if anything that only gave me more error messages. As I said, I'm really, really new to this whole stuff and I might just be stupid.
The Problem must be in one of these lines. If you need it, of course I'll post more of the code, I just don't want you to have to go though 70-80 lines of weird, unnecessarily complicated code. I just want to know what COULD be a possible reason for this happening, because I'm really, really desperate right now and also I have reached the point where thinking about it and not having any new thoughts just makes everything worse.
...
mov dword [power], 2
mov ecx, 0
while:
mov eax, [neededforloop]
cmp eax, ecx
je endwhile
mov eax, [power]
mul eax, 2
mov [power], eax
mov eax, ecx
add eax, 1
mov ecx, eax
jmp while
Surely nasm has given you the line number ... that should have pointed you at mul eax, 2
. In turn, you should have then looked that instruction up in the reference manual and noticed that there is no mul
instruction that accepts an immediate as an operand. There is such a one for imul
though.
TL;DR: change mul eax, 2
to imul eax, 2
(which is really a shorthand for imul eax, eax, 2
).
PS: You should use shifts to multiply by 2.
imul r, r/m
and imul r,r/m,imm
forms that you can use for signed or unsigned. As well as widening one-operand signed multiply.