Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

BUBBLE SORT in assembly 8086! help..

The program will ask the user to input 5 ASCII characters (ACDBE) via keyboard. the program will then Bubble sort the input to ABCDE. however, an error

[code] mov dx, offset buff
mov cx, size buff[/code]

was obtained from the compiler. help?



[code]
; You may customize this and other start-up templates;
; The location of this template is c:emu8086inc_com_template.txt
.model tiny
.code

org 100h

buff db 256 dup(?)

start:
mov ah, 3fh ; reading a string from standard input
xor bx, bx
mov dx, offset buff
mov cx, size buff
int 21h
jnc okay
ret

okay:
mov bx, offset buff
sub al, 2 ; ignore the CRLF
push ax
cmp al, 2 ; two or more chars ?
jb sorted

add ax, bx
dec ax
mov cx, ax ; cx - ptr. to the last element
inc bx ; starting with the second element

for1:
mov si, cx ; the inner loop always starts from the last element
mov dl, 1 ; dl is used as the "sorted" flag

for2:
mov ax, [si - 1] ; get two chars
cmp al, ah ; are they in order ?
jbe cool
xor dl, dl ; no, then reset the "sorted" flag
mov [si - 1], ah ; ... and exchange the values
mov [si], al

cool:
dec si ; ok, the inner loop continues until si < bx
cmp si, bx
jae for2

test dl, dl ; some exchanges occured ?
jne sorted ; nope - then the array is sorted

inc bx ; the outer loop continues till
cmp bx, cx ; bx goes past the last element in array ...
jbe for1

sorted:
pop cx ; write the result at the standard output
xor bx, bx
mov ah, 40h
inc bx
mov dx, offset buff
int 21h

ret


end start





[/code]

Comments

Sign In or Register to comment.