visual c++ - Using relative values in array sorting ( asm ) -


i need sort through array , sort each individual row in array in ascending order. doesn't seem going (surprise!) keep getting hit 2 errors:

a2101: cannot add 2 relocatable labels , a2026: constant expected

here's sort, makes sense me, think i'm still trying implement high-lvl language techniqes assembly. there way around not being able use relative values? (the array 7 rows 9 columns, btw).

mov cx, 7; cx = number of rows  outer: ; outer loop  walk through rows    push cx    mov cx, 9   mov row, cx ;rows      middle: ; middle-loop walk through columns        push cx       sub cx, 1  ;cx = cx-1       mov column, cx  ;columns           inner:  ;inner loop - compare , exchange column values                    cmp marray[row*9 + column], marray[row*9 + column+1]                   xchg marray[row*9 + column+1], marray[row*9 + column]                   ; compare , exchange values marray table                   inc column           loop inner        pop cx     loop middle ;end middle loop    pop cx  loop outer ; end outer loop  ret 

thanks help.

the following lines problematic:

cmp marray[row*9 + column], marray[row*9 + column+1] xchg marray[row*9 + column+1], marray[row*9 + column] 

unlike hll, assembly not allow arbitrary expressions in place of constants or variables. that's why hll's invented in first place. calculate offset in registers before using:

mov ax, row mov bx, ax shr bx, 3 ; bx = row*8 add bx, ax ; bx = row*9 add bx, column ; bx = row*8+column mov dx, [bx] ;first comparand inc bx cmd dx, [bx] ; that's compare! 

also, don't use branching; cmp instruction utterly pointless; waste result, , xcng not executed conditionally. read on conditional jump commands (jz/jnz etc.).

also, hope exercise, not real project. if it's real, please reconsider using assembly. trivial this, assembly wrong, wrong choice. espec. considering how bad @ it.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -