Hi,
Im trying to write a program that will ask the user to enter an N number between 2-f. Then accepts N inputs from user and sort them in ascending order. Below is what I have so far, but it is not working. Please help thanks.
DATA SEGMENT
MSG1 DB "How many integers would you like to enter? (Please enter from 2 to F)", "$"
N Db (?)
s db 20 dup (?) ; string to read/sort/print
swap db 1 dup (?) ; "swapped" flag
DATA ENDS
CODE SEGMENT
assume cs:code,ds:code
org 100h
START:
mov dx, offset MSG1
mov ah, 9
int 21h
mov ah,1 ; use DOS to read a character
int 21H
mov N,al
mov dx, offset N
mov ah, 9
int 21h
; read 10 characters
mov bx,offset s ; start of string
mov cl,N ; number of characters to read
READC:
mov ah,1 ; use DOS to read a character
int 21H
mov [bx],al ; store character in string
inc bx ; point to next character in string
dec cx ; decrement characters left to read
jnz readc ; repeat until all read
; bubble sort loop
SORT:
mov al,0 ; clear ’values swaped’ flag
mov swap,al
mov bx,offset s ; point to first character
mov cx,9 ; set count to compare 9 pairs
NEXT2:
mov al,[bx] ; get character pair into al, ah
inc bx ; and point to next character
mov ah,[bx]
cmp ah,al ; compare the pair
jnc noswap ; skip the swap if first is <= second
mov [bx],al ; swap
dec bx
mov [bx],ah
inc bx
mov al,1 ; set "swapped" flag
mov swap,al
NOSWAP:
dec cx ; compare next pair if not done
jnz next2
mov al,swap ; do another pass if any swaps
cmp al,0
jnz SORT
; print results
mov bx,offset s ; start of string
mov cl,N ; number of characters to read
PRINTC:
mov ah,2 ; use DOS to print a character
mov dl,[bx] ;
int 21H
inc bx ; next character in string
dec cx ; decrement characters to print
jnz printc ; repeat until all printed
STOP:
mov ax, 4c00h
int 21h
CODE ENDS
END START