Why won't this program work in assembly? I'm using Microsoft Visual C++ 2005 Express Edition, and using x86 assembly architecture. It's suppose to add the values in the array that are higher than the variable sample(in this case 50) and display the result. The answer should be +358 but I keep getting +0. I know it's one little mistake I'm making. Any ideas? Code:
.data
sum DWORD 0
sample DWORD 50
array DWORD 10,60,20,33,72,89,45,65,72,18
ArraySize = ($ - array)/ TYPE array
.code
main PROC
mov eax, 0
mov edx, sample
mov esi, 0
mov ecx, ArraySize
L1: cmp esi,ecx
jg L2
jmp L5
L2: cmp array[esi*4], edx
jg L3
jmp L4
add eax, array[esi*4]
L3: add eax,array[esi*4]
L4: inc esi
jmp L1
L5: mov sum, eax
call Writeint
call Crlf
exit
main ENDP
END main
Assembly language program not working?
firstly the add before the L3 is never used as the preceding instruction is a jmp.
But your main problem is that you're comparing esi to ecx right at the start, and if esi%26gt;ecx then you jump to L2, otherwise you got to L5. esi starts at 0, and ecx at the size of the array, so it starts off less, so the first comparison fails and causes a jump to the end.
Change:
L1: cmp esi,ecx
to:
L1: cmp ecx,esi
online florist
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment