; array2_64.asm a 2D array of characters, indexing and printing ; Assemble: nasm -f elf64 array2_64.asm ; Link: gcc -o array2_64 array2_64.o ; Run: ./array2_64 extern printf ; the C function, to be called SECTION .data ; Data section, initialized variables nrow: dq 5 ; 5 rows ncol: dq 7 ; 7 columns fmtc: db "%c", 0 ; print one character at a time fmtend: db 10, 0 ; end a line fmtdbg: db "i=%ld, j=%ld, k=%ld", 10, 0 star: db '*' ; one character '*' spc: db ' ' ; space section .bss a2: resb 5*7 ; two dimensional array of bytes i: resq 1 ; row subscript j: resq 1 ; col subscript SECTION .text ; Code section. global main ; the standard gcc entry point main: ; the program label for the entry point push rbp ; set up stack frame ; clear a2 to space mov rax,0 ; i=0 mov [i],rax loopi: mov rax,[i] mov rbx,0 ; j=0 mov [j],rbx loopj: mov rax,[i] mov rbx,[j] imul rax,[ncol] ; i*ncol add rax, rbx ; i*ncol + j mov dl, [spc] ; need just character, byte mov [a2+rax],dl ; store space ; mov rdi, fmtdbg ; mov rsi, [i] ; mov rdx, [j] ; mov rcx, rax ; mov rax, 0 ; call printf mov rbx,[j] inc rbx ; j++ mov [j],rbx cmp rbx,[ncol] ; j