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.



Thursday 8 June 2023

Pointers and Functions in C

What are Pointers and Functions in C?

The difference of opinion to the functions can be passed in two ways –

1.       Call by Value

2.       Call by Address

In call by value, only the values of arguments are sent to the function while in call by remark about, mark of arguments are sent to the purpose. In call by value procedure, any interchange made to the formal reasoning will not throw back on the real arguments.

Pointers in c language, Function in C language, call by value
Pointers and Functions in C language image-1

C uses only call by value when progress arguments to a function, but we can reproduce call by address by using pointers.

Here a and b are variables announced in the function main() while x and y are announced in the function value(). These an element resides at different addresses in store. Whenever the function value() is called, two variables are produce named x and y and are set to the value with the values of variables a and b.

This type of a limit going past is called call by value since we are only provide the values of real arguments to the calling function. Any working performed on variables x and y in the function value(), will not affect variables a and b.

Even though C does not use call by address, but we can reproduce it by passing addresses of variables as arguments to the function. To receive the addresses internal the function, we will need pointer variables.

Here we are progress mark of variables a and b in the function call. So the be given formal arguments in the function statement should be announced of pointer type. Whenever function ref() is called, two pointer to int variables, named p and q, we will be able to entrance variables a and b from function ref().

1.1   Function returning Pointer

We can have a function that come back a pointer. The syntax of statement of such type of function is –

Type *func(typ1, type2,…….);

While go back a pointer, make sure that the reminder address go back by the pointer will exist even after the the physical end of something of function.

Here we are come back a pointer which points to a regional variable. We know that a local variable live only inside the function. Take for granted the variable x is stored at address 2500, so the value of p will be 2500 and this value will be go back by the function func(). As soon as func() terminates, the local variable x will cause to live.

The address come back or returned by func() is allot or assigned to pointer variable ptr inside main(), so now ptr will carry or contain address 2500. When we dereference or obtain the address of a data item held in another location from ptr, we are the action or typing to entry or access the value of a variable that no longer exists. So never or at no time go back or return a pointer that point to a local variable.


Computer stuff kit tricks of Topics 52.








Wednesday 7 June 2023

Arrays and Pointers in C

What are Arrays and Pointers?

The variables that we have used till now are efficient of set aside only one worth at a time. Think about a position when we want to store and show the age of 100 employees.  There are three type of following:

arrays, pointers, c language, c program
Pointers and Arrays in C language image-1

1.       Declare 100 unlike variables to store the age of employees.

2.       Assign a value to each variable.

3.       Display the value of each variable.

In spite of the fact that we can perform our task by the above three steps but just visualizes how difficult it would be to pick up so many variables in the program and the program would begin to be very lengthy. The idea of arrays is useful in these types of position where we can group alike kind of data items.

An array is an assembly of similar type of data thing and each data item is called an component of the array. The elements of array part the same variable name but each element has a unlike lead number known as subscript.

For the above sample we can take an array variable age[100] of type int. The size of this array variable is 100 so it is ability of storing 100 integer values. The separate elements of this array are –

Age [0], age[1], age[2], age[3], ………………………………………………………..age[98], age[99]

Arrays can be one dimensional or multidimensional. The number of subscripts decide the dimension of array. A one-dimensional array has one subscript, two dimensional array has two subscripts and so on.

1.1   One Dimensional Array

 

1.1.1          Declaration of 1-D array

Like other easy variables, arrays should also be declared previous to they are used in the program.  The following syntax declaration of an array is –

Data_type array_name[size];

Here array_name indicate the name of the array and it can be any reasonable C identifier, data_type is the data type of the elements of array. The size of the array defines the number of elements that can be set aside in the array.

Some examples of array declarations –

int age[100];

float sal[5];

 char grade[20];

1.1.2          Accessing 1-D Array Elements

Identify the array name followed by subscript in square bracket can entrance the elements of an array. In C, the array start subscripts from 0.

1.1.3          processing 1-D Arrays

For take care of arrays we generally use a for loop and the variable is used at the site of subscript. The beginning value of loop variable is taken 0 since array subscripts from zero. The loop variable is enlarging by 1 each time so that we can entry and processes the next element in the array.


