我正在尝试遍历定义的“2d”数组并找到最小值。
尝试访问矩阵内的值时出现错误。请注意,我已尝试替换:
mov ecx, matrix[edi + esi *2]
和
mov ecx, [matrix + edi + esi * 2]
它没有帮助
;-----------------------------------------------
;SECTION .DATA
;Instantiated variables/Constants
;-----------------------------------------------
section .data
result: db "The smallest number is: " , 0x0a
result_len: equ $-result
nl: db " ", 0x0a
nl_len equ $-nl
matrix: dw 25, 24, 23, 22, 21
dw 20, 19, 18, 17, 16
dw 15, 14, 13, 12, 11
dw 10, 9, 8, 7, 6
dw 5, 4, 3, 2, 1
;-----------------------------------------------
;SECTION .BSS
;Non initialized variables
;-----------------------------------------------
section .bss
;-----------------------------------------------
;SECTION .TEXT
;Code
;-----------------------------------------------
section .text
global _start
_start:
;variable declaration
mov edi, 0
mov esi, 0
mov ecx, 9
outerLoop:
cmp edi, 50 ;each element is 2 bytes (2 ascii characters)
jg endloop ;we need 50 because it's 5 elements per row
mov esi, 0 ;and 5 rows
innerLoop:
cmp esi, 5 ;Compare esi(inner loop index) to 5
jge innerEnd ;jump if it reached the end of the row
mov eax, matrix[edi + esi*2]
cmp [eax], ecx
jg biggerThan
mov ecx, [eax]
biggerThan:
inc esi
jmp innerLoop
innerEnd:
add edi, 10 ;row has been complete, go to next
jmp outerLoop
endloop:
push ecx
mov eax, 4
mov ebx, 1
mov ecx, result
mov edx, result_len
int 0x80
mov eax, 4
mov ebx, 1
mov ecx, esp
add [ecx], DWORD 48
mov edx, 2
int 0x80
; display new line
mov eax, 4
mov ebx, 1
mov ecx, nl
mov edx, nl_len
int 0x80
exit:
mov eax, 1 ;eax contains 1 so quit
mov ebx, 0
int 0x80
如果有人能解释为什么这条线
mov eax, matrix[edi + esi*2]
它不起作用,或者我应该如何遍历数组并找到最小的,我将不胜感激。