Doesn't work, any idea?

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2008
Posts: 4
Reputation: windany is an unknown quantity at this point 
Solved Threads: 0
windany windany is offline Offline
Newbie Poster

Doesn't work, any idea?

 
0
  #1
Dec 7th, 2008
It is meant to count the first two numbers in the array and then place them in ascending order, but sth wrong. Any idea?

  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 976
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

Re: Doesn't work, any idea?

 
0
  #2
Dec 7th, 2008
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
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 4
Reputation: windany is an unknown quantity at this point 
Solved Threads: 0
windany windany is offline Offline
Newbie Poster

Re: Doesn't work, any idea?

 
0
  #3
Dec 7th, 2008
yes i changed +2 to +1, but it still doesn't work, it has a small bug.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 23
Reputation: low_coder is an unknown quantity at this point 
Solved Threads: 2
low_coder low_coder is offline Offline
Newbie Poster

Re: Doesn't work, any idea?

 
0
  #4
Dec 8th, 2008
; 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]
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 4
Reputation: windany is an unknown quantity at this point 
Solved Threads: 0
windany windany is offline Offline
Newbie Poster

Re: Doesn't work, any idea?

 
0
  #5
Dec 8th, 2008
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...
  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 23
Reputation: low_coder is an unknown quantity at this point 
Solved Threads: 2
low_coder low_coder is offline Offline
Newbie Poster

Re: Doesn't work, any idea?

 
0
  #6
Dec 9th, 2008
then you have to "inc si" and "jmp orderab" before "finish"
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 4
Reputation: windany is an unknown quantity at this point 
Solved Threads: 0
windany windany is offline Offline
Newbie Poster

Re: Doesn't work, any idea?

 
0
  #7
Dec 11th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 26
Reputation: jt_murphree is an unknown quantity at this point 
Solved Threads: 1
jt_murphree's Avatar
jt_murphree jt_murphree is offline Offline
Light Poster

Re: Doesn't work, any idea?

 
0
  #8
Dec 11th, 2008
Try declaring the array as a byte array instead of word.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



Tag cloud for Assembly
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC