0

I'm trying to write a function in assembly that converts bytes to uppercase using a lookup table

I'm pretty new to masm so this may be a simple fix, but for some reason my code is giving me compile time errors. The official MS docs on the error (https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2017?f1url=%3FappId%3DDev16IDEF1%26l%3DEN-US%26k%3Dk(LNK2017)%26rd%3Dtrue&view=msvc-170) claim that this happens when assembling a 32 bit application in 64 bit mode (or something like that)

here is my code:

.data
lut:
db 00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h, 08h, 09h, 0Ah, 0Bh, 0Ch, 0Dh, 0Eh, 0Fh
db 10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h, 18h, 19h, 1Ah, 1Bh, 1Ch, 1Dh, 1Eh, 1Fh 
db 20h, 21h, 22h, 23h, 24h, 25h, 26h, 27h, 28h, 29h, 2Ah, 2Bh, 2Ch, 2Dh, 2Eh, 2Fh 
db 30h, 31h, 32h, 33h, 34h, 35h, 36h, 37h, 38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh 
db 40h, 41h, 42h, 43h, 44h, 45h, 46h, 47h, 48h, 49h, 4Ah, 4Bh, 4Ch, 4Dh, 4Eh, 4Fh 
db 50h, 51h, 52h, 53h, 54h, 55h, 56h, 57h, 58h, 59h, 5Ah, 5Bh, 5Ch, 5Dh, 5Eh, 5Fh 
db 60h, 41h, 42h, 43h, 44h, 45h, 46h, 47h, 48h, 49h, 4Ah, 4Bh, 4Ch, 4Dh, 4Eh, 4Fh 
db 50h, 51h, 52h, 53h, 54h, 55h, 56h, 57h, 58h, 59h, 5Ah, 7Bh, 7Ch, 7Dh, 7Eh, 7Fh
.code
conversionFunction proc
    movsxd  rax, edi
    mov al, byte ptr [rax + lut]
    ret
conversionFunction endp
end
Badasahog
  • 348
  • 1
  • 18
  • 1
    `[rax + lut]` needs to fit `lut`'s absolute address into a 32-bit sign-extended `[disp32 + reg]`. You can't do that in a LargeAddressAware program, same as [32-bit absolute addresses no longer allowed in x86-64 Linux?](https://stackoverflow.com/q/43367427) More specifically for array indexing, see [Mach-O 64-bit format does not support 32-bit absolute addresses. NASM Accessing Array](https://stackoverflow.com/q/47300844) - the necessary RIP-relative LEA is about the same, although MASM doesn't use the `rel` keyword. (Also, I'd recommend using `movzx` or `movsx` as the byte load.) – Peter Cordes May 03 '22 at 10:44

0 Answers0