Skip to main content
added 62 characters in body
Source Link
Suresh
  • 145
  • 2
  • 16

8051 microcontroller problem to find execution time of part2part1 for a given code

For the below mentioned 8051 assembly code:
Time elapse: MOV R0,#100
Part 1 \$ \quad \, \, \,\,\$ : MOV R1,#50
Part 2 \$ \quad \, \, \,\,\$ : MOV R2,#248
Part 3 \$ \quad \, \, \,\,\$ : DJNZ R2,Part3
\$ \quad \quad \quad \, \, \,\,\,\, \$ : DJNZ R1,Part2
\$ \quad \quad \quad \, \, \,\,\, \, \$ : DJNZ R0,Part1

Assumptions:

  1. Microcontroller is running at \$12 MHz \$ frequency and \$ 1 \$ Machine cycle is having \$ 12 \$ clock cycles
    2)MOV instruction takes \$ 1 \$ Machine cycle
    3)DJNZ instruction takes \$ 2 \$ machine cycle
    Calculate time required for execution of part1:
    a) \$ 2495600 \mu \$s \$ \quad \$ b) \$ 2496300 \mu \$s \$ \quad \$ c) \$ 2495300 \mu \$s \$ \quad \$ d) \$ 2496600 \mu \$s

My Approach:
Here \$ \# 100 \to \$ Decimal
$$\because \text{In 8051 : MOV Rn,#Data} \implies \text{#Data } \to 8 \text{bit}$$ We Know:
DJNZ Rn,addr: $$\text{Decrement register 'Rn' and Jump to 'addr' if Rn} \ne (00)_H$$

Now,time required for execution of Part1:
Part 1 \$ \quad \, \, \,\,\$ : MOV R1,#50
Part 2 \$ \quad \, \, \,\,\$ : MOV R2,#248
Part 3 \$ \quad \, \, \,\,\$ : DJNZ R2,Part3
\$ \quad \quad \quad \, \, \,\,\,\, \$ : DJNZ R1,Part2
\$ \quad \quad \quad \, \, \,\,\, \, \$ : DJNZ R0,Part1

So,time required for execution of Part1, \$ T = N * 12*T_{CLK}\$
where, \$ N= \$ total number of machine cycles required for execution of Part1 $$\implies T = N * 12* \frac{1}{f_{CLK}}$$ $$= N * 12* \frac{1}{12*10^6}$$ $$\therefore T=N \mu s \quad \dots (i)$$ For \$ N :\$
\$N= 1+1+\{ 247*2 + 1*2\} \quad \color{red}{[\because \text{leftmost } 1 \text{ is for 'MOV R1,#50' ;}}\$
\$ \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \color{red}{\text{2nd 1 is for 'MOV R2,#248' ;}} \$
\$ \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \color{red}{\text{ 247 times 'DJNZ R2,Part3' True Condition &}} \$
\$ \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \color{red}{\text{1 time 'DJNZ R2,Part3' False Condition}]} \$
\$ \quad \quad \quad + 49*2 +49 \{ 1 +248*2\} + 1*2 \quad \color{red}{[\because \text{49 times 'DJNZ R1,Part2 ' True Condition & }}\$
\$ \color{red}{1 \text{ time 'DJNZ R1,Part2 ' False Condition}]}\$
\$ \quad \quad \quad \quad \quad + 98*2 +98 \{ 1 +1 +248*2 +49 (2 + 1 +248*2 )+1*2 \} \$\$ \quad \quad \quad \quad \quad + \underbrace{98*2 +98 \{ 1 +1 +248*2 +49 (2 + 1 +248*2 )+1*2 \} }_{\color{blue}{\text{Calculation for 98 times}}} \$
\$ \quad \quad \quad \quad \quad \quad \quad + \color{green}{\{}1*2+ 1*1 \color{green}{\} \to \text{calculation for 99th time}}\$ \$ \quad \color{red}{[\because \text{'DJNZ R0,Part1' is True for 99 times} \implies \text{Part1 is executed 99 times}]}\$
$$\implies N= 2470348$$ $$\therefore T= 2470348 \mu s$$ ,which is not there in the option, Key Provided:c)\$2495300 \mu \$s
so, please anyone help me to find my error...

