Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. How many times the following loop will be executed calculate the delay for a

ID: 3589812 • Letter: 3

Question

3. How many times the following loop will be executed calculate the delay for a 4 MHZ oscillator.

myreg        equ 0x88        

                  delay               movlw 0x00     ; 1 instr cycle

                  movwf             myreg              ; 1 instr cycle

                  again               nop                  ; 1 instr cycle

                                          nop                  ; 1 instr cycle

                                          nop                  ; 1 instr cycle

                                          nop                  ; 1 instr cycle

                                          decf myreg, f ; 1 instr cycle

                                          bnz again         ; 2 instr cycle

                                          return              ; 1 instr cycle

Explanation / Answer

myreg eq 0x88 in the first statement sets the value of myreg to hexadecimal value of 0x88.

0x88 in decimal = 8 * 161 + 8 * 160 = 8 * 16 + 8 = 128 + 8 = 136

So, the decimal value of 0x88 is 136.

The statement “bnz again” checks its previous statement and if the value is greater than zero, the condition is satisfied and branch to “again” takes place i.e. looping. The statement “decf myreg,f” means that the value of myreg is decremented by F i.e. decremented by 15.

In the first iteration, the value of myreg becomes 136-15=121.

In the second iteration, the value of myreg becomes 121-15=106.

In the third iteration, the value of myreg becomes 106-15=91.

In the fourth iteration, the value of myreg becomes 91-15=76.

And it goes on until the value of myreg becomes less than or equal to zero.

Since this continues till 9th iteration, the loop will be executed 9 times.

Hence, the answer is 9.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote