大小写转换问题
A 41H 0100 0001B or 0010 0000B 转换为小写
B 42H 0100 0010B
C 43H 0100 0011B
D 44H 0100 0100B
a 61H 0110 0001B and 1101 1111B 转换为大写
b 62H 0110 0010B
c 63H 0110 0011B
d 64H 0110 0100B
方法一:
assume cs:code
data segment
db 'ABcDEF' ; 将ABcDEF全部转换为小写
db 'abCdef' ; 将abCdef全部转换为大写
data ends
stack segment stack
dw 0, 0, 0, 0, 0, 0, 0, 0
dw 0, 0, 0, 0, 0, 0, 0, 0
dw 0, 0, 0, 0, 0, 0, 0, 0
dw 0, 0, 0, 0, 0, 0, 0, 0
stack ends
code segment
start:
mov ax, data
mov ds, ax
mov bx, 0
mov ax, data
mov es, ax
mov cx, 6
downLetter: mov dl, ds:[bx]
or dl, 00100000B
mov es:[bx], dl
inc bx
loop downLetter
mov cx, 6
mov bx, 6
UpLetter: mov dl, ds:[bx]
and dl, 11011111B
mov es:[bx], dl
inc bx
loop UpLetter
mov ax, 4C00H
int 21H
code ends
end start
方法二:
assume cs:code
data segment
db 'ABcDEF' ;单引号
db 'abCdef'
data ends
stack segment stack
dw 0, 0, 0, 0, 0, 0, 0, 0
dw 0, 0, 0, 0, 0, 0, 0, 0
dw 0, 0, 0, 0, 0, 0, 0, 0
dw 0, 0, 0, 0, 0, 0, 0, 0
stack ends
code segment
start:
mov ax, data
mov ds, ax
mov bx, 0
mov ax, data
mov es, ax
mov cx, 6
setLetter: mov dl, ds:[bx]
or dl, 00100000B
mov es:[bx], dl
mov dl, ds:[bx + 6]
and dl, 11011111B
mov es:[bx + 6], dl
inc bx
loop setLetter
mov ax, 4C00H
int 21H
code ends
end start
代码执行结果:
data 段中每个单词的头一个字母改为大写
assume cs:code, ds:data
data segment
db '1. file '
db '2. edit '
db '3. search '
db '4. view '
db '5. options '
db '6. help '
data ends
code segment
start:
mov ax, data
mov ds, ax
mov es, ax
mov bx, 0
mov si, 3
mov cx, 6
upLetter: mov dl, ds:[bx + si]
and dl, 11011111B
mov es:[bx + si], dl
add bx, 16
loop upLetter
mov ax, 4C00H
int 21
code ends
end start
代码执行结果:
data 段中每个单词都改为大写
assume cs:code, ds:data
data segment
db '1. ibm '
db '2. dec '
db '3. dos '
db '4. vax '
data ends
stack segment
dw 0, 0, 0, 0, 0, 0, 0, 0
dw 0, 0, 0, 0, 0, 0, 0, 0
stack ends
code segment
start:
mov ax, stack
mov ss, ax
mov sp, 32
mov ax, data
mov ds, ax
mov es, ax
mov cx, 4
mov bx, 0
mov si, 3
upLetter: push cx
push si
mov cx, 3
upRow: mov dl, ds:[bx + si]
and dl, 11011111B
mov es:[bx + si], dl
inc si
loop upRow
pop si
pop cx
add bx, 16
loop upLetter
mov ax, 4C00H
int 21
code ends
end start
代码执行结果:
data 段中每个单词前4个字母都改为大写
assume cs:code, ds:data
data segment
db '1. display '
db '2. brows '
db '3. replace '
db '4. modify '
data ends
stack segment
dw 0, 0, 0, 0, 0, 0, 0, 0
dw 0, 0, 0, 0, 0, 0, 0, 0
stack ends
code segment
start:
mov ax, stack
mov ss, ax
mov sp, 32
mov ax, data
mov ds, ax
mov es, ax
mov cx, 4
mov bx, 0
mov si, 3
upRow: push cx
push si
mov cx, 4
upCol: mov dl, ds:[bx + si]
and dl, 11011111B
mov es:[bx + si], dl
inc si
loop upCol
pop si
pop cx
add bx, 16
loop upRow
mov ax, 4C00H
int 21
code ends
end start