- #1
twoski
- 181
- 2
Homework Statement
Write a program in nasm which will read through a 5x5 matrix and print the largest value.
The Attempt at a Solution
I ran this through a debugger and for some reason $edi reaches 19 and sets $esi to 0. Which is weird since the value at [eax + edi * 4] should be 4, not 0.
My output code is wonky too, i could use some help with that.
Code:
segment .data
matrix dd 1,1,1,1,1, \
2,2,2,2,2, \
3,3,3,3,3, \
4,4,4,4,4, \
5,5,5,5,5
segment .bss
empty resb 4
count resb 4
segment .text
global _start
_start:
mov eax, matrix
call FindGreatest
FindGreatest:
mov esi, [empty]
mov edi, [count]
mov edi, 0
jmp Switch
Comparison:
inc edi
cmp esi, [eax + edi * 4] ; compare stored number with new number
jg Switch ; it's bigger so replace it
cmp edi, 25 ; check if we are out of bounds
jle Comparison ; start over again if we can
mov eax, esi
add eax, 30h ; is this the proper way to convert?
mov esi, eax
jmp Print ; print the value now that we have traversed the matrix
Switch:
mov esi, [eax + edi * 4] ; we found a higher number
jmp Comparison
Print:
mov edx, 4
mov ecx, esi ; we are outputting the stored digit as text
mov ebx, 1
mov eax, 4 ; output with stdio
int 0x80
jmp exit
exit:
mov eax, 1
xor ebx, ebx
int 0x80
Last edited: