(1)大小写转换
Source Code:
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 int 21H codesg ends end start
效果如图:
小写转大写and操作,大写转小写or操作
(2)两个字符串等长,则可以用数组的形式访问这两个字符串
Source Code:
assume cs:codesg , ds:datasg datasg segment db 'BaSiC' db 'MinIX' 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 mov al,[5+bx] or al,00100000b mov [5+bx],al inc bx loop s mov ax,4c00H int 21H codesg ends end start
效果如下:
(也就是[bx+idata]形式)
或者0[bx],同[bx+idata]
Source Code:
assume cs:codesg,ds:datasg datasg segment db 'BaSiC' db 'MinIX' datasg ends codesg segment start: mov ax,datasg mov ds,ax mov bx,0 mov cx,5 s: mov al,0[bx] and al,11011111b mov 0[bx],al mov al,5[bx] or al,00100000b mov 5[bx],al inc bx loop s mov ax,4c00H int 21H codesg ends end start
(3)SI DI 两个下标寄存器,复制字符串;
(一个字一个字复制)
Source Code:
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 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
(4)双重循环,将cx保存到dx中;
Source Code:
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 add bx,16 mov cx,dx loop s0 mov ax,4c00H int 21H codesg ends end start
效果如图:
(5)数据的暂存,寄存器个数少,一般思路是放到栈里;
Source Code:
assume cs:codesg, ds:datasg, ss:stacksg datasg segment db 'ibm ' db 'dec ' db 'dos ' db 'vax ' datasg ends stacksg segment dw 0,0,0,0,0,0,0,0 stacksg 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 si,0 mov cx,3 s: mov al,[bx+si] and al,11011111b mov [bx+si],al inc si loop s add bx,16 pop cx loop s0 mov ax,4c00H int 21H codesg ends end start
效果如下:
(6)问题7.9,只需将前面的bx起始位置修改;
效果如下:
Source Code:
assume cs:codesg, ds:datasg, ss:stacksg 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 stacksg segment dw 0,0,0,0,0,0,0,0 stacksg ends codesg segment start: mov ax,stacksg mov ss,ax mov sp,16 mov ax,datasg mov ds,ax mov bx,3 mov cx,4 s0: push cx mov si,0 mov cx,3 s: mov al,[bx+si] and al,11011111b mov [bx+si],al inc si loop s add bx,16 pop cx loop s0 mov ax,4c00H int 21H codesg ends end start