1,数据以字符形式给出
assume cs:code,ds:data
data segment
db 'unIX'
db 'foRK'
data ends
code segment
start: mov al,'a'
mov bl,'b'
mov ax,4c00h
int 21h
code ends
end start
2,大小写转换问题
ASCII码第五位置‘0’变成大写字母, 置‘1’变成小写字母
assume cs:codesg, ds:datasg
datasg segment
db 'BaSiC'
db 'iNfOrMaTiOn'
datasg ends
codesg segment
start: mov ax,datasg
mov ds,ax
mov bx,0
mov cx,5
s:mov al,[bx]
and al, 11011111B
mov [bx],al
inc bx
loop s
mov bx,5
mov cx,11
s0:mov al,[bx]
or al, 00100000B
mov [bx],al
inc bx
loop s0
mov ax, 4c00h
inc 21h
codesg ends
end start
SI和DI,数据复制
assume cs:codesg,ds:datasg
datasg segment
db 'welcome to masm!'
db '................'
datasg ends
codesg segment
start:
mov ax,datasg
mov ds,ax
mov si,0
mov di,16
mov bx,0
mov cx,8
s: mov ax, [si]
mov [di],ax
add si,2
add di,2
loop s
mov ax,4c00h
int 21h
codesg ends
end start
更少代码,更简洁实现数据复制
assume cs:codesg,ds:datasg
datasg segment
db 'welcome to masm!'
db '................'
datasg ends
codesg segment
start:
mov ax,datasg
mov ds,ax
mov si,0
mov cx,8
s: mov ax, 0[si]
mov 16[si],ax
add si,2
loop s
mov ax,4c00h
int 21h
codesg ends
end start
将datasg段中每个单词改为大写字母
assume cs:codesg,ds:datasg
datasg segment
db 'ibm '
db 'dec '
db 'dos '
db 'vax '
datasg ends
codesg segment
start:
mov ax,datasg
mov ds,ax
mov bx,0
mov cx,4
s0: mov dx,cx
mov si,0
mov cx,3
s:mov al,[bx+si]
and al,11011111b
mov [bx+si],al
inc si
loop s
mov cx,dx
add bx,16
loop s0
mov ax,4c00h
int 21h
codesg ends
end start
通用的一个方案来暂存数据(这个程序遇到的问题),
1,用空闲的寄存器
2,同空闲的内存
3,用栈
将datasg段中每个单词的前4个字母改写为大写字母。
assume cs:codesg,ds:datasg
stacksg segment
dw 0,0,0,0,0,0,0,0
stacksg ends
datasg segment
db '1. display '
db '2. brows '
db '3. replace '
db '4. modify '
datasg ends
codesg segment
start:
mov ax, stacksg
mov ss,ax
mov sp,16
mov ax,datasg
mov ds,ax
mov bx,0
mov cx 4
s0:push cx
mov cx 4
mov si 0
s:mov bl,[bx+si+3]
and bl,11011111b
mov [bx+si+3],bl
add si,1
loop s0
pop cx
add bx,16
loop s0
mov ax,4c00h
int 21h
codesg ends
end start