I am trying to figure out how to print out both rows and columns of an array. The program asks how many rows and columns and depending on user input it would display "Enter a number for [0][0]" "Enter a number for [0][1]" and etc.
Here is what I have written so far:
%include "io.inc"
SECTION .data ; Data section, initialized variables
num_rows db "How many rows?: ",0
num_col db "How many columns?: ",0
prompt db "Enter a number for [%d][%d]:",10,0
sum db "The sum is: ",10,0
number db "%d",10,0
rows times 4 dd "%d",0
col times 4 dd "%d",0
arrayLen dd 9 ; length of array
;size equ rows*col
formatin db "%d", 0
section .bss
array resd 6; this is a test array for testing purposes
SECTION .text ; Code section.
global CMAIN ; the standard gcc entry point
extern printf ,scanf
CMAIN: ; the program label for the entry point
;-----Ask for the number of rows and display
push num_rows
call printf
add esp,4 ;remove the parameter
push rows ;address of rows
push formatin ;arguments are right to left
call scanf
add esp,8
;move the values into the registers
mov ebp,[rows]
push ebp
push number
call printf
add esp,8
;----Ask for the number of cols and display
push num_col
call printf
add esp,4
push col
push formatin
call scanf
add esp,8
;move the values into the registers
mov ebx, [col]
push ebx
push number
call printf
add esp,8
mov ebp,array
push ecx
push number
call printf
add esp,8
mov ecx,0
xor ebp,ebp
outerLoop:
mov edx,ecx
push ecx
mov ecx,0
inner:
push ecx
;output
push ecx
push edx
push prompt
call printf
add esp,12
;Get addr
push ecx
push edx
push esi
;call GetElement
add esp,12
;input
push eax
push number
call scanf
add esp,8
pop ecx
inc ecx
cmp ecx,[col]
jl inner
pop ecx
end_outer:
inc ecx
cmp ecx,[rows]
jl outerLoop
push sum
call printf
add esp,4
xor ebp,ebp <- My professor told me never to use this
ret
;GetElement: THIS WHOLE SUBPROGRAM IS COMMENTED
; mov ebx,[ebp+8] ;addr of array
; mov ecx,[ebp+12] ;row
; mov esi,[ebp+16] ;col
; mov eax,ecx
; mul dword [col]
; add eax,esi
; imul eax,4
; add eax,ebx
; leave
; ret
When I run the code the indexes [rows][cols] do not print correctly. Can someone guide me?