Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Bubblesort in assembly problem

Status
Not open for further replies.

Aramil

Newbie level 1
Joined
Nov 11, 2009
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,286
Hello,

I'm trying to write a bubblesort algorithm for a class assignment but it doesn't seem to work.I 've checked my code over and over again..Could someone point out any mistakes?

P.S It's written for nasm compiler for a 386 proccessor


pastebin.com/sVj8QSce
 

(EDIT: Link to original code: ASM (NASM) | [ORG 0x100] [BITS 16] ;--- - Bubblesort NASM - sVj8QSce - Pastebin.com)
For some reason NASM would crash on my '486 -- this is written for TASM:
Code:
.286P

CODE SEGMENT
ASSUME CS:CODE,DS:CODE
ORG 00100H

PUSH CS
POP DS
MOV BX, OFFSET S
CALL BSORT
MOV AX, 0B800H
MOV ES, AX
LEA SI, [S]
MOV DI, (8*160)+80
MOV AH, " "
CLD
	PRINT:
LODSB
OR AL, AL
STOSW
JNZ PRINT
RET

	BSORT:
PUSH AX
PUSH SI
PUSH DI
MOV SI, 10	;LENGTH OF DATA STRING
	OUTER:
XOR DI, DI
DEC SI
JZ OUTER_DONE
	INNER:
INC DI
CMP DI, SI
JA OUTER
	COMPARE:
MOV AX, [BX+DI-1]
CMP AL, AH
JNA INNER
	SWAP:
XCHG AL, AH
MOV [BX+DI-1], AX
JMP SHORT INNER
	OUTER_DONE:
POP DI
POP SI
POP AX
RET

S DB "9876543210", 000H

CODE ENDS

END CODE:00100H
(EDIT: The above must be compiled as a ".COM" file.)
(EDIT: By the way, you definitely should place a "CLD" or "STD" instruction before instructions such as "LODSB", "LODSW", "LODSD", "STOSB", "STOSW", "STOSD", "MOVSB", "MOVSW", "MOVSD", "SCASB", "SCASW", "SCASD", "CMPSB", "CMPSW", "CMPSD", "INSB", "INSW", "INSD", "OUTSB", "OUTSW", "OUTSD" -- i.e., string instructions.)
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top