实训内容、程序及操作要领 排序: data segment mem db 10,9,8,7,6,5,4,3,2,1 len dw $-mem data ends code segment main proc far assume cs:code,ds:data start: push ds sub ax,ax push ax mov ax,data mov ds,ax mov dl,1 redo: mov bx,offset mem mov cx,len dec cx sub dl,0 jz done mov dl,0 redo1: mov al,[bx] inc bx cmp al,[bx] jc next mov ah,[bx] mov [bx],al dec bx mov [bx],ah inc bx mov dl,1 next: dec cx jnz redo1 jmp redo done: ret main endp code ends end start
查找:
data segment mem db 1,2,3,4,5,7 len equ $-mem mesg1 db "Pleas input the number you want to find:",10,13,"$" mesg2 db 10,13,"The number has been found!",10,13,"$" mesg3 db 10,13,"The number has not been found!",10,13,"$" data ends code segment
;main procdure main proc far assume cs:code,ds:data start: push ds xor ax,ax push ax mov ax,data mov ds,ax mov si,offset mem mov bx,si add bx,len-1 mov di,bx mov dx,offset mesg1 call xianshi mov ah,1 int 21h sub al,30h call chzhao ret main endp
;xianshi procdure xianshi proc near mov ah,9 int 21h ret xianshi endp
;chazhao procdure chzhao proc near redo: mov bx,di add bx,si shr bx,1 cmp [bx],al jz done jnc redo1 inc bx mov si,bx jmp next redo1: dec bx mov di,bx next: cmp di,si jge redo mov ah,0 jmp done1 done: mov ah,1 done1: cmp ah,1 jnz nhave lea dx,mesg2 jmp xshi nhave: lea dx,mesg3 xshi: call xianshi ret chzhao endp code ends end start 编译链接:(查找为例) C:/DOCUME~1/LUOZHU~1>masm chazhao2 Microsoft (R) Macro Assembler Version 5.00 Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.
Object filename [chazhao2.OBJ]: Source listing [NUL.LST]: Cross-reference [NUL.CRF]:
50420 + 449420 Bytes symbol space free
0 Warning Errors 0 Severe Errors C:/DOCUME~1/LUOZHU~1>link chazhao2
IBM Personal Computer Linker Version 2.00 (C)Copyright IBM Corp 1981, 1982, 1983
Run File [CHAZHAO2.EXE]: List File [NUL.MAP]: Libraries [.LIB]: Warning: No STACK segment
There was 1 error detected. 生成CHAZHAO2.EXE 运行: C:/DOCUME~1/LUOZHU~1>chazhao2 Pleas input the number you want to find: 3 The number has been found!
|