Wednesday, August 26, 2015

Simple explanation of linked list

// linked list code

#include <stdio.h>
#include <stdlib.h>
#define max 10


typedef struct list
{
int dat;
   struct list *next;

}list;


int main()
{    
     list a,b,c,d,e;  // list variables
    list *ptr;   // pointer of type list whihc points to list variables
     a.dat =5;
     a.next= &b;
     b.dat=4;
     b.next =&c;
     c.dat=3;
     c.next =&d;
     d.dat=3;
     d.next=NULL;
     ptr=&a;
 while(ptr!=NULL)
 {
     printf("value at location %d \n", ptr->dat);
     ptr=ptr->next;
 }


return 0;

}

Efficient stack implementation with pointers

 below is the code which implements a stack of size 10.  Pointer are used to easily push and pop the data. please feel free to use the code. can be used in the gcc compiler. Please feel free to use any functionality. change the max value and you can change it to what ever size stack you want...


 Source Code:
#include <stdio.h>
#include <stdlib.h>
#define max 10
int pos;
int *pop(int *pnt)
{
    int val=0;
    if(pos==0)
    {
        printf("no elements to delete ");
    }
    else
    {

    printf(" deleted value is %d ",*pnt);
    pnt--;
    pos--;
    }
    return pnt;

}
int push(int *pntr)
{
     int cntr;
    int val;

    if(pos==10)
    {
        printf("stack limit reached \n");
        printf("pop out a member first\n");
    }
    else{
        printf("enter the value to push \n");
        scanf("%d",&val);
        *pntr=val;
        pos=pos+1;
        printf("stack location %d \n",cntr);
    }

    return pos;
}
void ex()
{
    exit(0);

}




void prstck(int cnt,int *pt)
{
    int i;
    for(i=pos-1;i>=0;i--)
    {
        printf(" stack elem at locn  %d : %d  \n", i,*pt);
        pt--;
    }

}



int main()
{
int st[10];
int sel=0;
int cnt;
int *stp;      // stack pointer.
int *pppntr;

stp=st;

while(1)
{
  printf("enter your selection \n");
  printf("\n 1.push  2. pop  3. exit 4. display stack ");
  scanf("%d",&sel);

switch(sel)
{

    case 1 : stp++;
        cnt=push(stp);

             break;
    case 2 : pppntr= pop(stp);
             stp=pppntr;
             break;
    case 3 : ex();
             break;
    case 4 : prstck(cnt-1,stp);
             break;
    default : printf("no value entered \n");
                break;

}
}
return 0;
}















Thursday, August 20, 2015

ARM Development:: *** error 65: access violation at 0x40023800 : no 'read' permission --- FIX ARM

Hi,
Guess you are starting to learn the ARM development, and being a begineer in ARM,, getting this error is the most common issue... Its very easy to handle and it is fixable.. but you have to do it every time you start running the code in the keil simulator...


Before I recommend to view this page from ARM, you will get a basic idea what was that all about:

http://www.keil.com/support/docs/814.htm


So after reading this we know where the device MAP is but the question is what range of addresses I need to map:

Fro this we look at the error generated:

error 65: access violation at 0x40023800

Understanding the error:
From the documentation, form keil we understand that the address location pointed by the pointer in the RTOS, 0x40023800, is not available or the simulator cannot find the location. So it cannot perform read, write or execute anything at that location.

Resolve:
So now we try to map the range of addresses that the simulator want to access. For that , we see the error code and look for the address which is: 0x40023800.

Lets say we let it use the memory from 0x400000000 to  0x40FFFFFF, so that the location that the processor is trying to use is still in the range.

So we go to the

Debug-> Memory MAP
in the map range : 0x400000000,0x40FFFFFF
add these and select : read, write, execute.

and press run..