Assembler error: bit-bit 64-bit does not support absolute 32-bit addresses

So, I am learning the x86_64 nasm build on my Mac for fun. After greeting the world and some basic arithmetic, I tried to copy a little bit more advanced global program hello from this site and change it to a 64-bit version of intel, but I can not get rid of this error message: hello.s:53: error: Mach-O 64-bit format does not support 32-bit absolute addresses. Here is the command I use to build and links: nasm -f macho64 hello.s && ld -macosx_version_min 10.6 hello.o. And here is the corresponding line:

cmp rsi, name+8

rsi is the register that I use for my index in a loop, and name is a four-digit word reserved for user input, which is the name that is already written for this item.

Here is part of the code (to see the rest, click the link and go to the bottom, the only difference is that I use 64-bit registers):

loopAgain:
mov al, [rsi]           ; al is a 1 byte register
cmp al, 0x0a            ; if al holds an ascii newline...
je exitLoop             ; then jump to label exitLoop

; If al does not hold an ascii newline...
mov rax, 0x2000004      ; System call write = 4
mov rdi, 1              ; Write to stdout = 1
mov rdx, 1              ; Size to write
syscall

inc rsi

cmp rsi, name+8         ; LINE THAT CAUSES ERROR
jl loopAgain
+5
source share
2 answers

The instruction cmpdoes not support the 64-bit direct operand. Thus, you cannot put a 64-bit link of an immediate address in one of your operands - load name+8in the register (using regular MOV), and then compare with this register.

, Intel ISA (: PDF). CMP, CMP r/m32, imm32 CMP r/m64, imm32, 32- 32- 64- , CMP r/m64, imm64. MOV r64, imm64.

nasm , MOV rcx, name+8 ​​nasm. nasm ( , , nasm, , ). name:

name:
    resb 8
name_end:

MOV rcx, name_end. , name. , clang GNU binutils.

+3

, , , : Mach-O , , , . , name , , .

, , , , GCC. ,

static unsigned global_var;
unsigned inc(void)
{
    return ++global_var;
}

_inc:
    mflr r0                                           ; Save old link register
    bcl 20,31,"L00000000001$pb"                       ; Jump
"L00000000001$pb":
    mflr r10                                          ; Get address of jump
    mtlr r0                                           ; Restore old link register
    addis r2,r10,ha16(_global_var-"L00000000001$pb")  ; Add offset to address
    lwz r3,lo16(_global_var-"L00000000001$pb")(r2)    ; Load global_var
    addi r3,r3,1                                      ; Increment global_var
    stw r3,lo16(_global_var-"L00000000001$pb")(r2)    ; Store global_var
    blr                                               ; Return

, PowerPC, Mach-O ABI x86-64. PowerPC , , . , x86-64 .

(. GCC, -O2. -O0, .)

? ( ), :

  • ,
  • C.

, , , ABI. ABI - ! ABI , , . , LibSDL , libc memcpy ( ) .

+3

All Articles