;编程,将小写字母转换成大写
;一、指定的数据段,用寻址方式去修改
assume cs:code,ss:stack,ds:data
stack segment
dw 0,0,0,0,0,0,0,0
stack ends
data segment
db '1. display '
db '2. brows '
db '3. replace '
db '4. modify '
data ends
code segment
start:
mov ax,stack
mov ss,ax
mov sp,16
mov ax,data
mov ds,ax
mov bx,0
mov cx,4
s0:
push cx ;cx进栈以保存外循环次数
mov si,3 ;从第三个内存单元开始转换
mov cx,4 ;转换长度为4
s:
mov al,[bx+si]
and al,11011111b
mov[bx+si],al
inc si
loop s
add bx,16 ;两行间隔16个内存单元
pop cx
loop s0
mov ax,4c00h
int 21h
code ends
end start
;二、指定的字符串,用0结尾,不影响字母以外的符号(如果有多个字符串,则用循环的时候注意保护cx的值)
;单个的例子:
assume cs:code,ds:data
data segment
db "Beginner's All-purpose Symbolic Instruction Code.",'0'
data ends
code segment
start:
mov ax,data
mov ds,ax
mov si,0
call toUpper
mov ax,4c00h
int 21h
toUpper:
mov cl,[si]
mov ch,0
jcxz over
cmp cl,'a'
jb next ;小于跳转
cmp cl,'z'
ja next ;大于跳转
and byte ptr[si],11011111b
next:
inc si
jmp short toUpper
over:
ret
code ends
end start
;多个的例子:
assume cs:code,ds:data,ss:stack
stack segment
dw 0,0,0,0,0,0,0,0
stack ends
data segment
db 'abcd','0'
db 'efgh','0'
db 'ijkl','0'
data 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
s:
mov si,bx
push cx
push si
call toUpper
add bx,5
pop si
pop cx
loop s
mov ax,4c00h
int 21h
toUpper:
mov cl,[si]
mov ch,0
jcxz over
and byte ptr[si],11011111b
inc si
jmp short toUpper
over:
ret
code ends
end start
;三、指定的字符串,用$结尾
修改判断台条件即可
cmp 内容,'$'
jz 子程序
;多位十/十六进制
assume cs:code,ds:data
data segment
len equ 10
X db 5,2,3,4,5,6,7,8,9,0
Y db 5,6,7,8,9,0,1,2,3,4
Z db (len+1) dup(0)
C db 0
data ends
code segment
start:
mov ax,data
mov ds,ax
lea si,X+(len-1)
lea di,Y+(len-1)
lea bx,C
mov cx,10
addloop:
mov al,[si]
mov dl,[di]
add al,dl
add al,[bx]
mov byte ptr [bx],0
cmp al,10
jb less
sub al,10
mov byte ptr [bx],1
less:
mov [10+di+1],al
dec si
dec di
loop addloop
mov al,[C]
mov [Z],al
mov ax,4c00h
int 21h
code ends
end start
;中断编程,编写0号中断
assume cs:code
code segment
start:
mov ax,cs
mov ds,ax
mov si,offset d0
mov ax,0
mov es,ax
mov di,200H
mov cx,offset d0end-offset d0
rep movsb
mov ax,0
mov es,ax
mov word ptr es:[0],200H
mov word ptr es:[2],0
mov ax,4C00H
int 21H
d0:
jmp short d0start
db "overflow!"
d0start:
mov ax,cs
mov ds,ax
mov si,202H
mov ax,0B800H
mov es,ax
mov di,12*160+33*2
mov cx,9
display:
mov al,[si]
mov es:[di],al
inc si
add di,2
loop display
mov ax,4C00H
int 21H
d0end:
nop
code ends
end start
@Nickname4th Hainu University 2018.12