Is there any easy way (simple) way to flip array

Started by ilian007, December 01, 2009, 11:50:05 PM

Previous topic - Next topic

ilian007

Is there any easy way (simple) way to flip array,

for example Arr1 4,13,2,8,5 to become Arr1 5,8,2,13,4

just simple command not to use whole procedure to exchange numbers .. just to change the start of the array or something .. ?


thanks

dedndave

well - not really
i mean - there is no special instruction intended for that
you just have to write a little loop that picks up a byte at each end, swaps them, then moves toward the center for the next one
something like this...

        mov     di,offset Arr1
        mov     si,offset Arr1+sizeof Arr1-1

swap_loop:
        mov     al,[si]
        mov     ah,[di]
        mov     [di],al
        mov     [si],ah
        inc     di
        dec     si
        cmp     si,di
        ja      swap_loop

well, that's one way to do it - lol

drizz

The truth cannot be learned ... it can only be recognized.

dedndave

lol drizz - you are starting to sound like JJ
i am guessing it is a numeric string that he wants to display - lol
i would try building it the opposite direction to begin with   :bg
listen to me - now i am starting to sound like JJ - lol

http://www.masm32.com/board/index.php?topic=12816.msg98960#msg98960

raymond

There's one precaution you should take with Dave's suggested procedure: either
i) make sure the ES segment register is identical to the DS segment register (DI defaults to the ES segment unless specified otherwise)
or
ii) include DS as a segment override when using the DI register, such as
mov ah,ds:[di]
mov ds:[di],al

When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

sinsi

QuoteDI defaults to the ES segment unless specified otherwise
Only on string ops, surely? The only one to watch for is any access to [bp] which defaults to SS.
Light travels faster than sound, that's why some people seem bright until you hear them.

dedndave

DI references ES only for string instructions - for other instructions, it references DS
what sinsi said - i just wanted to clarify for MGG

ilian007

oh Ok I guess I will use another way to solve the problem that one seems too dificult. DednDave I am trying to code the 3rd method for Bubble sort and thinking of ways to make it possible.