本文为《汇编语言程序设计》1005小节例程。点击链接…进课程主页。
问题:编程将data段中的字符串转化为大写。
assume cs:code
data segment
db 'conversation'
data ends
code segment
start: mov ax,data
mov ds,ax
mov si,0
mov cx,12
call capital
mov ax,4c00h
int 21h
capital: and byte ptr [si],11011111b
inc si
loop capital
ret
code ends
end start
用0作为字符串的结束
assume cs:code
data segment
db 'conversation',0
data ends
code segment
start: mov ax,data
mov ds,ax
mov si,0
call capital
mov ax,4c00h
int 21h
capital: mov cl, [si]
mov ch, 0
jcxz ok
and byte ptr [si], 11011111b
inc si
ok: ret
code ends
end start
将以下字符串转为大写
assume cs:code
data segment
db 'word',0
db 'unix',0
db 'wind',0
db 'good',0
data ends
code segment
start: mov ax,data
mov ds,ax
mov bx,0
mov cx,4
s: mov si,bx
call capital
add bx,5
loop s
mov ax,4c00h
int 21h
capital: mov cl,[si]
mov ch,0
jcxz ok
and byte ptr [si],11011111b
inc si
jmp short capital
ok: ret
code ends
end start
;程序中cx既用于循环,又用于读取数据——冲突!
解决了寄存器冲突的程序
;正确的程序
assume cs:code
data segment
db 'word',0
db 'unix',0
db 'wind',0
db 'good',0
data ends
code segment
start: mov ax,data
mov ds,ax
mov bx,0
mov cx,4
s: mov si,bx
call capital
add bx,5
loop s
mov ax,4c00h
int 21h
capital: push cx
push si
change: mov cl,[si]
mov ch,0
jcxz ok
and byte ptr [si],11011111b
inc si
jmp short change
ok: pop si
pop cx
ret
code ends
end start
时间: 2024-09-20 08:03:52