DATA SEGMENT
PEOPLE DB 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17
LENGTH DB 17
POINT DB 0
PEOPLEOUT DB 17 DUP(0)
DATA ENDS
STACK SEGMENT
DW 100 DUP(0)
STACK ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV ES,AX
MOV AX,STACK
MOV SS,AX
MOV CX,17
LEA SI,PEOPLEOUT
L:
ADD POINT,11
MOV AL,POINT
CMP AL,LENGTH
JA L0;POINT 超过LENGTH
JMP L1
L0:CBW
DIV LENGTH
CMP AH,0
JZ L5
MOV POINT,AH
JMP L1
L5:MOV AH,LENGTH
MOV POINT ,AH
L1:
MOV AL,POINT
CBW
MOV DI,AX
MOV BL,PEOPLE[DI-1]
MOV [SI],BL
INC SI
PUSH CX
MOV BL, LENGTH
MOV AL,POINT
SUB BL,AL
JZ L2
MOV BH,0
MOV CX,BX
CBW
MOV DI,AX
MOVE:
MOV AH,PEOPLE[DI]
MOV PEOPLE[DI-1],AH
INC DI
LOOP MOVE
L2:DEC LENGTH
DEC POINT
POP CX
LOOP L
CODE ENDS
END START
结果保存在PEOPLEOUT中,如图所示: