C语言描述:
#include <stdio.h> int main() { int a[2][3]={1,2,3,4,5,6}; for(int i=0;i<2;i++) { for(int j=0;j<3;j++) { printf("%d",a[i][j]); } printf("\n"); } }
汇编语言:
include irvine32.inc .data arr dword 1,2,3,41,52,63 dword 7,8,9,10,11,12 row dword 2 col dword 6 .code main proc mov ebx,offset arr ;起始位置 mov esi,0 ;行数,一开始为0 outloop: mov edi,0 ;列数,每次外循环时将列数置0 innerloop: mov edx,esi imul edx,col add edx,edi ;edx=行数*总列数+当前列数 mov eax,[ebx+edx*4] call writeint inc edi ;列自增 cmp edi,col ;将列与总列数作比较 jl innerloop ;若小于,则内循环 inc esi call crlf cmp esi,row jl outloop ;否则外循环 main endp end main
输出结果: