Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
alyx17528yDon't assembly instructions typically have the destination register on the left? Example:
movq foo, bar
would move from bar into foo.
Looks like you've got your operands the wrong way around. -
If you mean it cant compile, try add % for registers.
If you mean the style is wrong, it is becoz you should use a stack frame for function http://stackoverflow.com/questions/... -
olirz968yYou should not use rpb since is the base pointer of the stack frame. If you use it you need to restore it before the ret instruction. Either do
movq %rdi, %rax
addq $1, %rax
ret
Or
push %rbp
movq %rdi, %rbp
addq $1, %rbp
movq %rbp, %rax
pop %rbp
ret
Need help. Explain why assembly code is wrong.
C code:
long f(long n) {return n + 1} ;
Assembly:
f:
movq rdi, rbp
addq $1, rbp
movq rbp, rax
ret
undefined