[汇编语言]-第七章 不同的寻址方式的灵活应用

[idata] 用一个常量来表示地址

[bx] 用一个变量表示地址

[bx+idata] 用一个变量和常量表示地址

[bx+si] 用两个变量表示地址

[bx+si+idata] 用两个变量和一个常量表示地址

 1 ;将datasg段中每个单词的头一个字母改为大写字母
 2 assume cs:codesg,ds:datasg
 3 datasg segment
 4     db '1. file         '
 5     db '2. edit         '
 6     db '3. search       '
 7     db '4. view         '
 8     db '5. options      '
 9     db '6. help         '
10 datasg ends
11 codesg segment
12 start:    mov ax,datasg
13         mov ds,ax
14         mov bx,0
15         
16         mov cx,6
17     s:  mov al,[bx +3]
18         and al,11011111B
19         mov    [bx + 3],al
20         add bx,16
21         loop s
22         
23         mov ax,4c00H
24         int 21h    
25 codesg ends
26 end start

;将datasg段中的每个单词修改为大写字母
assume cs:codesg,ds:datasg,ss:stacksg
datasg segment
    db 'ibm             '
    db 'dec             '
    db 'doc             '
    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

 1 ;将datasg段中每个单词的前四个字母改为大写字母
 2 assume cs:codesg, ss:stacksg, ds:datasg
 3 stacksg segment
 4     dw 0,0,0,0,0,0,0,0
 5 stacksg ends
 6 datasg segment
 7     db '1. display      '
 8     db '2. brows        '
 9     db '3. replace      '
10     db '4. modify       '
11 datasg ends
12 codesg segment
13 start:  mov ax,stacksg
14         mov ss,ax
15         mov sp,16
16         
17         mov ax,datasg
18         mov    ds,ax
19         mov bx,0
20         
21         mov cx,4
22     s0: push cx
23         mov si,0
24         mov cx,4
25         
26         s:  mov al,ds:[bx + 3 + si]
27             and    al,11011111B
28             mov    ds:[bx + 3 + si],al
29             inc    si
30             loop s
31         
32         pop cx
33         add bx,16
34         loop s0;
35         
36         mov ax,4c00H
37         int    21h    
38 codesg ends
39 end start

一般来讲,在需要暂存数据的时候,我们都应该使用栈.

原文地址:https://www.cnblogs.com/galoishelley/p/3570882.html