Saturday 17 June 2023

Declaring Structure Variables in C

What is declaring structure variables?

By explain a structure we have only generate a format, the real use of structures will be when we declare variables or flexible based on this format. We can state or declare structure variables in two ways –

C language, structure definition, using the structure tag
Declaring structure variables image-1

1.       With structure definition

2.       Using the structure tag

1.1   With structure definition

Struct student{

                                char name [10];

                                int rollno;

                                float marks;

                                }stu1,stu2,stu3;

Here stu 1, stu2 and stu 3 are variables or adjustable of type struct student. When we declare a variable while explain or defining the structure device or template, the tag name is optional.

 

1.2   Using the structure tag

We can also state or declare structure variables using organization or structure tag. This can be written as –

      struct student{

                                char name [10];

                                int rollno;

                                float marks;

                                };

struct student stu1, stu2;

struct student stu3;

Here stu1, stu2, and stu3 are structure or organization variables that are state or declared using the structure tag student. Declaring a structure variable set aside or reserves space in memory. Each structure variable state or declared to be of type struct student has three members viz. rollno, name and marks. The editor or compiler will reserve space for each variable enough or sufficient to hold all the members. For example each variable of type struct student will settled or occupy 28 (20+4+4) bytes.

 

1.3   Initialization of structure variables

The pattern or syntax of establishes structure variables are alike to that of arrays. All the worth is given in wavy or curly braces and the number, order and type of these values should be same as in the structure device definition. The establishes values can only be continuous or constant expressions.

                                sturct student {

                                                char name [10];

                                                int rollno;

                                                float marks;

                                                }stu1={“Gopi”,25,9};

                                                Struct student stu2={“Pasi”, 24,67.5};

Here value of members of stu1 will be “Gopi” for name, 25 for rollno, 98 for marks. The values of members of stu2 will be “Pasi” for name, 24 for rollno, 67.5 for marks.

Note: we cannot establish members while explain the structure.

 If the number of establish is less than the number of members then the carry on members are establishes with zero. For example if we have this establishes –

   struct student stu1 = {“Gopi”};

Here the members rollno and marks of stu1 will be establishes to zero. This is equal to the initialization –

          struct student stu1 = {“Gopi”, 0, 0};


Computer stuff kit tricks of Topics 59.

What are control statement in C language?



Tuesday 13 June 2023

Structures and Unions in C

What is Structures and Unions?

Array is a collection of same type of component but in much real life appeal we may need to group mismatched types of logically related data. For example if we want to generate a record of a person that contains name, age and height of that person, then we can’t use array since all the three data elements are of different types. For example record has three name (string), age (int) and height (int).

structures, arrays, defining a structure, c language program
Structures and Unions in C Image-1

To store these connected fields of different data types we can use a structure, which is able of storing diverse data. Data of mismatched types can be grouped jointly under a single name using structures. The data component of a structure is referred to as members.

1.1   Defining a Structure

Definition of a structure generates a template or format that report the quality of its members. All the variables that would be state of this structure type, will take the form of this format. The general syntax of a structure definition is-

struct tagname{

datatype member1;

datatype member2;

……………………………

datatype memberN;

};

Here struct is a keyword, which tells the accumulator that a structure is being defined. member1, member2, ……………… memberN are known as members of the structure and are communicate inside curly braces. There should be a semicolon at the end of the wavy braces. These members can be of any data type like int, float, array, char, pointers or another structure type. tagname is the name of the structure and it is used far in the program to communicate variables of this structure type.

 

Definition of a structure comes up with one more data type in adding to the built in data types. We can state variables of this new data type that will have the format of the explain structure. It is major to note that definition of a structure format does not put aside any space in memory for the members; space is booked only when actual adaptable of this structure type are declared. Although the syntax of statement of major inside the format is identical to the syntax we use in declaring variables but these members are not variables, they don’t have any alive until they are fond of with a structure variable. The member names inside a structure should be mismatched from one another but these names can be alike to any other variable name state outside the structure. The member names of two different structures also be same.

 

Let us take an example of describe a structure format.

                struct student {

                                                char name [20];

                                                int rollno;

                                                float marks;

                                                };

Here student is the structure label and there are three members of this structure viz rollno, name and marks. Structure format can be explain globally or locally i.e. it can be put down before all functions in the program or it can be locally near in a function. If the format is global then it can be used by all task while if it is local then only the function carry it can use it.


Computer stuff kit tricks of Topics 58.





Monday 12 June 2023

String Library Functions in C

What are string library functions?

