ESP is the stack pointer as in what it is officially supposed to do/intended? I was running out of registers so I didn't really have a choice. The thing about 16/32 bit has a bit of a problem of where its really difficult to actually output what they contain, the output code template seems to only work with 32 bit registers and the conversion I didn't know what to do, and seemed to largely work; so I didn't want to mess with what wasn't broke.
XOR as I understand it, is an exclusive or that will set the value to a something, if its xor ecx, ecx it "zeroes" out the register the same way as mov ecx, 0 I believe; and does seem to work to point to the first element in the matrix....
I managed to "solve" the problem after a while from switch from the logic which was using the counter pointer of trying to track WHERE the largest number was, to simply storing the largest number as the user inputs it; because the logic seemed to be stuck to the first row and I couldn't get it to unstuck it.
segment .bss
num: resw 1 ;For storing a number, to be read of printed....
nod: resb 1 ;For storing the number of digits....
temp: resb 2
matrix1: resw 200
m: resw 1
n: resw 1
i: resw 1
j: resw 1
buff resb 4
segment .data
msg1: db "Enter the number of rows in the matrix : "
msg_size1: equ $-msg1
msg2: db "Enter the elements one by one(row by row) : "
msg_size2: equ $-msg2
msg3: db "Enter the number of columns in the matrix : "
msg_size3: equ $-msg3
msg4: db "The Largest Number is... : "
msg_size4: equ $-msg4
tab: db 9 ;ASCII for vertical tab
new_line: db 10 ;ASCII for new line
segment .text
global _start
_start:
mov eax, 4
mov ebx, 1
mov ecx, msg1
mov edx, msg_size1
int 80h
mov ecx, 0
call read_num
mov cx, word[num]
mov word[m], cx
mov eax, 4
mov ebx, 1
mov ecx, msg3
mov edx, msg_size3
int 80h
mov ecx, 0
call read_num
mov cx, word[num]
mov word[n], cx
mov eax, 4
mov ebx, 1
mov ecx, msg2
mov edx, msg_size2
int 80h
;Reading each element of the matrix........
mov eax, 0
mov ebx, matrix1
mov word[i], 0
mov word[j], 0
i_loop:
mov word[j], 0
j_loop:
call read_num
mov dx , word[num]
;eax will contain the array index and each element is 2 bytes(1 word) long
mov word[ebx + 2 * eax], dx
inc eax ;Incrementing array index by one....
inc word[j]
mov cx, word[j]
cmp cx, word[n]
jb j_loop
inc word[i]
mov cx, word[i]
cmp cx, word[m]
jb i_loop
; read out matrix code
xor esp, [matrix1] ; esp initialized to first element in array, & is first largest value
;xor edi, edi ; edi initialized to 0, edi is loop counter
;Loop through the matrix, check each number if its larger than the first number in the array. AT the end print said number.
;Reading each element of the matrix.(Storing the elements in row major order).......
mov ebp, 0
mov edi, matrix1
mov esp, 0
mov word[i], 0
mov word[j], 0
i_loop2:
mov word[j], 0
j_loop2:
;eax will contain the array index and each element is 2 bytes(1 word) long
mov dx, word[edi+2*ebp] ;
mov word[num] , dx
cmp esp, [num] ;word[ebx + 2 * eax] ; compares current biggest number with current element iterated.
jge skip
mov esp, [num] ;word[ebx + 2 * eax] ; stores new biggest number
mov esi, ebp ; Stores pointer to the biggest element
skip:
;debug code
;mov eax, 4 ;
;mov ebx, 1
;mov ecx, esp
;add ecx, 48
;mov [buff], ecx
;mov ecx, buff
;mov edx, 4
;int 80h
;mov esp, [num]
inc ebp
inc word[j]
mov cx, word[j]
cmp cx, word[n]
jb j_loop2
inc word[i]
mov cx, word[i]
cmp cx, word[m]
jb i_loop2
;outut
mov eax, 4
mov ebx, 1
mov ecx, msg4
mov edx, msg_size4
int 80h
mov ecx, 0
mov eax, 4 ; system_write
mov ebx, 1 ; stdout
mov ecx, esp ; move biggest element to accumulator
add ecx, 48 ; convert to ascii representation
mov [buff], ecx ; move to memory
mov ecx, buff
mov edx, 4 ; size, 4 bytes
int 80h
exit:
mov eax, 1
mov ebx, 0
int 80h
;Function to read a number from console and to store that in num
read_num:
pusha
mov word[num], 0
loop_read:
mov eax, 3
mov ebx, 0
mov ecx, temp
mov edx, 1
int 80h
cmp byte[temp], 10
je end_read
mov ax, word[num]
mov bx, 10
mul bx
mov bl, byte[temp]
sub bl, 30h
mov bh, 0
add ax, bx
mov word[num], ax
jmp loop_read
end_read:
popa
ret
Here's the working code. Ideally I would want it to output based on the position of counter but that only seems to work with a 1 dimensional array, I have no idea how to specify a location in a 2 dimensional array in nasm land.