0% found this document useful (0 votes)
18 views14 pages

Index: Sl. No Experiment Name Page No

The document outlines a series of experiments for an Advanced Embedded Systems Lab, including creating child processes and threads, implementing multi-thread applications, and writing assembly language programs for various tasks. Each experiment includes a description, program code, and expected output. The experiments cover topics such as process management, thread synchronization, and basic assembly programming techniques.

Uploaded by

iamunderwater45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views14 pages

Index: Sl. No Experiment Name Page No

The document outlines a series of experiments for an Advanced Embedded Systems Lab, including creating child processes and threads, implementing multi-thread applications, and writing assembly language programs for various tasks. Each experiment includes a description, program code, and expected output. The experiments cover topics such as process management, thread synchronization, and basic assembly programming techniques.

Uploaded by

iamunderwater45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

INDEX

Sl. no Experiment Name Page no.


Develop and test programs:
1 a) To create child process and display it’s ID. 1
b) Execute child process function using switch structure.

2 Create ‘n’ number of child threads. Each thread prints the message 2
“I’m in thread number …” and sleeps for 50 ms and then quits.
The main thread waits for complete execution of all the child
threads and then quits. Compile and execute in Linux.
3 Implement the multi-thread application satisfying the following: 3
a) Two child threads are created with normal priority.
b) Thread 1 receives and prints its priority and sleeps for 50ms
and then quits.
c) Thread 2 prints the priority of the thread 1 and rises its priority
to above normal and retrieves the new priority of thread 1, prints it
and then quits.
d) The main thread waits for the child thread to complete its job
and quits.
4 Write ALP to find the square of a number (1 to 10) using look-up 7
table

Write an ALP to arrange a series of 32-bit numbers in


5 a) ascending order 8
b) descending order

6 Write an ALP to count the number of ones and zeros in two 10


consecutive memory locations
7 Interface a simple Switch and display its status through Relay, 11
Buzzer and LED.
ADVANCED EMBEDDED SYSTEMS LAB

Experiment No. 1

Develop and test programs:


a) To create child process and display it’s ID.
b) Execute child process function using switch structure.

Program:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

void childFunction(int choice) {


switch (choice) {
case 1:
printf("Child process executing task 1...\n");
break;
case 2:
printf("Child process executing task 2...\n");
break;
default:
printf("Child process executing default task...\n");
}
}
int main() {
pid_t pid;

pid = fork(); // Create child process

if (pid < 0) {
perror("Fork failed");
return 1;
} else if (pid == 0) { // Child process
printf("Child Process: PID = %d, Parent PID = %d\n", getpid(), getppid());
childFunction(1); // Call child function with a switch statement
exit(0); // Exit child process
} else { // Parent process
printf("Parent Process: PID = %d, Child PID = %d\n", getpid(), pid);
wait(NULL); // Wait for child to complete
}
return 0

Output:
Parent Process: PID = 12345, Child PID = 12346
Child Process: PID = 12346, Parent PID = 12345
Child process executing task 1...
M.Tech in VLSI Design & Embedded System
Dept. of ECE VTU CPGS Kalaburagi Page 1
ADVANCED EMBEDDED SYSTEMS LAB

Experiment No.2
Create ‘n’ number of child threads. Each thread prints the message “I’m in
thread number …” and sleeps for 50 ms and then quits. The main thread
waits for complete execution of all the child threads and then quits. Compile
and execute in Linux.

Program:
#include<stdio.h>
#include<pthread.h>

pthread_t tid[5];

void *thread_print(void *n){


1
printf("I AM IN THREAD %d\n",n);
sleep(5);
}

int main(){

int n=5;
int ret;
int i;

for(i=0;i<5;i++){
// Create thread using POSIX standards
ret = pthread_create(&tid[i], NULL, &thread_print, (void *) i);
}

// Main thread has to wait for child thread


for(i=0;i<5;i++){
pthread_join( tid[i], NULL);
}
}

Compilation in Linux with gcc compiler


>> gcc -pthread <program.c>
>> ./a.out

Output:
I'M IN THREAD NUMBER 0
I'M IN THREAD NUMBER 1
I'M IN THREAD NUMBER 2
I'M IN THREAD NUMBER 3
I'M IN THREAD NUMBER 4

M.Tech in VLSI Design & Embedded System


Dept. of ECE VTU CPGS Kalaburagi Page 2
ADVANCED EMBEDDED SYSTEMS LAB

Experiment No.3

Implement the multi-thread application satisfying the following:


a) Two child threads are created with normal priority.
b) Thread 1 receives and prints its priority and sleeps for 50ms and then
quits.
c) Thread 2 prints the priority of the thread 1 and rises its priority to above
normal and retrieves
the new priority of thread 1, prints it and then quits.
d) The main thread waits for the child thread to complete its job and quits.

Program:

#include<stdio.h>
#include<pthread.h>
#include<sys/types.h>
#include<unistd.h>
#include<stdlib.h>
#include<semaphore.h>
#include<string.h>
#include<stdlib.h>
#include<fcntl.h>

sem_t empty,full,mutex;
char child_buf[512];

// Path to create the fifo, /tmp can be used


char *myfifo = "/home/fedora/GANESH/M_TECH_VLSI_LAB_TWO/pipe/myfifo.txt";

char end_msg[] = "WM_QUIT"; // End msg

//child thread

void * Child_Thread(void* arg)


{

int j=1,k=0;

int r_fd = open(myfifo,O_NONBLOCK);

M.Tech in VLSI Design & Embedded System


Dept. of ECE VTU CPGS Kalaburagi Page 3
ADVANCED EMBEDDED SYSTEMS LAB

while(j)
{
k++;

sem_wait(&full); // Wait till parent writes into fifo


sem_wait(&mutex); // Wait if parent is writing, if not get the lock on
binary semaphore to read from fifo

int f= read(r_fd, &child_buf, sizeof(child_buf));


//sleep(4);

printf("Inside the child (CONSUMER) consumed item is:%s %d\n\n",child_buf,k);


sem_post(&mutex);
sem_post(&empty);

if( *child_buf == *end_msg)


{
j=0;
}
}
pthread_exit(NULL);
}

/*

Parent thread (Main thread)


This will opens a file in fifo mode, creates child thread, and writes into fifo

*/
int main()
{
pthread_t pid1,pid2;

int item=1,i=0;
char *parent_msg;
int fi = mkfifo(myfifo, 0666); // Create fifo

//printf("fifo creation %d\n",fi);

int w_fd = open(myfifo,O_RDWR); // open fifo for write and read

sem_init(&empty,0,10); // Semaphore signal used to


indicate fifo is empty
sem_init(&full,0,0); // Semaphore signal to indicate fifo is full
sem_init(&mutex,1,1); // Mutex to indicate lock, binary
semaphore is used here

M.Tech in VLSI Design & Embedded System


Dept. of ECE VTU CPGS Kalaburagi Page 4
ADVANCED EMBEDDED SYSTEMS LAB

pthread_create(&pid1,NULL,Child_Thread,NULL);
printf("\n\nthread created\n");

while(item)
{
i=i++;
int k = rand(); // to generate random number of parent msg's
if((k % 10) < 3){

item = 0;
parent_msg = "WM_QUIT";
}
else
{ parent_msg = "Hi I am parent";
}

printf("parent msg %s\n",parent_msg);

sem_wait(&empty); //Wait till fifo becomes empty


sem_wait(&mutex); // Wait if child thread is reading, else lock
the binary semaphore

int p = write(w_fd, parent_msg, (strlen(parent_msg)+1));

printf("Inside parent(PRODUCER) item produced is %s %d\n\n",parent_msg,i);

sem_post(&mutex);
sem_post(&full);
sleep(1);

}
pthread_join(pid1,NULL);
//printf("xxxxxxxxxxxxxx\n");
return 0;
}

M.Tech in VLSI Design & Embedded System


Dept. of ECE VTU CPGS Kalaburagi Page 5
ADVANCED EMBEDDED SYSTEMS LAB

Output:

Thread created
Parent message: Hi, I am the parent
Inside parent (PRODUCER) - Produced: Hi, I am the parent [1]

Inside the child (CONSUMER) - Consumed: Hi, I am the parent [1]

Parent message: Hi, I am the parent


Inside parent (PRODUCER) - Produced: Hi, I am the parent [2]

Inside the child (CONSUMER) - Consumed: Hi, I am the parent [2]

Parent message: WM_QUIT


Inside parent (PRODUCER) - Produced: WM_QUIT [3]

Inside the child (CONSUMER) - Consumed: WM_QUIT [3]

Main thread exiting...

M.Tech in VLSI Design & Embedded System


Dept. of ECE VTU CPGS Kalaburagi Page 6
ADVANCED EMBEDDED SYSTEMS LAB

Experiment No.04

Write ALP to find the square of a number (1 to 10) using look-up table

Program:

AREA SQUARE, CODE,READONLY


ENTRY
LDR R0,=TABLE
MOV R1,#6
MOV R1,R1,LSL #0x2
ADD R0,R0,R1
LDR R3,[R0]
STOP B STOP
TABLE DCD 0x00000000
DCD 0x00000001
DCD 0x00000004
DCD 0x00000009
DCD 0x00000010
DCD 0x00000019
DCD 0x00000024
DCD 0x00000031
DCD 0x00000040
DCD 0x00000051
DCD 0x00000064
END

Output:

R3=24(36 in hexadecimal )

M.Tech in VLSI Design & Embedded System


