矩阵的转置1

来源:互联网 发布:gson解析json对象 编辑:程序博客网 时间:2024/05/06 04:30

王爽汇编第二版学习笔记

 

 


 

一、题目要求:

1、在一个段中定义两个16*16(256个字节)的内存空间矩阵,对第一个矩阵中用循环填充00-FF。

2、要求在第二个矩阵中实现对第一个矩阵的转置

 

 


 

二、实现代码

assume cs:codesg,ds:datasg

 

datasg segment
        db 256 dup (0)
        db 256 dup (0)
datasg ends

 

codesg segment
start:
        mov ax,datasg
        mov ds,ax


        mov bx,0
        mov al,0


        mov cx,256
     s:                    ;填充第一个矩阵
        mov [bx],al
        inc bx
        inc al
        loop s

 

        mov bp,0    ;用bp来控制对第二个矩阵写入的列
        mov bx,0    ;用bx来控制对第一个矩阵读取的位置


        mov cx,16
     s1:
        mov dx,cx   ;保存cx寄存器的值,进入内层循环
        mov di,0     ;用di控制对第二个矩阵写入的行
        mov cx,16 
     s2:
        mov al,[bx]
        mov ds:[256+bp+di],al

        add di,10h  ;进入下一行
        inc bx
        loop s2

 

        inc bp
        mov cx,dx   ;恢复cx寄存器的值,回到外层循环
        loop s1
       

        mov ax,4c00h
        int 21h
codesg ends

end start

 

 


 

三、运行结果