assume cs:code,ds:data
data segment
db 'BaSiC'
db 'InfoMaTion'
data ends
;------------------------------------
;做法一
code segment
start: mov ax,data
mov ds,ax
mov bx,0 ;设置ds:bx指向数据段
mov cx,5 ;对于第一个字符串进行循环转换
s: mov al,ds:[bx]
and al,11011111B ;将字符的第五位转换成0,转换成大写字母
mov ds:[bx],al
inc bx
loop s
mov bx,5 ;指向第二个字符串
mov cx,11
s0: mov al,ds:[bx]
or al,00100000B ;将字符的第五位转换成1,转换成小写字母
mov ds:[bx],al
inc bx
loop s
mov ax,4c00h
int 21h
code ends
;------------------------------------
;做法二,改进版:利用bx+idata实现代码的简化
code segment
start: mov ax,data
mov ds,ax
mov bx,0
mov cx,5
s: mov al,ds:[bx]
and al,11011111b
mov ds:[bx],al
mov al,ds:[bx+5]
or al,00100000b
mov ds:[bx+5],al
inc bx
loop s
code ends
;------------------------------------
end start
assume cs:code,ds:data
data segment
db '1. file '
db '2. edit '
db '3. search '
data ends
code segment
start: mov ax,data
mov ds,ax
mov bx,0 ;ds:bx指定数据段,同时bx作为定义行的变量
mov cx,3
s: mov al,ds:[bx+3] ;3作为常量,定义第一个字母
and al,11011111b
mov ds:[bx+3],al
add bx,16
loop s
mov ax,4c00h
int 21h
code ends
end
assume cs:code,ds:data,ss:stack
data segment
db 'ibm '
db 'dec '
db 'vax '
data ends
;--------------------------------------------
;做法一
code segment
start: mov ax,data
mov ds,ax
mov bx,0
mov cx,3
s0: mov dx,cx ;同时使用同一个变量进行循环,需要对外层循环的值保存
mov si,0
mov cx,3 ;cx设置成内层循环的次数
s: mov al,ds:[bx+si]
and al,11011111b
mov ds:[bx+si],al
inc si
loop s
add bx,16
mov cx,dx ;用dx中存放的外层循环恢复外层循环的计数器
loop s0
mov ax,4c00h
int 21h
code ends
;--------------------------------------------
;做法二,利用栈保存外层循环的值
stack segment
dw 8 dup(0) ;利用栈段保存cx的值
stack ends
code segment
start: mov ax,stack
mov ss,ax
mov sp,16 ;ss:sp指向栈段
mov ax,data
mov ds,ax
mov bx,0 ;ds:bx指向数据段
mov cx,3
s0: push cx
mov si,0
mov cx,3
s: mov al,ds:[bx+si]
and al,11011111b
mov ds:[bx+si],al
inc si
loop s
add bx,16
pop cx
loop s0
mov ax,4c00h
int 21h
code ends
;--------------------------------------------
end start
assume cs:code,ds:data,ss:stack
data segment
db '1. display '
db '2. brows '
db '3. replace '
data ends
stack segment
dw 8 dup(0)
stack ends
code segment
start: mov ax,stack
mov ss,ax
mov sp,16
mov ax,data
mov ds,ax
mov bx,0
mov cx 3 ;设置外层循环只有3行
s0: push cx
mov si,0
mov cx,4 ;设置内层循环只需4次
s: mov al,ds:[bx+si+3] ;设置需要改变的第一个字母
and al,11011111b
mov ds:[bx+si+3],al
inc si
loop s
add bx,16
pop cx
loop s0
mov ax,4c00h
int 21h
code ends
end start
assume cs:code,ds:data
data segment
db 'conversation'
data ends
code segment
start: mov ax,data
mov ds,ax
mov si,0 ;ds:si指向字符串所在空间的首地址
mov cx,12 ;cx存放字符串的长度
call capital
mov ax,4c00h
int 21h
capital: and byte ptr ds:[si],11011111b
inc si
loop capital
ret
code ends
end start
assume cs:code,ds:data
data segment
db 'conversation',0
data ends
code segment
start: mov ax,data
mov ds,ax
mov si,0 ;ds:si指向数据段的开始处
call capital
mov ax,4c00h
int 21h
capital: mov cl,ds:[si]
mov ch,0
jcxz ok ;如果字符串为0,则会跳出循环
and byte ptr ds:[si],11011111b
inc si
jmp short capital ;跳转实现循环
ok: ret ;结束循环
code ends
end start
assume cs:code,ds:data,ss:stack
data segment
db 'word',0
db 'unix',0
db 'wind',0
data ends
stack segment
db 8 dup(0)
stack ends
code segment
start: mov ax,data
mov ds,ax
mov bx,0
mov cx,3 ;外循环实现
s: mov si,bx
call capital
add bx,5 ;内循环的实现
loop s
mov ax,4c00h
int 21h
capital: push cx
push si
change: mov cl,ds:[si]
mov ch,0
jcxz ok
and byte ptr ds:[si],11011111b
inc si
jmp short change
ok: pop si
pop cx
ret
code ends
end