Assembly Loop: How many times does NOP run?

  • Thread starter Thread starter JJBladester
  • Start date Start date
  • Tags Tags
    Assembly Loop
Click For Summary

Discussion Overview

The discussion revolves around calculating the number of NOP (No Operation) instructions executed in a nested loop written in assembly language. The context includes the use of this loop for creating a delay with an 8253 timer, focusing on the implications of processor speed and timing accuracy.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant calculates the total NOP executions as inner + outer = (4)(62000) + (4)(4000) = 264,000.
  • Another participant contests this calculation, stating that for each iteration of the outer loop, the inner loop runs 62,000 times, leading to 248,000 NOP executions for each outer loop iteration, which runs 4000 times.
  • A participant suggests reading the countdown timer from the 8253 for a delay that isn't processor dependent.
  • Another participant clarifies that the goal is to determine the speed of the computer's processor based on the duration of the NOP loop, indicating that processor independence is not the objective in this case.
  • Further discussion includes the potential issue of the timer wrapping around if the loop takes too long and proposes a method to avoid this by intercepting the timer interrupt.

Areas of Agreement / Disagreement

There is disagreement regarding the calculation of NOP executions, with multiple competing views on the correct interpretation of the loop structure and its timing implications. The discussion remains unresolved regarding the exact number of NOP executions.

Contextual Notes

Participants express uncertainty about the assumptions underlying their calculations and the implications of processor speed on the timing of the NOP loop. There are also unresolved considerations regarding the behavior of the timer and its impact on the loop's execution time.

JJBladester
Gold Member
Messages
281
Reaction score
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
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?
 
If you want a delay that isn't processor dependent, why not read the countdown timer from the 8253 itself?
 
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.
 
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).
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
6K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 7 ·
Replies
7
Views
7K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
6K
Replies
6
Views
2K