8051 microcontroller problem to find execution time of part2 for a given code

For the below mentioned 8051 assembly code:
Time elapse: MOV R0,#100
Part 1 \$ \quad \, \, \,\,\$ : MOV R1,#50
Part 2 \$ \quad \, \, \,\,\$ : MOV R2,#248
Part 3 \$ \quad \, \, \,\,\$ : DJNZ R2,Part3
\$ \quad \quad \quad \, \, \,\,\,\, \$ : DJNZ R1,Part2
\$ \quad \quad \quad \, \, \,\,\, \, \$ : DJNZ R0,Part1

Assumptions:

  1. Microcontroller is running at \$12 MHz \$ frequency and \$ 1 \$ Machine cycle is having \$ 12 \$ clock cycles
    2)MOV instruction takes \$ 1 \$ Machine cycle
    3)DJNZ instruction takes \$ 2 \$ machine cycle
    Calculate time required for execution of part1:
    a) \$ 2495600 \mu \$s \$ \quad \$ b) \$ 2496300 \mu \$s \$ \quad \$ c) \$ 2495300 \mu \$s \$ \quad \$ d) \$ 2496600 \mu \$s

My Approach:
Here \$ \# 100 \to \$ Decimal
$$\because \text{In 8051 : MOV Rn,#Data} \implies \text{#Data } \to 8 \text{bit}$$ We Know:
DJNZ Rn,addr: $$\text{Decrement register 'Rn' and Jump to 'addr' if Rn} \ne (00)_H$$

Now,time required for execution of Part1:
Part 1 \$ \quad \, \, \,\,\$ : MOV R1,#50
Part 2 \$ \quad \, \, \,\,\$ : MOV R2,#248
Part 3 \$ \quad \, \, \,\,\$ : DJNZ R2,Part3
\$ \quad \quad \quad \, \, \,\,\,\, \$ : DJNZ R1,Part2
\$ \quad \quad \quad \, \, \,\,\, \, \$ : DJNZ R0,Part1

So,time required for execution of Part1, \$ T = N * 12*T_{CLK}\$
where, \$ N= \$ total number of machine cycles required for execution of Part1 $$\implies T = N * 12* \frac{1}{f_{CLK}}$$ $$= N * 12* \frac{1}{12*10^6}$$ $$\therefore T=N \mu s \quad \dots (i)$$ For \$ N :\$
\$N= 1+1+\{ 247*2 + 1*2\} \quad \color{red}{[\because \text{leftmost } 1 \text{ is for 'MOV R1,#50' ;}}\$
\$ \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \color{red}{\text{2nd 1 is for 'MOV R2,#248' ;}} \$
\$ \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \color{red}{\text{ 247 times 'DJNZ R2,Part3' True Condition &}} \$
\$ \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \color{red}{\text{1 time 'DJNZ R2,Part3' False Condition}]} \$
\$ \quad \quad \quad + 49*2 +49 \{ 1 +248*2\} + 1*2 \quad \color{red}{[\because \text{49 times 'DJNZ R1,Part2 ' True Condition & }}\$
\$ \color{red}{1 \text{ time 'DJNZ R1,Part2 ' False Condition}]}\$
\$ \quad \quad \quad \quad \quad + 98*2 +98 \{ 1 +1 +248*2 +49 (2 + 1 +248*2 )+1*2 \} \$
\$ \quad \quad \quad \quad \quad \quad \quad + \color{green}{\{}1*2+ 1*1 \color{green}{\} \to \text{calculation for 99th time}}\$ \$ \quad \color{red}{[\because \text{'DJNZ R0,Part1' is True for 99 times} \implies \text{Part1 is executed 99 times}]}\$
$$\implies N= 2470348$$ $$\therefore T= 2470348 \mu s$$ ,which is not there in the option, Key Provided:c)\$2495300 \mu \$s
so, please anyone help me to find my error...

8051 microcontroller problem to find execution time of part1 for a given code

For the below mentioned 8051 assembly code:
Time elapse: MOV R0,#100
Part 1 \$ \quad \, \, \,\,\$ : MOV R1,#50
Part 2 \$ \quad \, \, \,\,\$ : MOV R2,#248
Part 3 \$ \quad \, \, \,\,\$ : DJNZ R2,Part3
\$ \quad \quad \quad \, \, \,\,\,\, \$ : DJNZ R1,Part2
\$ \quad \quad \quad \, \, \,\,\, \, \$ : DJNZ R0,Part1

Assumptions:

  1. Microcontroller is running at \$12 MHz \$ frequency and \$ 1 \$ Machine cycle is having \$ 12 \$ clock cycles
    2)MOV instruction takes \$ 1 \$ Machine cycle
    3)DJNZ instruction takes \$ 2 \$ machine cycle
    Calculate time required for execution of part1:
    a) \$ 2495600 \mu \$s \$ \quad \$ b) \$ 2496300 \mu \$s \$ \quad \$ c) \$ 2495300 \mu \$s \$ \quad \$ d) \$ 2496600 \mu \$s

My Approach:
Here \$ \# 100 \to \$ Decimal
$$\because \text{In 8051 : MOV Rn,#Data} \implies \text{#Data } \to 8 \text{bit}$$ We Know:
DJNZ Rn,addr: $$\text{Decrement register 'Rn' and Jump to 'addr' if Rn} \ne (00)_H$$

Now,time required for execution of Part1:
Part 1 \$ \quad \, \, \,\,\$ : MOV R1,#50
Part 2 \$ \quad \, \, \,\,\$ : MOV R2,#248
Part 3 \$ \quad \, \, \,\,\$ : DJNZ R2,Part3
\$ \quad \quad \quad \, \, \,\,\,\, \$ : DJNZ R1,Part2
\$ \quad \quad \quad \, \, \,\,\, \, \$ : DJNZ R0,Part1

So,time required for execution of Part1, \$ T = N * 12*T_{CLK}\$
where, \$ N= \$ total number of machine cycles required for execution of Part1 $$\implies T = N * 12* \frac{1}{f_{CLK}}$$ $$= N * 12* \frac{1}{12*10^6}$$ $$\therefore T=N \mu s \quad \dots (i)$$ For \$ N :\$
\$N= 1+1+\{ 247*2 + 1*2\} \quad \color{red}{[\because \text{leftmost } 1 \text{ is for 'MOV R1,#50' ;}}\$
\$ \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \color{red}{\text{2nd 1 is for 'MOV R2,#248' ;}} \$
\$ \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \color{red}{\text{ 247 times 'DJNZ R2,Part3' True Condition &}} \$
\$ \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \color{red}{\text{1 time 'DJNZ R2,Part3' False Condition}]} \$
\$ \quad \quad \quad + 49*2 +49 \{ 1 +248*2\} + 1*2 \quad \color{red}{[\because \text{49 times 'DJNZ R1,Part2 ' True Condition & }}\$
\$ \color{red}{1 \text{ time 'DJNZ R1,Part2 ' False Condition}]}\$
\$ \quad \quad \quad \quad \quad + \underbrace{98*2 +98 \{ 1 +1 +248*2 +49 (2 + 1 +248*2 )+1*2 \} }_{\color{blue}{\text{Calculation for 98 times}}} \$
\$ \quad \quad \quad \quad \quad \quad \quad + \color{green}{\{}1*2+ 1*1 \color{green}{\} \to \text{calculation for 99th time}}\$ \$ \quad \color{red}{[\because \text{'DJNZ R0,Part1' is True for 99 times} \implies \text{Part1 is executed 99 times}]}\$
$$\implies N= 2470348$$ $$\therefore T= 2470348 \mu s$$ ,which is not there in the option, Key Provided:c)\$2495300 \mu \$s
so, please anyone help me to find my error...

