View Single Post
Old Oct 29th, 2007, 11:27 PM   #15
akioshin
Newbie
 
akioshin's Avatar
 
Join Date: Oct 2007
Posts: 6
Rep Power: 0 akioshin is on a distinguished road
Re: tasm sorting 5 integers with array

hi everyone i've finish the problem sorting 5 intergers here is my code


extrn readnum:near
extrn writenum:near
extrn new_line:near
extrn clearscreen:near
public num
.286
.model small

printStr macro str
   pusha
   lea dx, str
   mov ah, 9
   int 21h
   popa
endm

.stack 0
.data

	msg db, 10, 13, 'Please enter one digit number: $'
	num dw 0
	num2 dw 0
	ar1 dw 5 dup(?)

.code


	mov ax, @data
	mov ds, ax


	mov bx, offset ar1
	mov cx, 5
aloop:

	printStr msg
	call readnum
	mov ax, num
	mov [bx], ax
	add bx, 2
	loop aloop
	


	sub si, si
        sub di, di

	mov num2, 8




		

@@loop_i:
	mov di, si
;        add di, 2           ; di + 2 

@@loop_j:

	mov bx, offset ar1
	mov ah, [bx+si]
	mov al, [bx+di]
        cmp   ah, al       ; if (ar1[i] <= ar1[j]) then no swap
        jle   @@no_swap
	
        mov   [bx+si], al  ; else swap
        mov   [bx+di], ah

@@no_swap:

	add di, 2
        cmp   di, 8    ; (compare with bound)
        jle   @@loop_j  ; if below or equal, then go to @@loop_j
	add si, 2
	cmp si, 8
	jle @@loop_i
	





	

;for displaying the array
disp1:
	mov bx, offset ar1
	mov cx, 5
disp:
	mov ax,[bx]

	mov num, ax
	call new_line
	call writenum	
	add bx, 2
	loop disp


	mov ah, 4ch
	int 21h
end
its working fine, is there a shorter code for this?i was just wondering
thanks a lot
akioshin is offline   Reply With Quote