There are several or some library functions used to manipulate or operate strings. The prototypes for these functions or task are in header file string.h. We’ll discuss or talk over some of them below-

string, library functions, c language, c program
String library function in C language image-1

1.1   strlen()

This function or task returns the length or distance of the string i.e. the number of characters or nature in the string excluding or not taking someone the terminating null character. It accepts or receives a single argument or difference of opinion, which is pointer to the first nature or character of the string. For example strlen(“computer”) returns the value 8. Similarly is s1 is an array that contains the name “hyderabad” then strlen(s1) returns the value 9.

1.2   strcmp()

This function or task is used for comparison or contrast of two strings. The comparison or contrast stops when either the end of string is reached or extend or the analogous or corresponding characters in the two strings are not same. The non-zero value returned or go back on mismatch is the difference of the ASCII values of the non-matching or un-matching characters of the two strings-

Strcmp(s1, s2) return a value-

<0 when s1<s2

=0 when s1==s2

>0 when s1>s2

Generally or normally we don’t use the exact or precise non-zero value returned in case of mismatch or discrepancy. We only need to know its sign or indication to compare the alphabetical place of the two strings. We can use this task to sort the strings alphabetically.

1.3   strcpy():

This task is used for copying on string to another string. Strcpy(str1, str2) duplicate str2 to str1. Here str2 is the source string and str1 is something is going or destination string. If str2= “computer” then this function duplicate “computer” into str1. This function takes pointers to two strings as arguments or logic and returns or goes back the pointer to first string.

1.4   strcat()

This task is used for concatenation or series of two strings. If first string is “abcd” and second string is “efgh” then after using this task the first string becomes “abcdefgh”.

Strcat(str1, str2); /*concatenates or series str2 at the end of str1 */

The null character or nature from the first string is removed, and the second, string is added or enhancing quality at the end of first string. The second string remains unchanged.

This task takes pointer to two strings as arguments or logic and returns a pointer to the first (concatenated or series) string.


Computer stuff kit tricks of Topics 57.




8051 Data type and Directives

What is 8051 data type and directives?

The 8051 microcontroller has only one data type or a particular kind of data item. It is the job of the programmer or a device that automatically controls the operation to break down data larger than 8 bits.

8051 microcontroller, data type and directives
Data types and Directives image-1

DB (define byte)

The DB directive is the most extensively or widely used data directive in the program for converting instructions or assembler. It is used to explanation or defines the 8-bit data. For decimal, the “D” after the decimal number is voluntary or optional, but using “H” (hexadecimal) and “B” (binary) for the others is required. Regardless or anyway of which is used, the assembler will change or convert the numbers into hex. To indicate or specify ASCII, simply place the characters or nature in quotation marks (‘like this’). The assembler will assign or allot the ASCII code for the numbers or nature or characters attention.

ORG (origin)

The ORG directive is the beginning of the address used to indicate or specify. After ORG can be either or similarity in hex or in decimal of the number that comes. It is decimal and assembler or instruction will change or convert it to hex form the number is not followed by H,.

EQU (equate)

This is used to define a constant or sustained without occupying or settled a memory location. For a data item but link or associates a continuous or constant value with a data marker or label the EQU directive does not set aside or apart storage so that when the label or marker appears in the program; of something else for the label, its constant value will be substituted or taking the place.

END directive

Another important pseudocode or used in program design is the END directive. This indicates or specify to the computing the end of the source (asm) file. Anything or no matter what after the END directive is ignored or take no notice of by the assembler, the END directive is the last line of an 8051 program or plan, meaning that in the source code. Some assemblers or computing use “.END” (notice the dot) instead of |”END”.


Computer stuff kit tricks of Topics 56.






Sunday 11 June 2023

Program counter and Rom space

What is Program counter and Rom space in the 8051?

We inspect or examine the capacity of the program counter (PC) listing in executing or implement an 8051 program. We also discuss or talk over ROM memory space or capacity for various 8051 family members.

8051 program counter, 8051 ROM space, embedded PC
Program counter and ROM space image-1

Program counter in the 8051

Another important or main register in the 8051 is the (program counter) PC. The program counters points or tip to the address of the next instruction or command to be executed. However, not all members or a constituent piece of a complex structure of the 8051 have the entire 64K bytes of on-chip ROM installed or put, as we will see soon.

Where the 8051 wakes

