Author Topic: compiled instruction contains flaw  (Read 18091 times)

nobody

  • Guest
compiled instruction contains flaw
« on: November 20, 2008, 08:46:21 PM »
Hello !

(also posted in Beginner Questions Forum, but no answer to latest update)

I have the following problem (using SUSE LINUX 11 with NASM version 2.05.01 compiled on Nov 7 2008, LATEST).

I program 64bit assembly code and the following code does not execute properly after code generation with nasm:

mov r9,[memoryvalue] = 08900000000000089h
and r9,0ff00000000000000h

yields 0x0 in r9
--> incorrect !


This code works fine, but not the way I want it:

mov r9,[memoryvalue]
mov rax,0ff00000000000000h
and r9,rax  

yields 0x089 in r9
--> correct

Could someone please fix it.... starting to use this command more often and it becomes annoying to
use the additional register.


Many thanks

Bjoern

nobody

  • Guest
Re: compiled instruction contains flaw
« Reply #1 on: November 20, 2008, 08:50:24 PM »
... and

the cmp command does not compile either.

e.g.

cmp rcx,0900 0000 0000 0000h

--> error (compiles with warning, but debugging shows that it's not like above)

only

mov rax,0900 0000 0000 0000h
cmp rcx,rax

works.


Thanks,
Bj

nobody

  • Guest
Re: compiled instruction contains flaw
« Reply #2 on: November 24, 2008, 02:44:10 PM »
Check out either the AMD64 or Intel Architecture manuals -- the only instruction that supports a 64bit immediate operand is MOV.  AND & CMP (and any other instructions) take only 32bit immediate operands at most, even when using the 64bit forms of those instructions.  So this is why your examples that use MOV to load the 64bit immediate work, but the others do not.

Were you getting any warnings when compiling?  If not maybe you should put in a request to the NASM people (not me :) to have some sort of warning emitted when using a 64bit immediate on anything other than MOV.