1

I am trying to declare an array size of 10 double words and then sort them. I would like this to work even when the array size is changed. Below is my code:


        segment .data
    a   dd  14, 10, 23, 45, 17, 9, 54, 22, 1, 76
    size dd 10


        segment .text

    compare:
    mov ax, 0   ;counter
    mov bx, [a + ax]
    cmp bx, [a + ax + 4]
    jb swapnumb

    ;swap numbers
    mov cx, [a + ax + 4]
    mov [a + ax + 4], bx
    mov [a + ax], cx

    notswap:
    add ax, 4
    jmp compare
        ret

I am receiveng the following errors:

SortSearch.asm:10: error: impossible combination of address sizes
SortSearch.asm:10: error: invalid effective address
SortSearch.asm:11: error: impossible combination of address sizes
SortSearch.asm:11: error: invalid effective address
SortSearch.asm:15: error: impossible combination of address sizes
SortSearch.asm:15: error: invalid effective address
SortSearch.asm:16: error: impossible combination of address sizes
SortSearch.asm:16: error: invalid effective address
SortSearch.asm:17: error: impossible combination of address sizes
SortSearch.asm:17: error: invalid effective address

Anyone have any suggestions?

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
Defqon
  • 117
  • 11
  • 1
    You can't use `ax` in address calculations in 16-bit 8086 instructions. You need to use `bx`, `si`, or `di`. – 1201ProgramAlarm Mar 05 '20 at 16:52
  • If you want to be able to use any register in addressing modes, don't write 16-bit code. Older x86 is *harder* to program, not simpler. – Peter Cordes Mar 05 '20 at 18:07
  • You `a:` is an array of dwords, but you're using 16-bit loads. That can only work if you ignore the upper 2 bytes of every element. (Which works here since they're always zero.) – Peter Cordes Mar 05 '20 at 21:53

0 Answers0