1,105,386 Community Members

error in 2nd loop

MrMicro
Newbie Poster
2 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

i have problem in this code it work well in 1st loop then its bug as si and di still the same and making alot of jumps without any change
this code sorting descending

jmp strXt0
arr dw 0x1,0x9,0x3,0x2,0x7,0x3,0x6,0x4,0x9,0x5
arr_e equ $
strXt0:
mov si, arr
mov di, arr+2
mov cx, 0
srto_l:
mov al, [si]
cmp al, [di]
jg swap
srto_retrnx:
add [si], 2
add [di], 2
cmp [di], arr_e
jz prgnmxexit 
jmp strXt0
swap:
xchg al, [di]
mov [si], al
mov al, [si+1]
xchg al, [di+1]
mov [si+1], al
inc cx
jmp srto_retrnx
prgnmxexit:
or cx, cx
jz done   
jmp strXt0
done:

so any 1 can help me whats the error?

Member Avatar
ShiftLeft
Light Poster
38 posts since Jun 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

In lines 13 & 14, what you want to be doing is incrementing the pointer, not adding two to the contents of where they are pointing.

    add     si, 2
    add     di, 2

or

    inc     si
    inc     si
    inc     di
    inc     di

then

    cmp     di, arr_e
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article