943,694 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 939
  • Assembly RSS
Dec 7th, 2008
0

Doesn't work, any idea?

Expand Post »
It is meant to count the first two numbers in the array and then place them in ascending order, but sth wrong. Any idea?

assembly Syntax (Toggle Plain Text)
  1. Code segment
  2.  
  3.  
  4.  
  5. jmp main
  6.  
  7. add1 dw 9,3,2,7,1,4,2,5,8,1
  8.  
  9.  
  10.  
  11. main: mov si,0
  12.  
  13. call orderab
  14.  
  15. exit: mov ax,04c00h
  16.  
  17. int 21h
  18.  
  19.  
  20.  
  21.  
  22.  
  23. orderab: cmp add1[si],add1[si+2]
  24.  
  25.  
  26.  
  27.  
  28.  
  29. jle finish
  30.  
  31. mov ax,add1[si]
  32.  
  33. mov bx,add1[si+2]
  34.  
  35. mov add1[si],bx
  36.  
  37. mov add1[si+2],ax
  38.  
  39. finish: ret
Last edited by Ancient Dragon; Dec 7th, 2008 at 7:54 pm. Reason: add code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
windany is offline Offline
7 posts
since Dec 2008
Dec 7th, 2008
0

Re: Doesn't work, any idea?

You're telling it to compare two elements away from the first one, being the third one not the second one.
http://www.geocities.com/SiliconVall.../asml1012.html
Reputation Points: 888
Solved Threads: 114
Nearly a Posting Virtuoso
MosaicFuneral is offline Offline
1,270 posts
since Nov 2008
Dec 7th, 2008
0

Re: Doesn't work, any idea?

yes i changed +2 to +1, but it still doesn't work, it has a small bug.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
windany is offline Offline
7 posts
since Dec 2008
Dec 8th, 2008
0

Re: Doesn't work, any idea?

; because "cmp" instruction doesnt accept two memory operands
; CMP r , r/i
; CMP m , r/i
; instead of "cmp add1[si],add1[si+2]"
; try:
mov dx, add1[si]
cmp dx, add1[si + 2]
Reputation Points: 40
Solved Threads: 4
Junior Poster in Training
low_coder is offline Offline
55 posts
since Nov 2008
Dec 8th, 2008
0

Re: Doesn't work, any idea?

I managed to make it work but it only compares the first two elements of the array, i want it to keep comparing until it gets to the end of the array...
Assembly Syntax (Toggle Plain Text)
  1. Code segment
  2.  
  3. jmp main
  4. add1 dw 9,3,2,7,1,4,2,5,8,1
  5.  
  6. main: mov si,0
  7. call orderab
  8.  
  9. exit: mov ax,04c00h
  10. int 21h
  11.  
  12.  
  13. orderab: mov ax,add1[si]
  14. cmp ax,add1[si+2]
  15.  
  16. jle finish
  17. mov bx,add1[si+2]
  18. mov add1[si],bx
  19. mov add1[si+2],ax
  20. finish: ret
Last edited by Ancient Dragon; Dec 8th, 2008 at 2:08 pm. Reason: add code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
windany is offline Offline
7 posts
since Dec 2008
Dec 9th, 2008
0

Re: Doesn't work, any idea?

then you have to "inc si" and "jmp orderab" before "finish"
Reputation Points: 40
Solved Threads: 4
Junior Poster in Training
low_coder is offline Offline
55 posts
since Nov 2008
Dec 11th, 2008
0

Re: Doesn't work, any idea?

ode segment

jmp main
add1 dw 9,3,2,7,1,4,2,5,8,1


main: call order

exit: mov ax,04c00h
int 21h


order: mov cx,10
loop: mov si,0
dec cx
cmp cx,0
jz exit
call orderab
jmp loop


orderab: mov dx,9
loop1: dec dx
mov ax,add1[si]
cmp ax,add1[si+2]
jle finish
mov bx,add1[si+2]
mov add1[si],bx
mov add1[si+2],ax
finish: inc si
inc si
cmp dx,0
jnz loop1
ret



Any idea why it doesn't work?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
windany is offline Offline
7 posts
since Dec 2008
Dec 11th, 2008
0

Re: Doesn't work, any idea?

Try declaring the array as a byte array instead of word.
Reputation Points: 34
Solved Threads: 2
Light Poster
jt_murphree is offline Offline
40 posts
since Dec 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Why can't I use labels ?
Next Thread in Assembly Forum Timeline: (Newbie question) Variable problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC