xplshn
·
2025-08-13
2dMatrix.b
B
1main() {
2 extrn printf;
3 auto W, H, i, j, word_size;
4
5 word_size = &0[1];
6 W = 5;
7 H = 4;
8
9 auto matrix_data 20; // H * W = 4 * 5 = 20 words // :3
10
11 // Allocate an array of pointers for the rows
12 auto matrix 4;
13
14 // Set row pointers to point into the data block
15 i = 0;
16 while (i < H) {
17 matrix[i] = &matrix_data[i * W];
18 i++;
19 }
20
21 i = 0;
22 while (i < H) {
23 j = 0;
24 while (j < W) {
25 matrix[i][j] = i * 10 + j;
26 j++;
27 }
28 i++;
29 }
30
31 printf("Printing a %d by %d matrix\n", H, W);
32 i = 0;
33 while (i < H) {
34 j = 0;
35 while (j < W) {
36 printf("%d\t", matrix[i][j]);
37 j++;
38 }
39 printf("\n");
40 i++;
41 }
42}