水铝英石

循环结构上机

例8-5

data segment
    sum dw 0
data ends    
code segment
    assume ds:code,cs:data
start: mov ax.data
    mov ds,ax
    
    mov ax,0
    mov cx,100
lp: add ax,cx
    loop lp
    mov sum,ax
    mov ah,4ch
    int 21h
code ends
    end start
    

例8-6

data segment
    mess db 'input srting',0ah,0dh,'$'
    stbuf db 100 dup(0)
    cn db 0
data ends    
code segment
    assume ds:code,cs:data
start:
    mov ax,data
    mov ds,ax
    
    mov dx,offset mess
    mov ah,09h
    int 21h
    
    mov si,offset stbuf
    mov ah,01h
    int 21h
    mov cl,0
    
lp: cmp al,0dh
    jz exit
    mov [si],al
    inc si
    cmp al,'a'     ;这部分换成查看输入的小写字母个数
    jb next
    cmp al,'z'
    ja next
    inc cl
next:
    mov ah,01h
    int 21h
    jmp lp
exit:
    mov cn,cl   
        
    mov ah,4ch
    int 21h
code ends
    end start

例8-7

data segment
    str db 'sniff the first enter space'
    cn  equ $-str 
    addr dw 0
    flag db 0
data ends    
code segment
    assume ds:code,cs:data,es:data
start:
    mov ax,data
    mov ds,ax
    mov es,ax
    mov cx,cn
    mov di,offset str
    mov al,20h
    repnz scasb
    jnz next
    dec di
    mov addr,di
    mov flag,1
    jmp exit    
next:
    mov flag,0
exit:
    mov ah,4ch
    int 21h
code ends
    end start

发表评论

邮箱地址不会被公开。 必填项已用*标注

滚动到顶部