王爽《汇编语言》第三版 实验11 编写子程序

解题思路在下面的代码中,这个实验不怎么复杂

assume cs:code

datasg segment
    db "Beginner's All-purpose Symbolic Instruction Code.", 0
datasg ends

;这个程序的目的是把datasg段中的字符串中的小写字母替换成相应的大写字母,这就需要对他们的ASCII值
;进行比较,以此判断此字母是大写还是小写,如果是小写,则将
;97 (a)                 102 (f)
;0 1 1 0 0 0 0 1        0 1 1 0 0 1 1 0
;65 (A)                 70  (F)
;0 1 0 0 0 0 0 1        0 1 0 0 0 1 1 0 
;把第6位变成0即可转换成大写字母,也就是和11011111做与运算
;至于是否为小写字母的判断,也是很简单的,[97, 122]区间即为小写字母,使用jb和ja来进行相应的跳转,如果jb和ja指令
;都没有生效,说明当前字符就是小写字母,则进行与运算,将运算结果放回原来的位置

code segment
begin:  mov ax, datasg
        mov ds, ax
        mov cx, 0
        mov si, 0
        call letterc

        mov ax, 4c00h
        int 21h 

letterc:push ax
        push si
        push cx
change: mov al, ds:[si]
        mov cl, al
        jcxz finish
        cmp al, 97
        jb notok
        cmp al, 122
        ja notok
        ;能运行到这一步,说明当前si所指向的是一个小写字母,进行与运算
        and al, 11011111B
        mov byte ptr [si], al
notok:  inc si
        jmp short change
finish: pop cx
        pop si
        pop ax
        ret

code ends
end begin

运行结果:
这里写图片描述

猜你喜欢

转载自blog.csdn.net/include_heqile/article/details/80712289