【发布时间】:2014-11-12 21:31:39
【问题描述】:
我的程序产生了分段错误,因此不会从我的数组中打印出最小的数字。我和我的助教一起检查了我的程序,但她只告诉我分段错误的原因可能是数组越界异常。如果有人这么好心,我需要一点帮助来找出我哪里出错了。
section .data ; initilized data segment
matrixA dd 79, 98, 58, 62, 94 ; 5x5 matrix
dd 82, 92, 76, 51, 81
dd 83, 46, 67, 71, 52
dd 43, 61, 73, 44, 48
dd 59, 85, 82, 66, 89
msgLow db 'The lowest Value of the Matrix is:', 0x0a ; Lowest Message
lenLow equ $- msgLow
section .bss ; uninitialized data segment
;...
section .text ; program data
global _start ; global scope
_start: ; main function
printMsg: ; Prints msgLow
mov eax, 4
mov ebx, 1
mov ecx, msgLow
mov edx, lenLow
int 0x80
init:
mov edi, 0 ; used to track row position
mov esi, 0 ; added to edi give a number in the matrixA
mov ecx, 99 ; upper limit of lowest number
call outter ; sub routine for finding lowest number
mov eax, 4 ; Prints out the lowest number
mov ebx, 1
mov ecx, esp
add [ecx], DWORD 48
mov edx, 4
exit: ; Program Exit
mov eax, 1
xor ebx, ebx
int 0x80
;Exit
;Function Start ; Function for finding lowest value
outter: ; Compare Main
cmp edi, 96 ;
ja funct_end ; end the function at edi => 100
mov esi, 0 ; initialize esi when this part of loop is run
inner:
cmp esi, 4 ; Compare esi (inner loop index) to 5
ja inner_end ; ends inner loop if > 4 esi's limit
mov eax, [matrixA + edi + esi * 4] ; moves element from matrixA into eax
cmp eax, ecx ; Compare eax element of matrixA to ecx
ja higher ; jump if value is above ecx value
mov ecx, eax ; sets new lowest number if reached
higher: ; Incrementer
inc esi ; increments sdi
jmp inner
inner_end: ; if outter give a higher value
add edi, 20 ; row is 5 x 4
jmp outter
funct_end: ; end of function
push ecx
ret
;Function End
非常感谢任何帮助。
【问题讨论】:
标签: assembly segmentation-fault nasm multidimensional-array