Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help needed

Status
Not open for further replies.

saturn13

Technical User
Jun 10, 2000
4
0
0
EU
i am wondering if you can help me with this question as a am a beginner in C language and having great difficulty. <br>a programmer has written 2 statements as part of aC program.<br>ptr = &a;<br>a = *ptr + 1;<br>the variable a is a 16-bit integer and the variable ptr has been declared as a pointer to an integer. A C compiler has produced the following machine code instructions from these 2 statements:<br>;ptr = &a;<br>&nbsp;&nbsp;&nbsp;load immediate&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0010<br>&nbsp;&nbsp;&nbsp;store direct&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0012<br>;a = *ptr + 1;<br>&nbsp;&nbsp;&nbsp;load direct&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0012<br>&nbsp;&nbsp;&nbsp;copy register&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A to IX<br>&nbsp;&nbsp;&nbsp;load indexed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0000<br>&nbsp;&nbsp;&nbsp;add immediate&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0001<br>&nbsp;&nbsp;&nbsp;store direct&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0010<br>&nbsp;<br>the data sheet for the 16-bit microprocessor which is to execute this program contains the following instruction execution timing information:<br>load/add immediate instructions - 2 processor cycles, <br>load/store direct instructions - 2 processor cycles,<br>load/store indexed instructions - 3 processor cycles,<br>copy/increment register instructions - 1 processor cycle,<br>&nbsp;<br>1 processor cycle = 10 proceesor clock periods.<br>&nbsp;<br>(a) how many words of memory does the above section of program occupy in memory?<br>assuming the processor clock frequency is 10 MHz how long does the section of the program take to execute?<br>which machine code instruction is redundant?<br>&nbsp;<br>(b) assuming the variable ptr&nbsp;&nbsp;is not required elsewhere in the program, explain why the 2 C statements above are equivalent to the single statement:<br>a = a + 1;<br>&nbsp;<br>(c) the 3 machine code instructions required to implement the C statement given in the part above are:<br>load direct&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0010<br>add immediate&nbsp;&nbsp;&nbsp;A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0001<br>store direct&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0010<br>&nbsp;<br>write down the equivalent assembly language versions of the 3 machine instructions for:<br>the 8086 microprocessor;<br>the 8051 microcontroller (assume here that all variables and instructions are 8-bit quantities).<br>&nbsp;<br>(d) the machine code program in the part above can be further reduced in memory requirements and increased the execution speed by the use of an increment the accumulator instruction instead of the add instruction. for this more efficient version of the program section and using the data given in part (a):<br>how many words of memory does it require;<br>what is its execution time?<br>how should the C programmer change the C statement in part (b) to ensure the compiler is likely to use the processor's increment instruction instead of the add instruction?
 
execution timing of an instruction is calculated by<br><br>1.Total Time taken<br><br>&nbsp;&nbsp;numberofclockcycles needed to execute that instruction multiplied by the clocks period so here<br>total no of cycles is 2+2+2+1+3+2+2<br>14*10**-6.<br><br>2.USE ++a or a++ instruction as it takes only one clock cycle so speed is enhanced.<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top