汇编网首页登录博客注册
masmaster的学习博客
博客首页博客互动【做检测题】论坛求助

我的博客

个人首页 |  我的文章 |  我的相册 |  我的好友 |  最新访客 |  文章收藏 |  论坛提问 |  友情链接 |  给我留言  
图片载入中
文章收藏

[2010-09-14 10:53] 习题4.31

请编写一个能够在最低端的640KB内存区域搜索指定信息的小型工具。

答:写了一个查找头一个64K地址范围的程序。
;-----------------------------------------------------
assume        cs:code,ss:stack,ds:data
data        segment
msg1        db        'Enter a string:$'
msg2        db        'Found!',0dh,0ah,'$'
msg3        db        'No Found!',0dh,0ah,'$'
msg4        db        'String Position:$'
buff        db        10 dup (0)
tmp        db        10 dup (0)
pos        dw        0
flag        db        0
data        ends
stack        segment stack
        dw 128 dup (0)
stack        ends
code        segment
start:
        mov ax,data
        mov ds,ax
        mov dx,offset msg1
        mov ah,9
        int 21h
        mov di,offset buff
        call input

        mov ax,0h
        mov es,ax
        mov bx,0h
        mov ax,0ffffh
        sub ax,cx
        inc ax
        xchg cx,ax
s:        
        push cx
        mov si,bx        
        mov di,offset tmp
        mov cl,buff
        xor ch,ch
s1:        
        mov al,es:[si]
        mov [di],al
        inc si
        inc di
        loop s1
        mov pos,si
        mov si,offset tmp
        mov di,offset buff+1
        mov cl,buff
        xor ch,ch
        call comp
        cmp flag,0
        jz xd
        pop cx
        inc bx
        loop s
        call crlf
        mov dx,offset msg3
        mov ah,9
        int 21h
        jmp done
xd:        call crlf        
        mov dx,offset msg2
        mov ah,9
        int 21h
        mov dx,offset msg4
        mov ah,9
        int 21h
        mov dx,es
        call disp
        mov dl,':'
        mov ah,2
        int 21h
        mov dx,pos
        sub dl,buff
        call disp
        mov dl,'-'
        mov ah,2
        int 21h
        mov dx,pos
        call disp

done:
        mov ah,4ch
        int 21h
;
crlf        proc
        mov ah,2
        mov dl,0dh
        int 21h
        mov dl,0ah
        int 21h
        ret
crlf        endp
;
;Output:char numbers in cx
input        proc
        mov cx,0
_in:        
        mov ah,1
        int 21h
        cmp al,0dh
        jz _ok
        mov [di+1],al
        inc di
        inc cx
        jmp _in
_ok:        sub di,cx        
        mov [di],cl
        ret
input        endp
;
comp        proc
_cmp:
        mov al,[si]
        cmp al,[di]
        jnz ol
        inc si
        inc di
        loop _cmp
        mov flag,0
        ret
ol:        mov flag,1
        ret
comp        endp
;
disp        proc
        mov cx,4
        mov ah,2
whex:        push cx
        mov cl,4
        rol dx,cl
        push dx
        and dx,0fh
        cmp dl,10
        jb whex1
        add dl,37h
        int 21h
        jmp whex2
whex1:        add dl,30h
        int 21h
whex2:        pop dx
        pop cx
        loop whex
        ret
disp        endp
code        ends
end        start
;-----------------------------------------------------
评论次数(0)  |  浏览次数(336)  |  类型(汇编习题集) |  收藏此文  | 
 
 请输入验证码  (提示:点击验证码输入框,以获取验证码