Is NASM inconsistent, or am I just not seeing the obvious fact of immediate CMP?

“Warning: a signed dword immediately exceeds the bounds” is the current issue of my existence as it seems inconsistent or I just don’t see the obvious fact.

I declare the following structure:

struc FRTType .class resq 1 ; Class .type resq 1 ; Type endstruc 

I have the following assignments:

 %assign TYPE_SCALAR 0xfffffffffffffff1 %assign INTEGER 0xffffffff1000a8a9 

And in the function I have:

 cmp qword [rdi+FRTType.class], TYPE_SCALAR ; This works fine jne .exception cmp qword [rdi+FRTType.type], INTEGER ; THIS PRODUCES WARNING 

I know that I can mov rax, INTEGER and then perform a comparison, but this seems unnecessary since the first comparison has no problems.

+8
assembly x86-64 nasm
source share
1 answer

No CMP r/m64,imm64 .
There CMP r/m64,imm32 , where imm32 expands to 64 bits. This works fine for 0xfffffffffffffff1 , because 0xfffffff1 with a character extension of 64 bits is 0xfffffffffffffff1 . But 0x1000a8a9 sign-extended up to 64 bits is 0x000000001000a8a9 , which is different from the value you wanted to compare.

You could overcome this, for example, by first loading immediately into the register:

 mov rax, INTEGER cmp qword [rdi+FRTType.type], rax 
+10
source share

All Articles