简体   繁体   中英

Assembly language x86 IRVINE infinite loops

I'm new to Assembly language and I need help with an error I keep experiencing, my task in class is to do what I did below, everything I did is correct and how the professor wants it but I can't stop the program from infinite looping, I have the correct answer which is 14 but how do I stop the loop from being infinite without using special commands like ret . How do I stop it?

;Declare an array of words
;Write a loop that adds all the elements of the array located in even places
;Example 3,7,2,8,9
;3+2+9=14

INCLUDE Irvine32.inc

.data

val1 WORD 3,7,2,8,9

.code

main PROC

mov eax, 0

L1:

mov ecx, (LENGTHOF val1)*(TYPE val1+2)-(TYPE val1+4)
mov eax, ecx

call writeDec

loop L1


    exit
main ENDP
END main

At the bottom of your loop, you have this instruction:

loop L1

which means "go back to L1."

Loop L1 is a conditional LOOP that is based on the value in ECX. The real issue is the problem with the value in ECX. LOOP will first decrement ECX by 1 and compare the new value in ECX with zero. If it isn't zero it goes to the label (L1). If it is zero it falls through.

Look carefully at where you set the value of ecx. After LOOP decrements ecx by 1 and execution goes to L1, what happens?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM