What is the ram of a computer?
What is the ram memory: Memory cell in computer
Entire In programming world, we use to operate on System
memory that is RAM memory.
Entire RAM has divided in numbers of equal parts, which are
known as memory cells. Following diagram represents the 256
MB RAM.
Each cell can store one-byte data. Data are stored in the
binary number system. That is a character data reserves one
memory cell while floating data reserves four memory cells.
binary number system. That is a character data reserves one
memory cell while floating data reserves four memory cells.
Each memory cell has unique address. Address is always in
whole number and must be in increasing order. We will discuss
how a characters, integers etc. data are in stored in the
data type chapter. Just for now assume
whole number and must be in increasing order. We will discuss
how a characters, integers etc. data are in stored in the
data type chapter. Just for now assume
int a = 4;
Here variables a stores in the memory in the flowing way:
If you know memory address of first cell is 0x5000 then
what would be the memory address of next memory cell?
what would be the memory address of next memory cell?
It will 5001 since integer data always stores at
continuous memory location and as we know memory address
always in increasing order.
continuous memory location and as we know memory address
always in increasing order.
what is resident memory
What is resident memory of a computer?
RAM has divided into two parts:
(1) Extended memory (useless)
(2) Residence memory
In Turbo C 3.0 compiler size of residence memory is 1MB.
resident memory:
When any program is executed it is stored in the
residence memory. For turbo c 3.0, it has 1MB residence
memory i.e. when we open turbo c 3.0 it stores 1MB in the
RAM.
residence memory. For turbo c 3.0, it has 1MB residence
memory i.e. when we open turbo c 3.0 it stores 1MB in the
RAM.
Physical address of a computer
Logical address and physical address: How to find
physical address of computer or operating system
All the c variables are stored in the residence memory.
or get a physical address of a RAM
All the c variables are stored in the residence memory.
In turbo C 3.0, 20 bits address of the memory cell is
known as physical address or real address. In 20 bits,
we can represent address from 0x00000 to 0xFFFFF. That
is all c variables must have memory address within this
range.
known as physical address or real address. In 20 bits,
we can represent address from 0x00000 to 0xFFFFF. That
is all c variables must have memory address within this
range.
A C programmer cannot not decides what will be the memory
address of any variables. It is decided by compiler. For Example:
What will be output of following c cod
#include<stdio.h>
int main(){
int a;
printf("%x",&x);
return 0;
}
Output: We cannot predict.
But we can say in 16 bits compilers address must be
within 0x0000 to 0xFFFF and in 32 bits compilers memory
address must be within 0x00000000 to 0xFFFFFFFF.
Note: Suppose your c compiler is based on the
microprocessor which total address buses are 32 then its
total size of addressable memory will be:
= 2 ^ 32 bytes
= 4 GB
Memory segment | Segment address
Memory segmentation in 8086 microprocessor :
Segmented memory
Segmented memory
Resident memory of RAM of size 1MB has divided into 16
equal parts. These parts is called segment. Each segment
has size is 64 KB.
equal parts. These parts is called segment. Each segment
has size is 64 KB.
This process of division is known as segmentation.
Note: In turbo c 3.0 physical addresses of any variables
are stored in the 20 bits. But we have not any pointers
(We will discuss later what is pointer?)of size 20 bits.
So pointers cannot access whole residence memory
address.To solve this problem we there are three types
pointers in c language. They are
1. Near pointer
2. Far pointer
3. Huge pointer
What is offset address
What is offset address?
Offset address and segment number in c programming language
Each segment has divided into two parts.
1. Segment no (4 bit)
2. Offset address (16 bit)
So, in the other words we can say memory address of any variable in c has two parts segment number and offset address.
In turbo c 3.0 a particular segment number offset address varies from 0x0000 to 0xFFFF
Suppose physical address of any variable in c is 0x500F1.
Then its segment number is 5 and offset address is 00F1.
Write a program to find the offset address of any variable?
#include<stdio.h>
int main(){
int x;
printf("%u ",&x); //To print offset address
printf("%p ",x); //To print segment address
printf("%p ",&x); //To print offset address
printf("%fp ",&x); //To print segment address : offset address
return 0;
}
Data segment in c
All the segments are used for specific purpose. Like segment number 15 is used for ROM, segment number 14 is used for BIOS etc.
We will discuss about how to access text video memory, graphics video memory in the pointer and union chapters of 255 bits color graphics programming.
1. Stack area
All automatic variables and constants are stored into stack area. Automatic variables and constants in c:
1. All the local variables of default storage class.
2. Variables of storage calls auto.
3. Integer constants, character constants, string constants, float constants etc in any expression.
4. Function parameters and function return value.
Variables in the stack area are always deleted when program control reaches it out of scope. Due to this stack area is also called temporary memory area. For example:
What will be output of following c code?
#include<stdio.h>
int main(){
int i;
for(i=0;i<3;i++){
int a=5;
printf("%d",a);
}
return 0;
}
Output: 5 5 5
Explanation: Since variable a is automatic variable, it will store in the stack area. Scope of variable a is within for loop. So after each iteration variable a will be deleted from stack and in each iteration variable a will initialize.
This two concepts are only for Turbo C 3.0
It follows LIFO data structure. That in the stack area of memory data is stored in last in first out. For example:
What will be output of flowing c code. (Turbo c 3.0)?
#include<stdio.h>
int main(){
int a =5, b = 6, c = 7,d =8;
printf("%d %d %d");
return 0;
}
Output: 8 7 6
Explanation:
Default storage class of variables a, b, c and d is auto .Since it automatic variable it will be sorted in the stack area of memory. It will store in the stack as
Stack always follows LIFO data structure. In the printf function, name of variables is not written explicitly. So default output will content of stack which will be in the LIFO order i.e. 8 7 6.
It has two part one for initialize variable another for non-initialize variable. All initialize variables are more nearer than not initialized variable and vice versa. For example:
What will be output of following program (Turbo c 3.0)?
#include<stdio.h>
int main(){
int a =5, b, c =7;
printf("%d %d %d");
return 0;
}
Output: 7 5 garbage value
Explanation:
Automatic variable a and c has initialized while b has not initialized. Initialize variables are more nearer than uninitialized variable .They will be stored in the stack. So due to LIFO first output will be 7 then 6 (since a is more nearer than b with respect to c) then any garbage value will be output which is present in the stack.
Note: Default storage class of any local variable is auto.
2. Data area:
All static and extern variable are stored in the data area. It is permanent memory space and variable will store in the memory unless and until program end. For example:
What will be output of following c code?
#include<stdio.h>
int main(){
int i;
for(i=0;i<3;i++){
static int a=5;
printf("%d",a);
}
return 0;
}
Output: 5 6 7
3. Heap area:
This memory area is use to allocate memory dynamically. In c we can allocate the memory space dynamically by using function malloc and calloc. It always allocates memory in the heap area. Its size is variable and depends upon free space in the memory.
4. Code area:
Function pointer can only access code area. Size of this area is always fixed and it is read only memory area.
No comments:
Post a Comment