;exercise 3-1


.model small


data segment

table	dw	56, 45, 67, 34, 78, 23, 89, 12, 90
len	dw	18

data ends


code segment
	
	assume cs:code, ds:data

start:
	mov ax,data
	mov ds,ax
  
  	mov si, 0			;i.e. i = 0 in the i for-loop
loopi:
  	mov di, si			;
  	inc di				;
  	inc di				;i.e. j = i + 1 in the j for-loop
loopj:
	mov ax, table[di]
	cmp table[si], ax			;
	jle cont			;i.e. if (memory[i] > memory[j])
	mov bx, table[si]		;i.e. temp = memory[i] 
	mov table[si], ax		;     memory[i] = memory[j]
	mov table[di], bx		;     memory[j] = temp
cont:
	inc di				;
	inc di				;i.e. j++ in the j for-loop
	cmp di, len			;i.e. j <= n in the j for-loop
	jle loopj
	inc si				;
	inc si				;i.e. i++ in the i for-loop
	test si, len			;i.e. i <= n - 1 in the i for-loop
	jl loopi

	mov ax,4c00h
	int 21h
  
code ends


end start