Assembly Loop: How many times does NOP run?

In summary, the conversation discusses a homework problem involving creating a delay loop in assembly for use with an 8253 timer. The question is how many times the NOP instruction runs in the nested loop, with the solution being (4)(62000) for each iteration of the outer loop, which runs 4000 times, resulting in a total of 248,000. There is also a suggestion to use the 8253 timer itself to measure the delay and determine the speed of the computer's processor.
  • #1
JJBladester
Gold Member
286
2

Homework Statement



How many NOP instructions are run in the nested loop below?


OUTER DW 4000 ;outer loop count
INNER DW 62000 ;inner loop count

MOV DX,OUTER
WAIT1: MOV CX,INNER
WAIT2:
NOP
NOP
NOP
NOP
LOOP WAIT2
DEC DX
JNZ WAIT1
RET
DELAY ENDP


The Attempt at a Solution



I am creating a delay loop for use with an 8253 timer which is used to create a tone on a PC's internal speaker. The program is written in assembly. I am having a hard time figuring out how many times NOP executes in the code above.

I believe it is inner + outer = (4)(62000) + (4)(4000) = 264,000.

Any insight would be appreciated.
 
Physics news on Phys.org
  • #2
JJBladester said:

Homework Statement



How many NOP instructions are run in the nested loop below?


OUTER DW 4000 ;outer loop count
INNER DW 62000 ;inner loop count

MOV DX,OUTER
WAIT1: MOV CX,INNER
WAIT2:
NOP
NOP
NOP
NOP
LOOP WAIT2
DEC DX
JNZ WAIT1
RET
DELAY ENDP


The Attempt at a Solution



I am creating a delay loop for use with an 8253 timer which is used to create a tone on a PC's internal speaker. The program is written in assembly. I am having a hard time figuring out how many times NOP executes in the code above.

I believe it is inner + outer = (4)(62000) + (4)(4000) = 264,000.

Any insight would be appreciated.
I think you're way off. For each iteration of the outer loop, the inner loop runs 62,000 times, so the NOP instructions run 62,000 * 4 = 248,000 times.

That's for each iteration of the outer loop, which runs 4000 times. What does that mean for the statements in the inner loop body?
 
  • #3
If you want a delay that isn't processor dependent, why not read the countdown timer from the 8253 itself?
 
  • #4
rcgldr said:
If you want a delay that isn't processor dependent, why not read the countdown timer from the 8253 itself?

One of the points of the exercise is to determine the speed of the computer's processor by how long it takes the NOP loop to run (how long the tone plays).

You're right, processor independence would normally be desired, but not in this case.
 
  • #5
JJBladester said:
One of the points of the exercise is to determine the speed of the computer's processor by how long it takes the NOP loop to run (how long the tone plays).
You could run the loop and read the timer before and after the loop. However the timer may wrap around if your loop takes too long. One way to avoid this would be to intercept the timer interrupt and use an interrupt count as the "upper" bits of the counter timer. Depending on how the timer is programmed, it may count down by 1 or count down by 2 (if it's by 2, there's a sequence of port I/O writes and reads to get the upper bit of the counter).
 

Related to Assembly Loop: How many times does NOP run?

1. How does an assembly loop work?

An assembly loop is a set of instructions that are repeated multiple times, allowing for efficient execution of a task. The loop begins with a jump instruction that directs the program to a specific location in memory, where the instructions to be repeated are stored. The instructions are then executed until a condition is met, such as a specific register value or a counter reaching a certain number. Once the condition is met, the loop ends and the program continues with the next instruction.

2. What is the purpose of using NOP in an assembly loop?

NOP stands for "no operation" and is used as a placeholder instruction in an assembly loop. It does not perform any operation, but simply takes up space in memory. This is useful for creating a delay between instructions or for aligning instructions in memory for better efficiency.

3. How many times does NOP run in an assembly loop?

The number of times NOP runs in an assembly loop depends on the specific loop and its purpose. In some cases, NOP may not be used at all, while in other cases it may be used multiple times. It all depends on the instructions within the loop and the desired outcome.

4. Can NOP be replaced with other instructions in an assembly loop?

Yes, NOP can be replaced with other instructions in an assembly loop. However, it is important to ensure that the replacement instructions do not alter the functionality of the loop. For example, if the NOP was used for a delay, the replacement instruction should also provide the same delay.

5. Are there any alternatives to using an assembly loop with NOP?

Yes, there are alternatives to using an assembly loop with NOP. One alternative is using a different instruction, such as a jump or branch instruction, to redirect the program back to the beginning of the loop. Another alternative is using hardware features, such as a timer or interrupt, to control the repetition of instructions.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
20
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Programming and Computer Science
Replies
7
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
3K
  • Programming and Computer Science
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
1K
  • Programming and Computer Science
Replies
2
Views
6K
Back
Top