实训汇编语言设计——排序& 查找

 

实训内容、程序及操作要领

排序:

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!

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值