0
global median
section .text
median: 
    xor rax,rax ; Initialize rax to zero
    cmp rsi, 0; 
    jle finish ;
next:
    mov rcx, 0;
    not rcx;

outer:
    inc rcx;
    mov eax, rcx;
    cmp rcx, rsi;
    jl inner;
    cmp rcx, rsi;
    je mid;
    
inner:
    inc eax;
    cmp eax, rsi;
    jge outer;
    mov r10, [rdi+rcx*8];
    mov r11, [rdi+eax*8];
    cmp r10, r11;
    jg swap;
    
swap:
    mov r9,r10;
    mov r10,r11;
    mov r11,r9;
    cmp eax, rsi;
    jl inner;
mid:
    mov rax, [rdx];
finish:
    ret

Line 24: error: Impossible combination of address sizes. Line 24: error: Invalid effective address.

I'm trying to create the object file using the following command.

nasm -felf64 median.asm

I would appreciate it if someone could help me with this one.

  • Registers in an addressing mode all have to be the same size. Since `eax` is correctly zero-extended to RAX (by `inc eax`), you can use `[rdi + rax*8]`. – Peter Cordes Sep 10 '22 at 17:50
  • Also, if you want `rcx = -1`, just do that with `mov rcx, -1`; that's more efficient than `mov rcx, 0` / `not rcx`. – Peter Cordes Sep 10 '22 at 17:51

0 Answers0