0

Here is my code. If I half the size of the binary value to 32-bits, it works, but as soon as I try 33 bits or higher, I get "error A2071: initializer magnitude too large for specified size"

Here is my code:

.data

.code
    ASM_ADD proc
        mov rax, 1111111111111111111111111111111111111111111111111111111111111111b
        mov rbx, 1
        
        add rax, rbx
        ret
    ASM_ADD endp
end

As far as I know, rax is a 64-bit register and if I use the actual numeric representation of this binary number (i.e 18,446,744,073,709,551,615 = 2^64 - 1), then it works...but if I try with 33 or more actual bit values, the program won't assemble

Does anyone know how to fix this?

Thanks

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 1
    What MASM version? Does it actually have the right value in the machine code for 32 `1` bits? If this is a current version of MASM, you could just use a better assembler that doesn't have problems parsing 64-bit binary literals like this, such as NASM. That line assembles just fine with NASM version 2.15.05, to the expected `48 c7 c0 ff ff ff ff mov rax,0xffffffffffffffff`. (Or if there was one fewer `1` bit, so it couldn't be represented as a 32-bit sign-extended value, then you'd get `mov r64, imm64`.) – Peter Cordes Dec 16 '21 at 03:30
  • 2
    For numbers with that many bits, I find hex is more readable even of I'm interested in individual bits. – lurker Dec 16 '21 at 03:57
  • @PeterCordes I downloaded Visual Studio 2022 and use the assembler that was bundled with that, so assume it's a recent version. I can't seem to find out. I was struggling to load hex values into registers with 0x and h, though found I could use hex values with a leading 0 - like 0ffffh. I'm still getting some weird behaviour, so I'll have another look this weekend. Thanks though – RandomUser123 Dec 17 '21 at 08:33
  • 1
    MASM only allows trailing-h like 0DEADBEEFh, not C style 0xDEADBEEF. The leading 0 disambiguates from symbol names like DEADBEEFh. [How to represent hex value such as FFFFFFBB in x86 assembly programming?](https://stackoverflow.com/q/11733731) – Peter Cordes Dec 17 '21 at 08:38

0 Answers0