Creating a For Loop to Run 1000 Times in Assembly

Viewed 43

a. Loop through a sequence of code exactly 1000 times. Inside of the loop the code should do the following:

i. Call the Random function one time to generate a pseudo-random number and assign the result that is returned to the variable “L”

ii. Call the Random function a second time to generate a pseudo-random number and assign the result that is returned to the variable “M”

iii. Compare the numerical value of the second-lowest Byte of L to the second-lowest Byte of M.

  1. Keep in mind that both L and M are 32-bit numbers, composed of 4 Bytes. The highest Byte is the 8-bits that are left-most of the 32-bits. The lowest Byte is the 8-bits that are the right-most of the 32-bits. The second-lowest Byte is the 8-bits just to the left of the lowest Byte and is composed of bits 8-15 (the lowest Byte being bits 0-7).

  2. So, for example, the second-lowest Byte of the 32-bit Hex number 0xAABBCCDD would be the “CC” value.

iv. Based on the result of the comparison, if the value of the Byte from L is higher than M, then increment the value of the variable “lHigh”.

v. Based on the result of the comparison, if the value of the Byte from M is higher than L, then increment the value of the variable “mHigh”.

vi. Based on the result of the comparison, if the value of the Byte from L is equal to M, then increment the value of the variable “equal”.

b. After you have looped through this process 1000 times, you should stop the loop and cause the program to go into an infinite loop of doing nothing (waiting for the user to end the program). i. NOTE, as a test for your program: after you have looped through the process 10 times it should find that L is higher 4 times and M is higher 6 times, and after you have looped through 100 times it should find that L is higher 49 times and M is higher 50 times and they are equal 1 time.

c. At this point, you will have a count of the number of times L was higher, M was higher, or L and M were equal stored in memory in the variables defined (The 3 values should add up to 1000).

Here is my attempt: MOV CL, 1000 L1: <LOOP-BODY> DEC CL JNZ L1

0 Answers
Related