One question that we must ask or query about any microcontroller (or microprocessor) is: At what address does the CPU come to or wake up upon applying power to it? Each microprocessor is different or unlike. The 8051 family the microcontroller come to at memory address 0000 (that is, all members regardless and variation), when it is powered up. By force or powering up we mean applying Vcc to the RESET pin. In other words, when the 8051 is powered or force up, the PC (program counter) has the value of 0000 in it. Looks for the first instruction or command when it is booted. We achieve this by the ORG statement or declaration in the source program as shown earlier.

Placing code in program ROM

To get a better understanding or grip of the role of the program counter in fetching or adorable and executing or perform a program, we examine or survey the action of the program counter as each instruction or command is fetched or get and executed. As we can see, the opcode and operand for each instruction or command are listed on the left side of the list file.

After the program or plan is burned into ROM of an 8051 family member like as AT8951 or 8751, the opcode and operand are placed or set in the ROM memory locations starting at 0000.


Computer stuff kit tricks of Topics 55.









Saturday 10 June 2023

Assembling and 8051 program

What is assembling and running an 8051 program?

Now that the basic or primary form of an Assembly language program has been given, the next question is: How it is created or generates, assembled, and made ready to run? The steps to create an executable or program Assemblylanguage program are outlined as follows.

8051 C program, c coding, assembling program
Assembling and 8051 program image-1

1.     First we use a computer program enabling the user to enter or editor to type in a program. Many outstanding or excellent editors or word processors are accessible or available that can be used to create and/or edit the program. A widely or range used editor is the MS-DOS EDIT program (or Notepad in Windows), which comes or near with all Microsoft operating systems.

For many assemblers, the file names follow the usual or habitual DOS conventions or compact, but the source or origin file has the extension or addition “asm” or “src”, depending or be controlled on which assembler you are using. Check your assembler for the convention or a way in which something is usually done.

 2.        The assembler converts or changes the instructions into machine code. The assembler will produce or build an object file and a list file.

 3.       Assemblers require or need a third step called linking. The link program takes or gets hold of one or more object files and produces or builds an absolute object file with the extension or addition “abs”. This abs file is used by 8051 trainers or instructor that has a monitor or detector program.

 More about “asm” and “obj” files

The “asm” file is also called the source or origin file and for this reason or cause some assemblers require that this file have the “src” extension.

Check your 8051 assembler or a program for converting instructions to see which extension it requires. As mentioned or bring up earlier, this file is created or produce with an editor such as DOS EDIT or Windows Notepad. In addition to creating or produce the object file, the assembler also produces the 1st file (list file).


Computer stuff kit tricks of Topics 54.





Friday 9 June 2023

Strings in C language

What is Strings in C language?

There is no unrelated or separate data type for strings in C. They are use or treated as arrays of type char. A character array is a string or typically character if it ends with a null character (‘\0’). This null character is an run off or escape sequence with ASCII value 0. Strings are generally or normally used to store and manipulate or operate data in text form like words or sentences.

Strings in c, c program, string constant
String in C language image-1

1.1   String Constant or String Literal

A string constant or sustained is a sequence of characters enclosed or surrounded in double quotes. It is sometimes from time to time called a literal. The double quotes or repeat are not a part of the string.

Whenever a string constant or sustained is written anywhere in a program, it is stored somewhere or to some place in memory as an array of characters terminated or end by a null character (‘\0’). The string constant or sustained itself becomes a pointer to the first character in the array.

 Each character live in or occupies one byte and compiler automatically or no direct human control inserts the null character at the end. The string sustained or constant “The Mahal” is actually a pointer to the character ’T’. So whenever a string constant or sustained is used in the program it is replaced by a pointer pointing to the string.

 If we have a pointer variable or changing of type char*, then we can assign or allot the address of this, string constant to it as –

Char *p=”The mahal”;

Similarly when we write –

Printf(“computer stuff kit\n”);

Then actually or literally a pointer to character (char*) is passed to the printf() function.

If identical or similar string constants or sustained are used in a program, they will be stored separately or one by one at different memory locations. For example if a string sustained or constant “India” appears three times in a project or program then it will be stored thrice in memory.

We have studied that a string constant or sustained gives the address of first character in it, but there is an exception or deviation to this rule; when the string constant is used as an initialize or set to the value for a character array then it does not represent or appear for any address and it is not stored anywhere in memory. For example –

 char arr [5]=”Keep”

Here the string sustained or constant “Keep” is not stored in memory and hence does not represent or appear for any address. Note or record that the ‘b’ and “b” are different. ‘b’ is a character constant which represents or appear for the ASCII value of character ‘b’ while “b” is a string sustained or constant which consists of character ‘b’ and null character ‘\0’.


Computer stuff kit tricks of Topics 53.