在程序集中链接列表中的冒泡排序

时间:2014-12-18 17:56:45

标签: assembly x86

我在x86上编写了这段代码。我的字符串是:
'Pistachios : A native of Syria'
'Hazels : A native of Europe and south west Asia'
'Almonds : A native of the eastern Mediterranean region'

但是,当我想打印新的排序列表时, 我只获得'Almonds : A native of the eastern Mediterranean region'作为输出。 谢谢你的帮助

 STACK_SEG SEGMENT STACK USE16

 DB 100 DUP(?)
STACK_SEG ENDS     


DATA_SEG SEGMENT 'DATA' USE16

LIST_ORG DW PIS
PIS DW HAZ
DB 'Pistachios : A native of Syria$'
HAZ DW ALM
DB 'Hazels : A native of Europe and south west Asia$'
ALM DW 0
DB 'Almonds : A native of the eastern Mediterranean region$'
NEWLINE DB 0DH,0AH,'$'
DATA_SEG ENDS 




CODE_SEG SEGMENT PARA 'CODE' PUBLIC USE16
ASSUME CS:CODE_SEG, DS:DATA_SEG, SS:STACK_SEG
MAIN PROC FAR
PUSH DS ;INITIATE THE PROGRAM
XOR AX,AX
PUSH AX
MOV AX,DATA_SEG
MOV DS,AX   


MOV DI,LIST_ORG  
MOV CX,3
MOV BX,5
LOOP1:
CMP BX,0H
JE EXIT
MOV BX,0H   
LOOP2:
  CMP CX,1
  JE DONE2
  MOV SI,[DI] 


  MOV AL,[DI+2]
  MOV AH,[SI+2]

  CMP AH,AL
  JL CHANGE
  DEC CX
  JMP LOOP2
  CHANGE:  
  XCHG SI,DI
  DEC CX
  INC BX
  JMP LOOP2

  DONE2:
  JMP LOOP1
  EXIT:


  AGAIN2:
  MOV AH,9
  LEA DX,DI+2;first 2 byte is pointer
  INT 21H 

  MOV AH,9
  LEA DX,NEWLINE
  INT 21H 


   MOV SI,[DI]
   CMP SI,0
   JZ RETT
   MOV DI,SI
   JMP AGAIN2
  RETT:

   RET
MAIN ENDP
CODE_SEG ENDS              
END MAIN

1 个答案:

答案 0 :(得分:0)

尝试

MOV DX, NEWLINE

而不是

LEA DX, NEWLINE