Computer stuff kit tricks of Topics 51.







Tuesday 6 June 2023

Function in C

What is function in C language?

A function is independent subprogram that is denoting to do some specific, described task. A C program be made up of one or more functions. If a program has only one purpose then it must be the main() function.

Function in C language, function returning value
Function in C language image-1

1.1   Advantages of using functions:

1.       Normally a inconvenient problem is separated into sub problems and then solved. This divided and beat skill is implemented in C through functions. A program can be separated into functions, each of which executes some particular task. So the use of C functions designed or produced in separate piece or parts and divides the work of a program.

2.       When some particular code is to be used more than once and at dissimilar places int eh program, the use of functions keep away from retelling of that code.

3.       The program suit simply comprehensible, modifiable and easy to detect and test. It becomes easy to write the program and interpret what work is done by each part of the program.

4.       Functions can be retaining in a library and the state or quality of  being reusable can be achieved.

C programs have two types of functions:

1.       Library functions

2.       User-defined functions

 

1.2   Library functions

C has the space to prepare library functions for carry out some working. These functions are present in the C library and they are limited. The functions scanf() and printf() are input output library task. Similarly we have functions like strlen(), strcmp() for string unscrupulous.

To use a library function we have to embrace function header file using the hardware or software that processes information before it heads to another program directive #include. For example to use input output task like printf(), scanf() we have to embrace stdio.h, for string library string.h should be included.

 

1.3   User-Defined Functions

Users can produce their own function for execute any particular task of the program. These types o functions are called varied by the user functions. To create and use these functions, we should know about these three things they are:

1.       Function definition

2.       Function call

3.       Function declaration

 

1.4   Function definition

The function definition is made up of the whole illustration and code of a function. It tells what the task is doing and what are its inputs and outputs. A function definition contain of two parts – a function header and a function body.

 

1.5   Function call

The function definition report what a function can do, but to literally use it in the program the function should be called to some place. A function is called by simply writing its name come after by the disagreement list inside the parentheses.

 

1.6   Function Declaration

The calling function needs data about the called function. If explanation of the called function is placed before the calling function, then statement is not needed.


Computer stuff kit tricks of Topics 50.




Monday 5 June 2023

Control statements in C

What are Control statements?

In C programs, statements are performing sequentially in the organization in which they look in the program. But occasionally we may want to use a state for perform only a part of program. Also many affairs arise where we may want to program some statements some times. Control statements allow us to specify the order in which the many order in the program are to be executed. This control the flow of control. Control statements visibility how the control is move to other parts of the program. C language bear four types of control statements, which are as follows:

If ….else, loop, while, goto, switch, do…. while, for.

C programs, Loop, while, goto, switch, do
Control Statements in C language image-1

1.1   compound statement or block

A compound statement or a block is a set of statements surrounded within a match of wavy braces {}.

The statements inside the slab are implementing sequentially.

A compound statement is syntax similar to a one statement and can look anywhere in the program where a one statement is permit.

1.2   if…..else

If…else is a bi-directional conditional control statement. This statement is used to check a condition and take one of the two viable actions. If the condition is correct then a one statement or a block of statements is (one part of the program) performed, otherwise another single statement or a block of statements is (other part of the program) performed. Remember that in c, any nonzero value is regarded as true while zero is look on as false.

1.3   Nesting of if….else

We can have another if….else statement in the if chunk or the else hunk. This is called nesting of if….else statements. Here is an example of nesting where we have if…..else inside both if block and else block.

1.4   else if Ladder

This is a kind of nesting in which there is an if….else statement in each else part excepting the last else part. This type of nesting is often used in plan and also known as else if ladder. Here each condition is checked, and when a order is found to be true, the statements corresponding to that are programmed, and the control comes out of the nested form without checking still existing conditions. If none of the conditions is correct then the last else part is programmed.

1.5   Loops

Loops are used when we want to programmed a part of the executed or a block of statements some times. For examples, assume we want to print “C is best” 10 times. One way to get the wished output is – we write 10 printf statements, which is not better. Other way out us – use loop. Using loop we can write one loop statement and only one printf statement, and this speak to is definitely better than the first one.