zoukankan      html  css  js  c++  java
  • 汇编试验六:实践课程中的程序

    (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
    View Code

    效果如图:

    小写转大写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
    View Code

    效果如下:

    (也就是[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
    View Code

    (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
    View Code

    (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
    View Code

    效果如图:

    (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
    View Code

    效果如下:

    (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
    View Code
  • 相关阅读:
    一个方法只做一件事
    日常-生活-学习-经验分享
    Python 用下划线作为变量前缀和后缀指定特殊变量
    浏览器渲染的基本原理
    七个对我最好的职业建议
    web性能优化
    Javascript 设计模式
    数据结构与算法 Javascript描述
    mysql计算连续天数,mysql连续登录天数,连续天数统计
    Oracle计算连续天数,计算连续时间,Oracle连续天数统计
  • 原文地址:https://www.cnblogs.com/TreeDream/p/6924752.html
Copyright © 2011-2022 走看看