We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,348 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

error in 2nd loop

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?

2
Contributors
1
Reply
3 Hours
Discussion Span
5 Months Ago
Last Updated
2
Views
MrMicro
Newbie Poster
2 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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
ShiftLeft
Light Poster
31 posts since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.2873 seconds using 2.71MB