Source Link
Suresh
  • 145
  • 2
  • 16

8051 microcontroller problem to find execution time of part2 for a given code

For the below mentioned 8051 assembly code:
Time elapse: MOV R0,#100
Part 1 \$ \quad \, \, \,\,\$ : MOV R1,#50
Part 2 \$ \quad \, \, \,\,\$ : MOV R2,#248
Part 3 \$ \quad \, \, \,\,\$ : DJNZ R2,Part3
\$ \quad \quad \quad \, \, \,\,\,\, \$ : DJNZ R1,Part2
\$ \quad \quad \quad \, \, \,\,\, \, \$ : DJNZ R0,Part1

Assumptions:

  1. Microcontroller is running at \$12 MHz \$ frequency and \$ 1 \$ Machine cycle is having \$ 12 \$ clock cycles
    2)MOV instruction takes \$ 1 \$ Machine cycle
    3)DJNZ instruction takes \$ 2 \$ machine cycle
    Calculate time required for execution of part1:
    a) \$ 2495600 \mu \$s \$ \quad \$ b) \$ 2496300 \mu \$s \$ \quad \$ c) \$ 2495300 \mu \$s \$ \quad \$ d) \$ 2496600 \mu \$s

My Approach:
Here \$ \# 100 \to \$ Decimal
$$\because \text{In 8051 : MOV Rn,#Data} \implies \text{#Data } \to 8 \text{bit}$$ We Know:
DJNZ Rn,addr: $$\text{Decrement register 'Rn' and Jump to 'addr' if Rn} \ne (00)_H$$

Now,time required for execution of Part1:
Part 1 \$ \quad \, \, \,\,\$ : MOV R1,#50
Part 2 \$ \quad \, \, \,\,\$ : MOV R2,#248
Part 3 \$ \quad \, \, \,\,\$ : DJNZ R2,Part3
\$ \quad \quad \quad \, \, \,\,\,\, \$ : DJNZ R1,Part2
\$ \quad \quad \quad \, \, \,\,\, \, \$ : DJNZ R0,Part1

So,time required for execution of Part1, \$ T = N * 12*T_{CLK}\$
where, \$ N= \$ total number of machine cycles required for execution of Part1 $$\implies T = N * 12* \frac{1}{f_{CLK}}$$ $$= N * 12* \frac{1}{12*10^6}$$ $$\therefore T=N \mu s \quad \dots (i)$$ For \$ N :\$
\$N= 1+1+\{ 247*2 + 1*2\} \quad \color{red}{[\because \text{leftmost } 1 \text{ is for 'MOV R1,#50' ;}}\$
\$ \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \color{red}{\text{2nd 1 is for 'MOV R2,#248' ;}} \$
\$ \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \color{red}{\text{ 247 times 'DJNZ R2,Part3' True Condition &}} \$
\$ \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \color{red}{\text{1 time 'DJNZ R2,Part3' False Condition}]} \$
\$ \quad \quad \quad + 49*2 +49 \{ 1 +248*2\} + 1*2 \quad \color{red}{[\because \text{49 times 'DJNZ R1,Part2 ' True Condition & }}\$
\$ \color{red}{1 \text{ time 'DJNZ R1,Part2 ' False Condition}]}\$
\$ \quad \quad \quad \quad \quad + 98*2 +98 \{ 1 +1 +248*2 +49 (2 + 1 +248*2 )+1*2 \} \$
\$ \quad \quad \quad \quad \quad \quad \quad + \color{green}{\{}1*2+ 1*1 \color{green}{\} \to \text{calculation for 99th time}}\$ \$ \quad \color{red}{[\because \text{'DJNZ R0,Part1' is True for 99 times} \implies \text{Part1 is executed 99 times}]}\$
$$\implies N= 2470348$$ $$\therefore T= 2470348 \mu s$$ ,which is not there in the option, Key Provided:c)\$2495300 \mu \$s
so, please anyone help me to find my error...