Dept. of ECE VTU CPGS Kalaburagi Page 7
ADVANCED EMBEDDED SYSTEMS LAB

Experiment No.05

Write an ALP to arrange a series of 32-bit numbers in


a) ascending order
b) descending order

a)ascending order
Program:

AREA ASCENDING, CODE, READONLY


ENTRY
START MOV R8,#4
LDR R2,=CVALUE
LDR R3,=DVALUE
LOOP0 LDR R1,[R2],#4
REGION STR R1,[R3],#4
SUBS R8,R8,#1
CMP R8,#0
BNE LOOP0
START1 MOV R5,#3
MOV R7,#0
LDR R1,=DVALUE
LOOP LDR R2,[R1],#4
LDR R3,[R1]
CMP R2,R3
BLT LOOP2
STR R2,[R1],#-4
STR R3,[R1]
MOV R7,#1
ADD R1,#4
LOOP2 SUBS R5,R5,#1
CMP R5,#0
BNE LOOP
CMP R7,#0
BNE START1
NOP
NOP
NOP
CVALUE DCD 0X44444444
DCD 0X11111111
DCD 0X33333333
DCD 0X22222222
AREA DATA1,DATA,READWRITE
DVALUE DCD 0X00000000
END

Output:
Memory register 0x40000000:11 11 11 11 22 22 22 22 33 33 33 33 44 44 44 44 00 00 00 00

M.Tech in VLSI Design & Embedded System


Dept. of ECE VTU CPGS Kalaburagi Page 8
ADVANCED EMBEDDED SYSTEMS LAB

b)descending order

Program:

AREA DESCENDING, CODE, READONLY


ENTRY
START MOV R8,#4
LDR R2,=CVALUE
LDR R3,=DVALUE
LOOP0 LDR R1,[R2],#4
REGION STR R1,[R3],#4
SUBS R8,R8,#1
CMP R8,#0
BNE LOOP0
START1 MOV R5,#3
MOV R7,#0
LDR R1,=DVALUE
LOOP LDR R2,[R1],#4
LDR R3,[R1]
CMP R2,R3
BGT LOOP2
STR R2,[R1],#-4
STR R3,[R1]
MOV R7,#1
ADD R1,#4
LOOP2 SUBS R5,R5,#1
CMP R5,#0
BNE LOOP
CMP R7,#0
BNE START1
NOP
NOP
NOP
CVALUE DCD 0X44444444
DCD 0X11111111
DCD 0X33333333
DCD 0X22222222
AREA DATA1,DATA,READWRITE
DVALUE DCD 0X00000000
END

Output:

Memory register 0x40000000:44 44 44 44 33 33 33 33 22 22 22 22 11 11 11 11 00 00 00 00

M.Tech in VLSI Design & Embedded System


Dept. of ECE VTU CPGS Kalaburagi Page 9
ADVANCED EMBEDDED SYSTEMS LAB

Experiment No.6

Write an ALP to count the number of ones and zeros in two consecutive
memory locations.

Program:
AREA ONEZERO,CODE,READONLY
ENTRY
MOV r2,#0;
MOV r3,#0;
MOV r7,#2
LDR r6,=VALUE
LOOP MOV r1,#32
LDR r0,[r6],#4
LOOP0 MOVS r0,R0,ROR#1
BHI ONES
ZEROS ADD r3,r3,#1
B LOOP1
ONES ADD r2,r2,#1
LOOP1 SUBS r1,r1,#1
BNE LOOP0
SUBS r7,r7,#1
CMP r7,#0
BNE LOOP
BACK B BACK
VALUE DCD 0X11111111,0XAA55AA55
END

Output:

r2 (number of 1s) = 48 (0x30)


r3 (number of 0s) = 16 (0x10)

M.Tech in VLSI Design & Embedded System


Dept. of ECE VTU CPGS Kalaburagi Page 10
ADVANCED EMBEDDED SYSTEMS LAB

Experiment No.7

Interface a simple Switch and display its status through Relay, Buzzer and
LED.

M.Tech in VLSI Design & Embedded System


Dept. of ECE VTU CPGS Kalaburagi Page 11
ELECTRONICS AND COMMUNICATION LAB

Program:

#include <LPC213x.h>
void delay()
{
int i,j:
for(i=0;i<1000;i++)
for(j=0,j<100;j++);
}
int main (void)
{
IO0DIR = 0X01;
while (1)
{
if ((IO0PIN & 91<<2))==0)
{
IO0SET |= (1<<0);
}
else
{
IO0CLR |=(1<<0);
}
}

M.Tech in VLSI Design & Embedded System


Dept. of ECE VTU CPGS Kalaburagi Page 11
ELECTRONICS AND COMMUNICATION LAB

M.Tech in VLSI Design & Embedded System


Dept. of ECE VTU CPGS Kalaburagi Page 13

You might also like