Sunday , 24 November 2024

CS609 Assignment solution fall 2012

 

Serial communication is often used either to control or to receive data from an embedded microprocessor. Serial communication is a form of I/O in which the bits of a byte begin transferred appear one after the other in a timed sequence on a single wire. Serial communication has become the standard for intercomputer communication. In this lab, we’ll try to build a serial link between 8051 and PC using RS232.

What is a pointer variable?


a pointer variable is a variable that contains the memory location of another variable or an array (or anything else in memory). Effectively, it points to another memory location.

for standard variables, you define a type, assign a value to that variable or read the value from it, and you can also read the memory location (&n = memory location of n) of the variable.

for pointers, you can point them to any variable, even another pointer, and you can get the value of the variable it points to (*p), the location of that variable in memory (p), or the address in memory of the pointer itself (&p).
consider:
long n = 65;
long *p;
p = &n;

results in: (I just made up the locations)
Type | Name | Location | Value
long n 0xA3FF 65
long * p 0x31DF 0xA3FF

so p points to n. Now,
n = 65
&n = 0xA3FF
p = 0xA3FF
*p = 65
&p = 0x31DF

You may find yourself having to use typecasts frequently when using pointers.

Pointers are useful when passing data to functions.

for instance, consider the following function:

void add(int a, int b, int c) { c = a + b; }

the problem here is that the computer copies each variable into a new memory location before passing them to the function. This function effectively does nothing. However, if you change the function to:


void add(int a, int b, int *c) { c = a + b; }
and call the function by passing in the location of the variable to the function:
add(a,b,&c);
then you can modify the variable itself.

Pointers are also good for working with arrays:
char *c = “Hello World”;
int i=0;
while (c[i] != 0x00) { cout c[i]; c++ } //print one letter at a time.

 

Check Also

CS609 today solved Papers by Muhammad Zeeshan & Aamer Abbas

Quiz Start Time: 06:58 PM Time Left 34 sec(s) Question # 1 of 10 ( …

Leave a Reply

Your email address will not be published. Required fields are marked *

*