私は10個の値を持つ配列Tを持っており、具体的には(重要な場合)、2d、5c、5b、d3、9b、9a、48、f1、e8、59の順になっています。
私のコードでは、合計を見つけようとしています。 、最小、最大、および平均。
合計と平均を取得しますが、何らかの理由で正解を得るために2で割る必要があります...奇妙です。ある時点で私のfindMinコードは機能していましたが(2dを与えてくれました)、今は機能していません(0を与えるだけです)。findMaxは、配列にも存在しない値も提供します。コードは次のとおりです。
done:
mov ebx, 0 ;clear for loop counter
mov ecx, 0 ;clear array pointer
mov eax, [T] ;base case for sum
findSum:
cmp ebx, 10
jge done1 ;if loop count = 10, done
add ecx, 4 ;point to next array value
add eax, [T+ecx] ;add to register eax
inc ebx
mov sum, eax ;store sum in var 'sum'
jmp findSum
done1:
;; resets regs for loop counter
mov ebx, 0
mov ecx, 0
mov eax, [T] ;first val of table is min by default
jmp findMin
findMin:
;; finds the lowest value in table, first value is min by default
cmp ebx, 10 ;while ebx != 10
jge done2 ;else done
add ecx, 4 ;point to next value of array
inc ebx ;increment loop counter
cmp [T+ecx], eax ;if value at T is greater than eax(min)
jge findMin ;compare next value to min
mov eax, [T+ecx] ;else value is less than min, assigns to reg eax
mov min, eax ;assigns it to var min
jmp findMin
done2:
;; resets regs for loop counter
mov ebx, 0
mov ecx, 0
mov eax, [T] ;first val of table is max by default
jmp findMax
findMax:
;; finds the highest value in the table, first val is max by default
cmp ebx, 10 ;while ebx != 0
jge findAvg ; else done
add ecx, 4 ;to point to next value in array
inc ebx ;increment loop counter
cmp [T+ecx], eax ;if value at array is less than max(eax)
jle findMax ;compare next values
mov eax, [T+ecx] ;else value is greater than max, assign to reg eax
mov max, eax ;assign to var max
jmp findMax
sum、min、maxはすべてdwordとして宣言されています。
理由について私が見落としているに違いないことがわかりますか。a
)正しい合計を得るには、合計を2で割る必要がありますか。
b)findMinセグメントとfindMaxセグメントが機能していませんか?(最小= 0&最大= acc)