├── Cycle-1 ├── Bankeralgo.c ├── fcfs-tv.c ├── fcfs.c ├── fileAlloc.c ├── index.c ├── linkedAlloc2.c ├── priority-tv.c ├── priorty.c ├── roundRobin.c ├── rr-tv.c ├── sequentialFileAllocation.c ├── sjf-tv.c └── sjf.c ├── Cycle-2 ├── Basic arthimetric.kit ├── SearchingLinear.kit └── sorting.kit ├── Cycle-3 ├── Addition16bit.asm └── palindrome.asm ├── Cycle-4 ├── Absolute Loader │ ├── absoluteLoader.c │ └── input.txt ├── Macro Preprocessor │ ├── 2023-02-02 (9).png │ └── macrropp.c ├── Single Pass Assembler │ ├── input.txt │ ├── optab.txt │ ├── output.txt │ ├── singlepass.c │ ├── symtab.txt │ └── symtab1.txt ├── file.c ├── input.txt ├── intermediate.txt ├── length.txt ├── objcode.txt ├── optab.txt ├── output.txt ├── pass1.c ├── pass2.c └── symtab.txt ├── README.md └── mp new-staff[1524].docx /Cycle-1/Bankeralgo.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n, m, i, j, k, y,alloc[20][20],max[20][20],avail[50],ind=0; 5 | printf("Enter the no of Proceses:"); 6 | scanf("%d",&n); 7 | printf("Enter the no of Resources:"); 8 | scanf("%d",&m); 9 | printf("Enter the Allocation Matrix:"); 10 | for (i = 0; i < n; i++) { 11 | for (j = 0; j < m; j++) 12 | scanf("%d",&alloc[i][j]); 13 | } 14 | printf("Enter the Max Matrix:"); 15 | for (i = 0; i < n; i++) { 16 | for (j = 0; j < m; j++) 17 | scanf("%d",&max[i][j]); 18 | } 19 | printf("Enter the Available Matrix"); 20 | for(i=0;i work[j]) 51 | { 52 | flag = 1; 53 | break; 54 | } 55 | } 56 | if (flag == 0) { 57 | safesequence[ind++] = i; 58 | for (y = 0; y < m; y++) 59 | work[y] += alloc[i][y]; 60 | finish[i] = 1; 61 | } 62 | } 63 | } 64 | } 65 | printf("\nFollowing is the SAFE Sequence\n"); 66 | for (i = 0; i <= n - 1; i++) 67 | printf(" P%d ", safesequence[i]); 68 | } 69 | -------------------------------------------------------------------------------- /Cycle-1/fcfs-tv.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct process 3 | { int pid; 4 | float at,bt,ct,tat,wt,st; 5 | } p[100],temp; 6 | 7 | void fcfs(struct process a[100],int n) 8 | { 9 | int i,j; 10 | float avgtat = 0,avgwt = 0,time = 0,z=0; 11 | char s[]=" "; 12 | 13 | for (i=0;ia[j+1].at) 16 | { 17 | temp=a[j]; 18 | a[j]=a[j + 1]; 19 | a[j+1]=temp; 20 | } 21 | 22 | printf("\nGantt Chart\n"); 23 | for (i=0;i NULL\n",time-z,time); 29 | z=0; 30 | } 31 | a[i].st=time; 32 | time+=a[i].bt; 33 | a[i].ct=time; 34 | a[i].tat=time-a[i].at; 35 | a[i].wt=a[i].tat-a[i].bt; 36 | avgtat+=a[i].tat; 37 | avgwt+=a[i].wt; 38 | printf("%f - %f -> P%d\n",a[i].st,a[i].ct,a[i].pid); 39 | i++; 40 | } 41 | else 42 | { 43 | z++; 44 | ++time; 45 | } 46 | } 47 | 48 | avgtat/=n; 49 | avgwt/=n; 50 | 51 | for (i=0;ia[j+1].pid) 54 | { 55 | temp=a[j]; 56 | a[j]=a[j + 1]; 57 | a[j+1]=temp; 58 | } 59 | 60 | printf("\nProcess Id AT%s BT%s CT%s TAT%s WT\n",s,s,s,s); 61 | for(i=0;i 22 | 23 | int main(){ 24 | int n, bt[20], wt[20], tat[20], avwt = 0, avtat = 0, i, j; 25 | printf("Enter Total Number of processes (max 20) : "); 26 | scanf("%d",&n); 27 | 28 | printf("\n Enter Process Burst Time \n"); 29 | for( i = 0; i < n; i++){ 30 | printf("P[%d] : ",i+1); 31 | scanf("%d" , &bt[i]); 32 | } 33 | wt[0] = 0; 34 | for( i = 1; i < n ; i++){ 35 | wt[i] = 0; 36 | for ( j = 0; j < i; j++) 37 | wt[i] += bt[j]; 38 | } 39 | printf("\n Process \tBurst Time\tWaiting Time\tTurnaround Time"); 40 | 41 | for( i = 0; i < n; i++){ 42 | tat[i] = bt[i] + wt[i]; 43 | avwt += wt[i]; 44 | avtat += tat[i]; 45 | printf("\n P[%d] \t\t\t %d \t %d \t\t %d",i+1,bt[i],wt[i],tat[i]); 46 | } 47 | avwt /= i; 48 | avtat /= i; 49 | printf("\n\n Average Waiting Time:%d",avwt); printf("\n Average Turnaround Time:%d \n",avtat); 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /Cycle-1/fileAlloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define SIZE 50 4 | struct node 5 | { 6 | int data; 7 | int nextBlock; 8 | struct node *link; 9 | }*first=NULL,*last,*temp,*new; 10 | struct node memBlock[50]; 11 | int flag,prevBlock=-1; 12 | int check(int start, int size); 13 | void sequential(); 14 | void linked(); 15 | void indexed(); 16 | void main() 17 | { 18 | int choice; 19 | printf("\n1.Sequential Allocation\n2.Linked Allocation\n3.IndexedAllocation\n4.Exit\n"); 20 | printf("Enter a choice : "); 21 | scanf("%d", &choice); 22 | switch (choice) 23 | { 24 | case 1:{ 25 | sequential(); 26 | main(); 27 | break; 28 | } 29 | case 2:{ 30 | linked(); 31 | main(); 32 | break; 33 | } 34 | case 3:{ 35 | indexed(); 36 | main(); 37 | break; 38 | } 39 | case 4:{ 40 | break; 41 | } 42 | default:{ 43 | printf("\nInvalid choice"); 44 | main(); 45 | } 46 | } 47 | } 48 | int check(int start, int size) 49 | { 50 | int i; 51 | for (i = start; i < start+size; i++) 52 | { 53 | if (memBlock[i].data == 1) 54 | { 55 | return 1; 56 | break; 57 | } 58 | } 59 | return 0; 60 | } 61 | void sequential() 62 | { 63 | int i,start,size; 64 | printf("\nEnter the start block : "); 65 | scanf("%d",&start); 66 | printf("\nEnter the length of the file : "); 67 | scanf("%d",&size); 68 | flag = 0; 69 | flag = check(start, size); 70 | if (flag==0) 71 | { 72 | for (i = start; i < start+size; i++) 73 | { 74 | memBlock[i].data = 1; 75 | printf("%d ---> %d\n",i,memBlock[i].data); 76 | } 77 | printf("\nFile is allocated...\n"); 78 | } 79 | else 80 | { 81 | printf("\nFile cannot be allocated"); 82 | } 83 | } 84 | void linked() 85 | { 86 | int i,start,size; 87 | printf("\nEnter the start block : "); 88 | scanf("%d",&start); 89 | printf("\nEnter the length of the file : "); 90 | scanf("%d",&size); 91 | flag=0; 92 | flag = check(start, size); 93 | if (flag == 0) 94 | { 95 | for(i=start;i data = 1; 100 | new -> link = NULL; 101 | if(first == NULL) 102 | { 103 | first = new; 104 | last = new; 105 | } 106 | else 107 | { 108 | last -> link = new; 109 | last = new; 110 | } 111 | } 112 | } 113 | if(first == NULL) 114 | { 115 | printf("\nFile cannot be allocated\n"); 116 | } 117 | else 118 | { 119 | temp = first; 120 | while(temp != NULL){ 121 | 122 | for(i=start;i %d\n",i,temp->data); 125 | temp = temp->link; 126 | } 127 | } 128 | printf("\nFile is allocated...\n"); 129 | } 130 | 131 | } 132 | 133 | void indexed() 134 | { 135 | int size,i,st,flag=0,j=0,allocated=0; 136 | printf("\nEnter the length of file : "); 137 | scanf("%d",&size); 138 | for (j = 0; j < SIZE; j++) 139 | { 140 | if (memBlock[j].data == 0) 141 | { 142 | if (flag==0) 143 | { 144 | st = j; 145 | flag=1; 146 | } 147 | allocated++; 148 | memBlock[j].data = 1; 149 | memBlock[prevBlock].nextBlock = j; 150 | prevBlock = j; 151 | } 152 | if (allocated==size) 153 | { 154 | break; 155 | } 156 | } 157 | int c = st; 158 | printf("\n%d---->%d",st,1); 159 | for (i = 0; i < size-1; i++) 160 | { 161 | c = memBlock[c].nextBlock; 162 | printf("\n%d---->%d",c,1); 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /Cycle-1/index.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define SIZE 50 4 | struct node{ 5 | int data; 6 | int nextBlock; 7 | }; 8 | 9 | struct node memBlock[50]; 10 | 11 | int flag,prevBlock=-1; 12 | 13 | void indexed(){ 14 | 15 | int size, i, st, flag=0, j=0, allocated=0; 16 | printf("\nEnter the length of file : "); 17 | scanf("%d",&size); 18 | for ( j=0; j 2 | #include 3 | struct node{ 4 | int data; 5 | struct node *link; 6 | }*new, *temp, *last, *first; 7 | 8 | struct node memBlock[50]; 9 | 10 | int flag; 11 | int check(int start, int size){ 12 | int i; 13 | for (i = start; i < start+size; i++){ 14 | if (memBlock[i].data == 1){ 15 | return 1; 16 | break; 17 | } 18 | } 19 | return 0; 20 | } 21 | void linked(){ 22 | 23 | int i, start, size; 24 | printf("\nStart block : "); 25 | scanf("%d",&start); 26 | printf("\nLength of the file : "); 27 | scanf("%d",&size); 28 | 29 | flag = 0; 30 | flag = check(start, size); 31 | 32 | if (flag == 0){ 33 | for (int i=start; idata = 1; 37 | new->link = NULL; 38 | 39 | if (first == NULL){ 40 | first = new; 41 | last = new; 42 | } 43 | else{ 44 | last->link = new; 45 | last = new; 46 | } 47 | } 48 | } 49 | 50 | if (first == NULL){ 51 | printf("File NOT allocated."); 52 | 53 | } 54 | else{ 55 | temp = first; 56 | while(temp!=NULL){ 57 | for(i=start; ilink; 61 | } 62 | printf("\nFile allocated."); 63 | } 64 | } 65 | 66 | } 67 | 68 | int main(){ 69 | 70 | int i,d; 71 | 72 | do{ 73 | 74 | printf("\n1.linked \n2. Exit\n"); 75 | scanf("%d", &d); 76 | switch(d){ 77 | case 1 : linked(); main(); break; 78 | 79 | default : printf("Try again"); 80 | } 81 | }while (d != 2); 82 | 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /Cycle-1/priority-tv.c: -------------------------------------------------------------------------------- 1 | /*ALGORITHM: 2 | Step1:Get the number of process. 3 | Step2:Get the id and service time for each process. 4 | Step3:Initially the waiting time of first short process as 0 and total time of first 5 | short is process the service time of that process. 6 | Step4:Calculate the total time and waiting time of remaining process. 7 | Step5:Waiting time of one process is the total time of the previous process. 8 | Step6:Total time of process is calculated by adding the waiting time and service 9 | time of each process. 10 | Step7:Total waiting time calculated by adding the waiting time of each process. 11 | Step8:Total turn around time calculated by adding all total time of each process. 12 | Step9:calculate average waiting time by dividing the total waiting time by total 13 | number of process. 14 | Step10:Calculate average turn around time by dividing the total waiting time by 15 | total number of process. 16 | Step11:Display the result. 17 | */ 18 | 19 | #include 20 | struct process 21 | { int pid,priority,done; 22 | float at,bt,ct,tat,wt,st; 23 | } p[100],temp; 24 | 25 | 26 | void sjf(struct process a[100],int n) 27 | { 28 | int i,j,flag; 29 | float avgtat=0,avgwt=0,time=0,z=0; 30 | char s[]=" "; 31 | 32 | for (i=0;ia[j+1].priority) 35 | { 36 | temp=a[j]; 37 | a[j]=a[j + 1]; 38 | a[j+1]=temp; 39 | } 40 | 41 | printf("\nGantt Chart\n"); 42 | for(i=0;i NULL\n",time-z,time); 52 | z=0; 53 | } 54 | a[j].st=time; 55 | time+=a[j].bt; 56 | a[j].ct=time; 57 | a[j].tat=a[j].ct-a[j].at; 58 | a[j].wt=a[j].tat-a[j].bt; 59 | avgtat+=a[j].tat; 60 | avgwt+=a[j].wt; 61 | a[j].done=1; 62 | flag=1; 63 | i++; 64 | printf("%f - %f -> P%d\n",a[j].st,a[j].ct,a[j].pid); 65 | } 66 | } 67 | 68 | if(flag==0) 69 | { 70 | z++; 71 | time++; 72 | } 73 | 74 | } 75 | 76 | avgtat/=n; 77 | avgwt/=n; 78 | 79 | for (i=0;ia[j+1].pid) 82 | { 83 | temp=a[j]; 84 | a[j]=a[j + 1]; 85 | a[j+1]=temp; 86 | } 87 | 88 | printf("\nProcess Id AT%s BT Priority CT%s TAT%s WT\n",s,s,s); 89 | 90 | for(i=0;i 25 | #include 26 | #include 27 | typedef struct{ 28 | int pno; 29 | int pri; 30 | int btime; 31 | int wtime; 32 | } sp; 33 | 34 | int main(){ 35 | int i,j,n; 36 | int tbm = 0, totwtime = 0,totttime = 0; 37 | sp *p,t; 38 | printf("\n Priority Scheduling.\n"); 39 | printf("\n Enter the Number of Process : "); 40 | scanf("%d", &n); 41 | p = (sp*) malloc (sizeof(sp)); 42 | printf("\nEnter the Burst time and priority : \n"); 43 | for ( i = 0; i < n; i++){ 44 | printf("Process %d : ", i+1); 45 | scanf("%d%d", &p[i].btime,&p[i].pri); 46 | p[i].pno = i+1; 47 | p[i].wtime=0; 48 | } 49 | 50 | for(i=0;ip[j].pri){ 53 | t = p[i]; 54 | p[i] = p[j]; 55 | p[j] = t; 56 | } 57 | } 58 | printf("\nProcess\tBurst Time\tWaiting Time\tTurnaround Time\n"); 59 | for ( i = 0; i < n; i++){ 60 | totwtime += p[i].wtime=tbm; 61 | tbm += p[i].btime; 62 | printf("\n%d\t\t%d",p[i].pno,p[i].btime); 63 | printf("\t\t%d\t\t%d",p[i].wtime,p[i].wtime+p[i].btime); 64 | } 65 | totttime = tbm + totwtime; 66 | printf("\n Total Waiting time:%d",totwtime); 67 | printf("\n Average Waiting time:%f",(float)totwtime/n); 68 | printf("\n Total Turnaround time:%d",totttime); 69 | printf("\n Avg Turnaround time:%f",(float)totttime/n); 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /Cycle-1/roundRobin.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Ex.No:5.b 4 | CPU SCHEDULING ALGORITHMS 5 | ROUND ROBIN SCHEDULING 6 | AIM: 7 | To write a C program for implementation of Round Robin scheduling algorithms. 8 | ALGORITHM: 9 | Step 1: Inside the structure declare the variables. 10 | Step 2: Declare the variable i,j as integer, totwtime and totttime is equal to zero. 11 | Step 3: Get the value of „n‟ assign p and allocate the memory. 12 | Step 4: Inside the for loop get the value of burst time and priority and read the time quantum. 13 | Step 5: Assign wtime as zero. 14 | Step 6: Check p[i].pri is greater than p[j].pri . 15 | Step 7: Calculate the total of burst time and waiting time and assign as turnaround time. 16 | Step 8: Stop the program. 17 | 18 | */ 19 | 20 | #include 21 | int main(){ 22 | int count, j, n, time, remain, flag = 0, time_quantum; 23 | int wait_time = 0,turnaround_time = 0, at[10], bt[10], rt[10]; 24 | printf("Enter Total Process : \t "); 25 | scanf("%d",&n); 26 | remain = n; 27 | for( count = 0; count < n; count++){ 28 | printf("Enter Arrival Time and Burst Time for Process Process Number %d :", count+1); 29 | scanf("%d",&at[count]); 30 | scanf("%d",&bt[count]); 31 | rt[count] = bt[count]; 32 | } 33 | printf("Enter Time Quantum : \t"); 34 | scanf("%d",&time_quantum); 35 | printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n"); 36 | for( time = 0,count=0; remain != 0;){ 37 | if(rt[count] <= time_quantum && rt[count] > 0 ){ 38 | time += rt[count]; 39 | rt[count] = 0; 40 | flag = 1; 41 | } 42 | else if( rt[count] > 0){ 43 | rt[count] -= time_quantum; 44 | time += time_quantum; 45 | } 46 | if( rt[count] == 0 && flag == 1){ 47 | remain--; 48 | printf("P[%d]\t|\t%d\t\t\t|\t\t%d\n",count+1, time-at[count], time-at[count]-bt[count]); 49 | wait_time += time - at[count] - bt[count]; 50 | turnaround_time += time - at[count]; 51 | flag=0; 52 | } 53 | if(count == n-1) 54 | count=0; 55 | 56 | else if( at[count+1] <= time) 57 | count++; 58 | else 59 | count=0; 60 | } 61 | printf("\nAverage Waiting Time= %f\n", wait_time * 1.0 / n); 62 | printf("\nAvg Turnaround Time =%f\n", turnaround_time * 1.0 / n); 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /Cycle-1/rr-tv.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct process 3 | { int pid,done,vis; 4 | float at,bt,ct,tat,wt,st,rt; 5 | } p[100],temp; 6 | 7 | int f=-1,r=-1,q[100],rq[100],m=0; 8 | 9 | void add(int a) 10 | {if(f==-1) 11 | f++; 12 | r++; 13 | q[r]=a; 14 | } 15 | 16 | int fetch() 17 | {if(f==r) 18 | {int k=f; 19 | f=-1; 20 | r=-1; 21 | return q[k]; 22 | } 23 | return q[f++]; 24 | } 25 | 26 | 27 | void rr(struct process a[100],int n,int tq) 28 | { 29 | int i,j,k,flag,pc=0; 30 | float avgtat=0,avgwt=0,time=0,z=0,tot=0,time0; 31 | char s[]=" "; 32 | 33 | for (i=0;ia[j+1].at) 36 | { 37 | temp=a[j]; 38 | a[j]=a[j + 1]; 39 | a[j+1]=temp; 40 | } 41 | 42 | 43 | printf("\nGantt Chart\n"); 44 | while(pc NULL\n",time-z,time); 59 | z=0; 60 | } 61 | 62 | if(a[k].rt<=tq && a[k].done==0) 63 | {time0=time; 64 | time+=a[k].rt; 65 | a[k].rt=0; 66 | pc++; 67 | a[k].done=1; 68 | a[k].ct=time; 69 | a[k].tat=a[k].ct-a[k].at; 70 | a[k].wt=a[k].tat-a[k].bt; 71 | avgtat+=a[k].tat; 72 | avgwt+=a[k].wt; 73 | } 74 | 75 | else if(a[k].rt>tq) 76 | {time0=time; 77 | time+=tq; 78 | a[k].rt-=tq; 79 | } 80 | 81 | printf("%f - %f -> P%d\n",time0,time,a[k].pid); 82 | 83 | for(j=i;j0) 91 | {add(k); 92 | rq[m++]=a[k].pid; 93 | } 94 | flag=1; 95 | } 96 | 97 | if(flag==0) 98 | {z++; 99 | time++; 100 | } 101 | 102 | } 103 | } 104 | 105 | printf("\nReady Queue\n"); 106 | for(i=0;ia[j+1].pid) 115 | { 116 | temp=a[j]; 117 | a[j]=a[j + 1]; 118 | a[j+1]=temp; 119 | } 120 | 121 | printf("\nProcess Id AT%s BT%s CT%s TAT%s WT\n",s,s,s,s); 122 | 123 | for(i=0;i 2 | #include 3 | 4 | int flag =-1; 5 | 6 | struct node{ 7 | int data; 8 | }; 9 | 10 | 11 | struct node memBlock[50]; 12 | 13 | int check(int start, int size){ 14 | int i; 15 | for (i = start; i < start+size; i++){ 16 | if (memBlock[i].data == 1){ 17 | return 1; 18 | break; 19 | } 20 | } 21 | return 0; 22 | } 23 | void sequential() 24 | { 25 | int i,start,size; 26 | printf("\nStart block : "); 27 | scanf("%d",&start); 28 | printf("\nLength of the file : "); 29 | scanf("%d",&size); 30 | 31 | flag = 0; 32 | flag = check(start, size); 33 | 34 | if (flag==0){ 35 | for(i = start; i < start+size; i++){ 36 | 37 | memBlock[i].data = 1; 38 | printf("%d ------- Allocated\n",i); 39 | } 40 | //printf("\nFile is allocated...\n"); 41 | } 42 | 43 | else{ 44 | printf("\nFile cannot be allocated"); 45 | } 46 | } 47 | 48 | int main(){ 49 | int i,d; 50 | 51 | do{ 52 | 53 | printf("\n1.Sequential \n2. Exit\n"); 54 | scanf("%d", &d); 55 | switch(d){ 56 | case 1 : sequential(); break; 57 | 58 | default : printf("Try again"); 59 | } 60 | }while (d != 2); 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /Cycle-1/sjf-tv.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct process 3 | { int pid,done; 4 | float at,bt,ct,tat,wt,st; 5 | } p[100],temp; 6 | 7 | 8 | void sjf(struct process a[100],int n) 9 | { 10 | int i,j,flag; 11 | float avgtat=0,avgwt=0,time=0,z=0; 12 | char s[]=" "; 13 | 14 | for (i=0;ia[j+1].bt) 17 | { 18 | temp=a[j]; 19 | a[j]=a[j + 1]; 20 | a[j+1]=temp; 21 | } 22 | 23 | printf("\nGantt Chart\n"); 24 | for(i=0;i NULL\n",time-z,time); 34 | z=0; 35 | } 36 | a[j].st=time; 37 | time+=a[j].bt; 38 | a[j].ct=time; 39 | a[j].tat=a[j].ct-a[j].at; 40 | a[j].wt=a[j].tat-a[j].bt; 41 | avgtat+=a[j].tat; 42 | avgwt+=a[j].wt; 43 | a[j].done=1; 44 | flag=1; 45 | i++; 46 | printf("%f - %f -> P%d\n",a[j].st,a[j].ct,a[j].pid); 47 | } 48 | } 49 | 50 | if(flag==0) 51 | { 52 | z++; 53 | time++; 54 | } 55 | 56 | } 57 | 58 | avgtat/=n; 59 | avgwt/=n; 60 | 61 | for (i=0;ia[j+1].pid) 64 | { 65 | temp=a[j]; 66 | a[j]=a[j + 1]; 67 | a[j+1]=temp; 68 | } 69 | 70 | printf("\nProcess Id AT%s BT%s CT%s TAT%s WT\n",s,s,s,s); 71 | 72 | for(i=0;i 23 | 24 | int main() { 25 | int bt[20], p[20], wt[20], tat[20], i, j, n, total = 0, pos, temp; 26 | float avg_wt, avg_tat; 27 | printf("Enter number of process:"); 28 | scanf("%d",&n); 29 | 30 | printf("\n Enter Burst Time:\n"); 31 | for( i = 0; i < n; i++){ 32 | printf("p%d:",i+1); 33 | scanf("%d",&bt[i]); 34 | p[i]=i+1; 35 | } 36 | 37 | for( i = 0; i < n; i++){ 38 | pos = i; 39 | for( j = i+1; j < n; j++){ 40 | if( bt[j] < bt[pos]) 41 | pos = j; 42 | } 43 | 44 | temp = bt[i]; 45 | bt[i] = bt[pos]; 46 | bt[pos] = temp; 47 | 48 | temp = p[i]; 49 | p[i] = p[pos]; 50 | p[pos] = temp; 51 | } 52 | 53 | wt[0] = 0; 54 | 55 | for( i = 1; i < n; i++){ 56 | wt[i] = 0; 57 | for( j = 0; j < i; j++) 58 | wt[i] += bt[j]; 59 | 60 | total += wt[i]; 61 | } 62 | 63 | avg_wt = (float)total / n; 64 | 65 | total = 0; 66 | 67 | printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time"); 68 | for( i = 0; i < n; i++){ 69 | tat[i] = bt[i] + wt[i]; 70 | total += tat[i]; 71 | printf("\n p%d\t\t\t %d\t\t\t %d\t\t\t\t%d",p[i],bt[i],wt[i],tat[i]); 72 | } 73 | 74 | avg_tat = (float)total / n; 75 | printf("\n\nAverage Waiting Time=%f",avg_wt); printf("\nAverage TurnaroundTime=%f\n",avg_tat); 76 | } 77 | -------------------------------------------------------------------------------- /Cycle-2/Basic arthimetric.kit: -------------------------------------------------------------------------------- 1 | ##Implementation of Basic Arithmetric operation in 8086 Microprocessor Trainer Kit 2 | 3 | ##Starting address from 1000H 4 | 5 | MOV CL,00H 6 | MOV AL,[1100H] 7 | MOV BL,[1101H] 8 | ADD AL,BL 9 | JNC 1015 10 | INC CL 11 | MOV [1103H],CL 12 | MOV CL,00H 13 | 14 | MOV AL,[1100H] 15 | SUB AL,BL 16 | JNC 1026 17 | INC CL 18 | MOV [1106H],CL 19 | MOV [1104H],AL 20 | 21 | MOV AL,[1100H] 22 | MUL BL 23 | MOV [1107H],AX 24 | 25 | MOV AL,[1100H] 26 | MOV BL,[1101H] 27 | DIV BL 28 | MOV [1109H],AL 29 | MOV [110AH],AH 30 | HLT 31 | 32 | ## 33 | input 34 | 1100H : first value 35 | 1101H : second value 36 | -------------------------------------------------------------------------------- /Cycle-2/SearchingLinear.kit: -------------------------------------------------------------------------------- 1 | ##Implementation of Linear Searching in 8086 Microprocessor Trainer Kit 2 | 3 | ##Starting address from 2000H 4 | 5 | MOV SI,3001H 6 | MOV CL,[3000H] 7 | MOV BL,[4000H] 8 | CMP AL,BL 9 | JZ 2018H 10 | INC SI 11 | LOOP 200C 12 | JMP 2021 13 | MOV [4005H],01H 14 | MOV [4006H],AL 15 | HLT 16 | 17 | ## 18 | Input 19 | 3000H :05H //Counter 20 | 3001H :06H //starting value of array 21 | "" 22 | "" 23 | "" 24 | "" 25 | 4000H :06H // search key/item 26 | 4005H :00H // flag kind thing 27 | 28 | -------------------------------------------------------------------------------- /Cycle-2/sorting.kit: -------------------------------------------------------------------------------- 1 | ##Implementation of Ascending order sorting in 8086 Microprocessor Trainer Kit 2 | 3 | ##Starting address from 1000H 4 | 5 | MOV SI,1100H 6 | MOV CL,[SI] 7 | DEC CL 8 | MOV SI,1100H 9 | MOV CH,[SI] 10 | DEC CH 11 | INC SI 12 | MOV AL,[SI] 13 | INC SI 14 | CMP AL,[SI] 15 | JC 101D 16 | XCHG AL,[SI] 17 | XCHG AL,[SI-1] 18 | DEC CH 19 | JNZ 1011 20 | DEC SL 21 | JNZ 1008 22 | HLT 23 | 24 | ## 25 | input 26 | 1100H :05H //counter 27 | 1101H : //starting value of array 28 | "" 29 | "" 30 | .. 31 | 32 | . 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Cycle-3/Addition16bit.asm: -------------------------------------------------------------------------------- 1 | ASSUME CS: CODE, DS:DATA 2 | DATA SEGMENT 3 | OPR1 DW 1234H 4 | OPR2 DW 5678H 5 | RESULT DW ? 6 | DATA ENDS 7 | 8 | CODE SEGMENT 9 | 10 | START: MOV AX, DATA 11 | MOV DS,AX 12 | MOV AX,OPR1 13 | MOV BX,OPR2 14 | ADD AX,BX 15 | MOV RESULT,AX 16 | MOV AH,4CH 17 | INT 21H 18 | CODE ENDS 19 | END START 20 | -------------------------------------------------------------------------------- /Cycle-3/palindrome.asm: -------------------------------------------------------------------------------- 1 | ASSUME CS:CODE,DS:DATA 2 | DATA SEGMENT 3 | mystring db 'Paul thomas$' 4 | string1 db 'palindrome$' 5 | string2 db 'not palindrome$' 6 | DATA ENDS 7 | CODE SEGMENT 8 | START: 9 | MOV AX,DATA 10 | MOV DS,AX 11 | LEA DI,mystring 12 | MOV SI,DI 13 | BACK:MOV AL,[DI] 14 | CMP AL,'$' 15 | JZ SCAN 16 | INC DI 17 | JMP BACK 18 | SCAN: DEC DI 19 | CMP SI,DI 20 | JNC OUT1 21 | MOV AL,[SI] 22 | CMP AL,[DI] 23 | JNZ OUT2 24 | INC SI 25 | JMP SCAN 26 | OUT1:LEA DX,string1 27 | JMP L2 28 | OUT2:LEA DX, string2 29 | L2: MOV AH,09H 30 | INT 21H 31 | MOV AH,4CH 32 | INT 21H 33 | CODE ENDS 34 | END START 35 | -------------------------------------------------------------------------------- /Cycle-4/Absolute Loader/absoluteLoader.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | 7 | void main() { 8 | FILE * fp; 9 | int i, addr1, l, j, staddr1; 10 | char name[10], line[50], name1[10], addr[10], rec[10], ch, staddr[10]; 11 | printf("enter program name:"); 12 | scanf("%s", name); 13 | fp = fopen("input.txt", "r"); 14 | fscanf(fp, "%s", line); 15 | for (i = 2, j = 0; i < 8, j < 6; i++, j++) 16 | name1[j] = line[i]; 17 | name1[j] = '\0'; 18 | printf("name from obj.%s\n", name1); 19 | if (strcmp(name, name1) == 0) { 20 | do { 21 | fscanf(fp, "%s", line); 22 | if (line[0] == 'T') { 23 | for (i = 2, j = 0; i < 8, j < 6; i++, j++) 24 | staddr[j] = line[i]; 25 | staddr[j] = '\0'; 26 | staddr1 = atoi(staddr); 27 | i = 12; 28 | while (line[i] != '$') { 29 | if (line[i] != '^') { 30 | printf("00%d \t %c%c\n", 31 | staddr1, line[i], line[i + 1]); 32 | staddr1++; 33 | i = i + 2; 34 | } else i++; 35 | } 36 | } else if (line[0] = 'E') { 37 | fclose(fp); 38 | exit(0); 39 | } 40 | } while (!feof(fp)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Cycle-4/Absolute Loader/input.txt: -------------------------------------------------------------------------------- 1 | H^SAMPLE^001000^0035 2 | T^001000^0C^001003^071009$ 3 | T^002000^03^111111$ 4 | E^001000 5 | -------------------------------------------------------------------------------- /Cycle-4/Macro Preprocessor/2023-02-02 (9).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PaulThomas20002/S5-SYSTEM-SOFTWARE-AND-MICROPROCESSORS-LAB/bc3f5ecf3cb1b525c9bb5f5921590976c59acd3c/Cycle-4/Macro Preprocessor/2023-02-02 (9).png -------------------------------------------------------------------------------- /Cycle-4/Macro Preprocessor/macrropp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void main() 5 | { 6 | FILE *f1,*f2,*f3,*f4,*f5; 7 | int len,i,pos=1; 8 | char 9 | arg[20],mne[20],opnd[20],la[20],name[20], 10 | mne1[20],opnd1[20],pos1[10],pos2[10]; 11 | f1=fopen("input.txt","r"); 12 | f2=fopen("namtab.txt","w+"); 13 | f3=fopen("deftab.txt","w+"); 14 | f4=fopen("argtab.txt","w+"); 15 | f5=fopen("op.txt","w+"); 16 | fscanf(f1,"%s%s%s",la,mne,opnd); 17 | while(strcmp(mne,"END")!=0) 18 | { 19 | if(strcmp(mne,"MACRO")==0) 20 | { 21 | fprintf(f2,"%s\n",la); 22 | fseek(f2,SEEK_SET,0); 23 | fprintf(f3,"%s\t%s\n",la,opnd); 24 | fscanf(f1,"%s%s%s",la,mne,opnd); 25 | while(strcmp(mne,"MEND")!=0) 26 | { 27 | if(opnd[0]=='&') 28 | { 29 | (pos,pos1,5); 30 | strcpy(pos2,"?"); 31 | strcpy(opnd,strcat(pos2,pos1)); 32 | pos=pos+1; 33 | } 34 | fprintf(f3,"%s\t%s\n",mne,opnd); 35 | fscanf(f1,"%s%s%s",la,mne,opnd); 36 | } 37 | fprintf(f3,"%s",mne); 38 | } 39 | else 40 | { 41 | fscanf(f2,"%s",name); 42 | if(strcmp(mne,name)==0) 43 | { 44 | len=strlen(opnd); 45 | for(i=0;i 2 | #include 3 | #include 4 | void main() 5 | { 6 | FILE *f1,*f2,*f3,*f4,*f5; 7 | int lc,sa,i=0,j=0,m[10],pgmlen,len,k,len1,l=0; 8 | char name[10],opnd[10],la[10],mne[10],s1[10],mne1[10],opnd1[10]; 9 | char lcs[10],ms[10]; 10 | char sym[10],symaddr[10],obj1[10],obj2[10],s2[10],q[10],s3[10]; 11 | 12 | f1=fopen("input.txt","r"); 13 | f2=fopen("optab.txt","r"); 14 | f3=fopen("symtab.txt","w+"); 15 | f4=fopen("symtab1.txt","w+"); 16 | f5=fopen("output.txt","w+"); 17 | fscanf(f1,"%s%s%s",la,mne,opnd); 18 | if(strcmp(mne,"START")==0) 19 | { 20 | sa=atoi(opnd); 21 | strcpy(name,la); 22 | lc=sa; 23 | } 24 | strcpy(s1,"*"); 25 | fscanf(f1,"%s%s%s",la,mne,opnd); 26 | while(strcmp(mne,"END")!=0) 27 | { 28 | if(strcmp(la,"-")==0) 29 | { 30 | fscanf(f2,"%s%s",mne1,opnd1); 31 | while(!feof(f2)) 32 | { 33 | if(strcmp(mne1,mne)==0) 34 | { 35 | m[i]=lc+1; 36 | fprintf(f3,"%s\t%s\n",opnd,s1); 37 | fprintf(f5,"%s\t0000\n",opnd1); 38 | lc=lc+3; 39 | i=i+1; 40 | break; 41 | } 42 | else 43 | fscanf(f2,"%s%s",mne1,opnd1); 44 | } 45 | 46 | } 47 | 48 | else 49 | { 50 | fseek(f3,SEEK_SET,0); 51 | fscanf(f3,"%s%s",sym,symaddr); 52 | while(!feof(f3)) 53 | { 54 | if(strcmp(sym,la)==0) 55 | { 56 | sprintf(lcs,"%d",lc); 57 | fprintf(f4,"%s\t%s\n",la,lcs); 58 | sprintf(ms,"%d",m[j]); 59 | j=j+1; 60 | fprintf(f5,"%s\t%s\n",ms,lcs); 61 | i=i+1; 62 | break; 63 | } 64 | else 65 | fscanf(f3,"%s%s",sym,symaddr); 66 | } 67 | if(strcmp(mne,"RESW")==0) 68 | lc=lc+3*atoi(opnd); 69 | else if(strcmp(mne,"BYTE")==0) 70 | { 71 | strcpy(s2,"-"); 72 | len=strlen(opnd); 73 | lc=lc+len-2; 74 | for(k=2;k 2 | #include 3 | #include 4 | #include 5 | void main() { 6 | char opcode[10], operand[10], label[10], code[10], mnemonic[10]; 7 | int locctr, start, length; 8 | 9 | FILE *fp1, *fp2, *fp3, *fp4; 10 | 11 | fp1 = fopen("input.txt", "r"); 12 | fp2 = fopen("optab.txt", "r"); 13 | fp3 = fopen("symtbl.txt", "w"); 14 | fp4 = fopen("out.txt", "w"); 15 | 16 | fscanf(fp1, "%s\t%s\t%s", label, opcode, operand); 17 | 18 | if (strcmp(opcode, "START") == 0) { 19 | start = atoi(operand); 20 | locctr = start; 21 | fprintf(fp4, "\t%s\t%s\t%s\n", label, opcode, operand); 22 | fscanf(fp1, "%s\t%s\t%s", label, opcode, operand); 23 | } else { 24 | locctr = 0; 25 | } 26 | 27 | while (strcmp(opcode, "END") != 0) { 28 | fprintf(fp4, "%d\t", locctr); 29 | 30 | if (strcmp(label, "**") != 0) { 31 | fprintf(fp3, "%s\t%d\n", label, locctr); 32 | } 33 | 34 | fscanf(fp2, "%s\t%s", code, mnemonic); 35 | 36 | while (strcmp(code, "END") != 0) { 37 | if (strcmp(opcode, code) == 0) { 38 | locctr += 3; 39 | break; 40 | } 41 | fscanf(fp2, "%s\t%s", code, mnemonic); 42 | } 43 | 44 | if (strcmp(opcode, "WORD") == 0) { 45 | locctr += 3; 46 | } else if (strcmp(opcode, "RESW") == 0) { 47 | locctr += (3 * (atoi(operand))); 48 | } else if (strcmp(opcode, "RESB") == 0) { 49 | locctr += (atoi(operand)); 50 | } else if (strcmp(opcode, "BYTE") == 0) { 51 | int i = 2; 52 | while (isalnum((operand[i]))) { 53 | locctr++; 54 | i++; 55 | printf("%d",isalnum((operand[i]))); 56 | } 57 | } 58 | 59 | fprintf(fp4, "%s\t%s\t%s\t\n", label, opcode, operand); 60 | fscanf(fp1, "%s\t%s\t%s", label, opcode, operand); 61 | } 62 | 63 | fprintf(fp4, "%d\t%s\t%s\t%s\n", locctr, label, opcode, operand); 64 | 65 | length = locctr - start; 66 | 67 | printf("The length of the code : %d\n", length); 68 | 69 | fclose(fp1); 70 | fclose(fp2); 71 | fclose(fp3); 72 | fclose(fp4); 73 | } 74 | -------------------------------------------------------------------------------- /Cycle-4/input.txt: -------------------------------------------------------------------------------- 1 | ** START 2000 2 | ** LDA FIVE 3 | ** STA ALPHA 4 | ** LDCH CHARZ 5 | ** STCH C1 6 | ALPHA RESW 2 7 | FIVE WORD 5 8 | CHARZ BYTE C'Z' 9 | C1 RESB 1 10 | ** END ** -------------------------------------------------------------------------------- /Cycle-4/intermediate.txt: -------------------------------------------------------------------------------- 1 | ** START 2000 2 | 2000 ** LDA FIVE 3 | 2003 ** STA ALPHA 4 | 2006 ** LDCH CHARZ 5 | 2009 ** STCH C1 6 | 2012 ALPHA RESW 2 7 | 2018 FIVE WORD 5 8 | 2021 CHARZ BYTE C'Z' 9 | 2022 C1 RESB 1 10 | 2023 ** END ** 11 | -------------------------------------------------------------------------------- /Cycle-4/length.txt: -------------------------------------------------------------------------------- 1 | 23 -------------------------------------------------------------------------------- /Cycle-4/objcode.txt: -------------------------------------------------------------------------------- 1 | H^**^002000^002023 2 | T^002000^22^332018^442012^532021^572022^000005^5A 3 | E^002000 -------------------------------------------------------------------------------- /Cycle-4/optab.txt: -------------------------------------------------------------------------------- 1 | LDA 03 2 | STA 0f 3 | LDCH 53 4 | STCH 57 5 | END * -------------------------------------------------------------------------------- /Cycle-4/output.txt: -------------------------------------------------------------------------------- 1 | ** START 2000 2 | 2000 ** LDA FIVE 332018 3 | 2003 ** STA ALPHA 442012 4 | 2006 ** LDCH CHARZ 532021 5 | 2009 ** STCH C1 572022 6 | 2012 ALPHA RESW 2 7 | 2018 FIVE WORD 5 000005 8 | 2021 CHARZ BYTE C'Z' 5A 9 | 2022 C1 RESB 1 10 | 2023 ** END ** 11 | -------------------------------------------------------------------------------- /Cycle-4/pass1.c: -------------------------------------------------------------------------------- 1 | /* 2 | !important 3 | Initially create 2 files input.txt & optab.txt in same directory, 4 | add the input 5 | After compiling pass1.c & executing a.out , 6 | length.txt, intermediate.txt & symtab.txt 7 | will be created and output will be writed to it and displayed on terminal 8 | */ 9 | #include 10 | #include 11 | #include 12 | 13 | void passOne(char label[10], char opcode[10], char operand[10], char code[10], char mnemonic[3]); 14 | void display(); 15 | 16 | int main() 17 | { 18 | // for reading from input 19 | char label[10], opcode[10], operand[10]; 20 | // for reading from optab 21 | char code[10], mnemonic[3]; 22 | // call the function 23 | passOne(label, opcode, operand, code, mnemonic); 24 | 25 | return 0; 26 | } 27 | 28 | void passOne(char label[10], char opcode[10], char operand[10], char code[10], char mnemonic[3]) 29 | { 30 | int locctr, start, length; 31 | 32 | FILE *fp1, *fp2, *fp3, *fp4, *fp5; // file pointers 33 | 34 | // read mode 35 | fp1 = fopen("input.txt", "r"); 36 | fp2 = fopen("optab.txt", "r"); 37 | // write mode 38 | fp3 = fopen("symtab.txt", "w"); 39 | fp4 = fopen("intermediate.txt", "w"); 40 | fp5 = fopen("length.txt", "w"); 41 | 42 | fscanf(fp1, "%s\t%s\t%s", label, opcode, operand); // read first line 43 | 44 | if (strcmp(opcode, "START") == 0) { 45 | // atoi() requires stdlib.h header file , it converts ASCII to integer 46 | start = atoi(operand); // convert operand value from string to integer and assign to start 47 | locctr = start; 48 | fprintf(fp4, "\t%s\t%s\t%s\n", label, opcode, operand); // write to output file (additional tab space as start will not have any locctr) 49 | fscanf(fp1, "%s\t%s\t%s", label, opcode, operand); // read next line 50 | } 51 | else { 52 | locctr = 0; 53 | } 54 | 55 | // iterate till end 56 | while (strcmp(opcode, "END") != 0) { 57 | 58 | // 1. transfer address and read line to output file 59 | fprintf(fp4, "%d\t%s\t%s\t%s\n", locctr, label, opcode, operand); 60 | 61 | // 2. make symtab file with values not starting with ** 62 | if (strcmp(label, "**") != 0) { 63 | fprintf(fp3, "%s\t%d\n", label, locctr); 64 | } 65 | 66 | // 3. read from optab (code and mnemonic value) 67 | fscanf(fp2, "%s\t%s", code, mnemonic); 68 | 69 | // 4. traverse till the end of optab file 70 | while (strcmp(code, "END") != 0) { 71 | if (strcmp(opcode, code) == 0) { // if opcode in input matches the one in optab, increment locctr by 3 72 | locctr += 3; 73 | break; 74 | } 75 | // read next line 76 | fscanf(fp2, "%s\t%s", code, mnemonic); 77 | } 78 | 79 | // 5. Searching opcode for WORD, RESW, BYTE, RESB keywords and updating locctr 80 | 81 | // WORD -> add 3 to locctr 82 | if (strcmp(opcode, "WORD") == 0) { 83 | locctr += 3; 84 | } 85 | // RESW -> add 3*operand to locctr 86 | else if (strcmp(opcode, "RESW") == 0) { 87 | locctr += (3 * (atoi(operand))); // convert operand to integer and multiply with 3 88 | } 89 | // BYTE -> add 1 to locctr 90 | else if (strcmp(opcode, "BYTE") == 0) { 91 | ++locctr; 92 | } 93 | // RESB -> add operand to locctr 94 | else if (strcmp(opcode, "RESB") == 0) { 95 | locctr += atoi(operand); 96 | } 97 | 98 | // read next line 99 | fscanf(fp1, "%s\t%s\t%s", label, opcode, operand); 100 | } 101 | // 6. transfer last line to file 102 | fprintf(fp4, "%d\t%s\t%s\t%s\n", locctr, label, opcode, operand); 103 | 104 | // 7. Close all files 105 | fclose(fp4); 106 | fclose(fp3); 107 | fclose(fp2); 108 | fclose(fp1); 109 | 110 | // 8. display outputs 111 | display(); 112 | 113 | // 9. calculate length of program 114 | length = locctr - start; 115 | fprintf(fp5, "%d", length); 116 | fclose(fp5); 117 | printf("\nThe length of the code : %d\n", length); 118 | } 119 | 120 | void display() { 121 | 122 | char str; 123 | FILE *fp1, *fp2, *fp3; 124 | 125 | // 1. Input Table 126 | printf("\nThe contents of Input Table :\n\n"); 127 | fp1 = fopen("input.txt", "r"); 128 | str = fgetc(fp1); 129 | while (str != EOF) { 130 | printf("%c", str); 131 | str = fgetc(fp1); 132 | } 133 | fclose(fp1); 134 | 135 | //2. Output Table 136 | printf("\n\nThe contents of Output Table :\n\n"); 137 | fp2 = fopen("intermediate.txt", "r"); 138 | str = fgetc(fp2); 139 | while (str != EOF) { 140 | printf("%c", str); 141 | str = fgetc(fp2); 142 | } 143 | fclose(fp2); 144 | 145 | // 3. Symtable 146 | printf("\n\nThe contents of Symbol Table :\n\n"); 147 | fp3 = fopen("symtab.txt", "r"); 148 | str = fgetc(fp3); 149 | while (str != EOF) { 150 | printf("%c", str); 151 | str = fgetc(fp3); 152 | } 153 | fclose(fp3); 154 | } 155 | 156 | /* 157 | 158 | input.txt 159 | --------- 160 | 161 | ** START 2000 162 | ** LDA FIVE 163 | ** STA ALPHA 164 | ** LDCH CHARZ 165 | ** STCH C1 166 | ALPHA RESW 2 167 | FIVE WORD 5 168 | CHARZ BYTE C'Z' 169 | C1 RESB 1 170 | ** END ** 171 | 172 | 173 | optab.txt 174 | --------- 175 | 176 | LDA 03 177 | STA 0f 178 | LDCH 53 179 | STCH 57 180 | END * 181 | 182 | ----------------------------- 183 | 184 | symtab.txt 185 | ---------- 186 | 187 | ALPHA 2012 188 | FIVE 2018 189 | CHARZ 2021 190 | C1 2022 191 | 192 | intermediate.txt 193 | ---------------- 194 | 195 | ** START 2000 196 | 2000 ** LDA FIVE 197 | 2003 ** STA ALPHA 198 | 2006 ** LDCH CHARZ 199 | 2009 ** STCH C1 200 | 2012 ALPHA RESW 2 201 | 2018 FIVE WORD 5 202 | 2021 CHARZ BYTE C'Z' 203 | 2022 C1 RESB 1 204 | 2023 ** END ** 205 | 206 | length.txt 207 | ---------- 208 | 23 209 | 210 | */ -------------------------------------------------------------------------------- /Cycle-4/pass2.c: -------------------------------------------------------------------------------- 1 | /* 2 | !important 3 | Must Compile and Execute 'pass1.c' before executing this 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | void display(); 11 | 12 | // itoa manual implementation as its not ANSI Standard 13 | //start of itoa block 14 | // Function to swap two numbers 15 | void swap(char *x, char *y) { 16 | char t = *x; *x = *y; *y = t; 17 | } 18 | 19 | // Function to reverse `buffer[i…j]` 20 | char* reverse(char *buffer, int i, int j) 21 | { 22 | while (i < j) { 23 | swap(&buffer[i++], &buffer[j--]); 24 | } 25 | 26 | return buffer; 27 | } 28 | 29 | // Iterative function to implement `itoa()` function in C 30 | char* itoa(int value, char* buffer, int base) 31 | { 32 | // invalid input 33 | if (base < 2 || base > 32) { 34 | return buffer; 35 | } 36 | 37 | // consider the absolute value of the number 38 | int n = abs(value); 39 | 40 | int i = 0; 41 | while (n) 42 | { 43 | int r = n % base; 44 | 45 | if (r >= 10) { 46 | buffer[i++] = 65 + (r - 10); 47 | } 48 | else { 49 | buffer[i++] = 48 + r; 50 | } 51 | 52 | n = n / base; 53 | } 54 | 55 | // if the number is 0 56 | if (i == 0) { 57 | buffer[i++] = '0'; 58 | } 59 | 60 | // If the base is 10 and the value is negative, the resulting string 61 | // is preceded with a minus sign (-) 62 | // With any other base, value is always considered unsigned 63 | if (value < 0 && base == 10) { 64 | buffer[i++] = '-'; 65 | } 66 | 67 | buffer[i] = '\0'; // null terminate string 68 | 69 | // reverse the string and return it 70 | return reverse(buffer, 0, i - 1); 71 | } 72 | //end of itoa block 73 | 74 | int main() 75 | { 76 | char a[10], ad[10], label[10], opcode[10], operand[10], symbol[10]; 77 | int start, diff, i, address, add, len, actual_len, finaddr, prevaddr, j = 0; 78 | char mnemonic[15][15] = {"LDA", "STA", "LDCH", "STCH"}; 79 | char code[15][15] = {"33", "44", "53", "57"}; 80 | 81 | FILE *fp1, *fp2, *fp3, *fp4; 82 | fp1 = fopen("output.txt", "w"); 83 | fp2 = fopen("symtab.txt", "r"); 84 | fp3 = fopen("intermediate.txt", "r"); 85 | fp4 = fopen("objcode.txt", "w"); 86 | 87 | fscanf(fp3, "%s\t%s\t%s", label, opcode, operand); 88 | 89 | while (strcmp(opcode, "END") != 0) 90 | { 91 | prevaddr = address; 92 | fscanf(fp3, "%d%s%s%s", &address, label, opcode, operand); 93 | } 94 | finaddr = address; 95 | 96 | fclose(fp3); 97 | fp3 = fopen("intermediate.txt", "r"); 98 | 99 | fscanf(fp3, "\t%s\t%s\t%s", label, opcode, operand); 100 | if (strcmp(opcode, "START") == 0) 101 | { 102 | fprintf(fp1, "\t%s\t%s\t%s\n", label, opcode, operand); 103 | fprintf(fp4, "H^%s^00%s^00%d\n", label, operand, finaddr); 104 | fscanf(fp3, "%d%s%s%s", &address, label, opcode, operand); 105 | start = address; 106 | diff = prevaddr - start; 107 | fprintf(fp4, "T^00%d^%d", address, diff); 108 | } 109 | 110 | while (strcmp(opcode, "END") != 0) 111 | { 112 | if (strcmp(opcode, "BYTE") == 0) 113 | { 114 | fprintf(fp1, "%d\t%s\t%s\t%s\t", address, label, opcode, operand); 115 | len = strlen(operand); 116 | actual_len = len - 3; 117 | fprintf(fp4, "^"); 118 | for (i = 2; i < (actual_len + 2); i++) 119 | { 120 | itoa(operand[i], ad, 16); 121 | fprintf(fp1, "%s", ad); 122 | fprintf(fp4, "%s", ad); 123 | } 124 | fprintf(fp1, "\n"); 125 | } 126 | 127 | else if (strcmp(opcode, "WORD") == 0) 128 | { 129 | len = strlen(operand); 130 | itoa(atoi(operand), a, 10); 131 | fprintf(fp1, "%d\t%s\t%s\t%s\t00000%s\n", address, label, opcode, operand, a); 132 | fprintf(fp4, "^00000%s", a); 133 | } 134 | 135 | else if ((strcmp(opcode, "RESB") == 0) || (strcmp(opcode, "RESW") == 0)) { 136 | fprintf(fp1, "%d\t%s\t%s\t%s\n", address, label, opcode, operand); 137 | } 138 | 139 | else 140 | { 141 | while (strcmp(opcode, mnemonic[j]) != 0) 142 | j++; 143 | if (strcmp(operand, "COPY") == 0) 144 | fprintf(fp1, "%d\t%s\t%s\t%s\t%s0000\n", address, label, opcode, operand, code[j]); 145 | else 146 | { 147 | rewind(fp2); 148 | fscanf(fp2, "%s%d", symbol, &add); 149 | while (strcmp(operand, symbol) != 0) 150 | fscanf(fp2, "%s%d", symbol, &add); 151 | fprintf(fp1, "%d\t%s\t%s\t%s\t%s%d\n", address, label, opcode, operand, code[j], add); 152 | fprintf(fp4, "^%s%d", code[j], add); 153 | } 154 | } 155 | 156 | fscanf(fp3, "%d%s%s%s", &address, label, opcode, operand); 157 | } 158 | 159 | fprintf(fp1, "%d\t%s\t%s\t%s\n", address, label, opcode, operand); 160 | fprintf(fp4, "\nE^00%d", start); 161 | 162 | fclose(fp4); 163 | fclose(fp3); 164 | fclose(fp2); 165 | fclose(fp1); 166 | 167 | display(); 168 | 169 | return 0; 170 | } 171 | 172 | void display() { 173 | char ch; 174 | FILE *fp1, *fp2, *fp3, *fp4; 175 | 176 | printf("\nIntermediate file is converted into object code"); 177 | 178 | printf("\n\nThe contents of Intermediate file:\n\n"); 179 | fp3 = fopen("intermediate.txt", "r"); 180 | ch = fgetc(fp3); 181 | while (ch != EOF) 182 | { 183 | printf("%c", ch); 184 | ch = fgetc(fp3); 185 | } 186 | fclose(fp3); 187 | 188 | printf("\n\nThe contents of Symbol Table :\n\n"); 189 | fp2 = fopen("symtab.txt", "r"); 190 | ch = fgetc(fp2); 191 | while (ch != EOF) 192 | { 193 | printf("%c", ch); 194 | ch = fgetc(fp2); 195 | } 196 | fclose(fp2); 197 | 198 | printf("\n\nThe contents of Output file :\n\n"); 199 | fp1 = fopen("output.txt", "r"); 200 | ch = fgetc(fp1); 201 | while (ch != EOF) 202 | { 203 | printf("%c", ch); 204 | ch = fgetc(fp1); 205 | } 206 | fclose(fp1); 207 | 208 | printf("\n\nThe contents of Object code file :\n\n"); 209 | fp4 = fopen("objcode.txt", "r"); 210 | ch = fgetc(fp4); 211 | while (ch != EOF) 212 | { 213 | printf("%c", ch); 214 | ch = fgetc(fp4); 215 | } 216 | fclose(fp4); 217 | 218 | } 219 | 220 | /* 221 | 222 | intermediate.txt 223 | ---------------- 224 | 225 | ** START 2000 226 | 2000 ** LDA FIVE 227 | 2003 ** STA ALPHA 228 | 2006 ** LDCH CHARZ 229 | 2009 ** STCH C1 230 | 2012 ALPHA RESW 2 231 | 2018 FIVE WORD 5 232 | 2021 CHARZ BYTE C'Z' 233 | 2022 C1 RESB 1 234 | 2023 ** END ** 235 | 236 | symtab.txt 237 | ---------- 238 | 239 | ALPHA 2012 240 | FIVE 2018 241 | CHARZ 2021 242 | C1 2022 243 | 244 | ----------------------------- 245 | 246 | output.txt 247 | ---------- 248 | 249 | ** START 2000 250 | 2000 ** LDA FIVE 332018 251 | 2003 ** STA ALPHA 442012 252 | 2006 ** LDCH CHARZ 532021 253 | 2009 ** STCH C1 572022 254 | 2012 ALPHA RESW 2 255 | 2018 FIVE WORD 5 000005 256 | 2021 CHARZ BYTE C'Z' 5a 257 | 2022 C1 RESB 1 258 | 2023 ** END ** 259 | 260 | objcode.txt 261 | ----------- 262 | 263 | H^**^002000^002023 264 | T^002000^22^332018^442012^532021^572022^000005^5a 265 | E^002000 266 | 267 | */ -------------------------------------------------------------------------------- /Cycle-4/symtab.txt: -------------------------------------------------------------------------------- 1 | ALPHA 2012 2 | FIVE 2018 3 | CHARZ 2021 4 | C1 2022 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SYSTEM-SOFTWARE-AND-MICROPROCESSORS-LAB- 2 | KTU S5 CSL 331 SYSTEM SOFTWARE AND MICROPROCESSORS LAB 3 | 4 |

MICROPROCESSOR LAB

5 |

I. Assembly Language Programming Exercises/Experiments using 8086 Trainer kit 6 |
II. Exercises/Experiments using MASM (PC required) 7 |
III. Interfacing Exercises/Experiments with 8086 trainer kit through Assembly Language 8 | programming 9 |
IV. Exercises/Experiments using 8051 trainer kit 10 |

SYSTEM SOFTWARE LAB:

11 |

I. Experiments related to the operating system. 12 |
II. Exercises/Experiments related to the assemblers, loaders and macroprocessors 13 |

14 | 15 |

MICROPROCESSORS LAB : List of Exercises/ Experiments

16 |
(Minimum 10 Exercises (at least 2 questions from each part I, II, III & IV) ) : 2 Hrs/week 17 |

I. Assembly Language Programming Exercises/Experiments using 8086 Trainer kit 18 |
1. Implementation of simple decimal arithmetic and bit manipulation operations. 19 |
2. Implementation of code conversion between BCD, Binary, Hexadecimal and 20 | ASCII. 21 |
3. Implementation of searching and sorting of 16-bit numbers. 22 |

II. Exercises/Experiments using MASM (PC Required) 23 |
4. Study of Assembler and Debugging commands. 24 |
5. Implementation of decimal arithmetic (16 and 32 bit) operations. 25 |
6. Implementation of String manipulations. 26 |
7. Implementation of searching and sorting of 16-bit numbers. 27 |

III. Interfacing Exercises/Experiments with 8086 trainer kit through Assembly Language 28 | Programming 29 |

8. Interfacing with stepper motor - Rotate through any given sequence. 30 |
9. Interfacing with 8255 (mode0 and mode1 only). 31 |
10. Interfacing with 8279 (Rolling message, 2 key lockout and N-key rollover 32 | implementation). 33 |
11. Interfacing with Digital-to-Analog Converter. 34 |

IV. Exercises/Experiments using 8051 trainer kit 35 |

12. Familiarization of 8051 trainer kit by executing simple Assembly Language programs 36 | such as decimal arithmetic and bit manipulation. 37 |
13. Implementation of Timer programming (in mode1). 38 |



SYSTEM SOFTWARE LAB: List of Exercises/ Experiments

39 |
(Minimum 8 Exercises (at least 3 and 5 questions from each part V and VI)) : 2 40 | Hrs/week 41 |

V. Exercises/Experiments from operating system 42 |
1. Simulate the following non-preemptive CPU scheduling algorithms to find turnaround 43 | time and waiting time. 44 |

a) FCFS b) SJF c) Round Robin (pre-emptive) d) Priority 45 |
2. Simulate the following file allocation strategies. 46 |
a) Sequential b) Indexed c) Linked 47 |
3. Implement the different paging techniques of memory management. 48 |
4. Simulate the following file organization techniques 49 |
a) Single level directory b) Two level directory c) Hierarchical 50 |
5. Implement the banker’s algorithm for deadlock avoidance. 51 |
6. Simulate the following disk scheduling algorithms. 52 |
a) FCFS b) SCAN c) C-SCAN 53 |
7. Simulate the following page replacement algorithms: 54 |
a)FIFO b)LRU c) LFU 55 |

VI. Exercises/Experiments from assemblers, loaders and macroprocessor 56 |

1. Implement pass one of a two pass assembler. 57 |
2. Implement pass two of a two pass assembler. 58 |
3. Implement a single pass assembler. 59 |
4. Implement a two pass macro processor 60 |
5.Implement a single pass macro processor. 61 |
6. Implement an absolute loader. 62 |
7. Implement a relocating loader 63 | -------------------------------------------------------------------------------- /mp new-staff[1524].docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PaulThomas20002/S5-SYSTEM-SOFTWARE-AND-MICROPROCESSORS-LAB/bc3f5ecf3cb1b525c9bb5f5921590976c59acd3c/mp new-staff[1524].docx --------------------------------------------------------------------------------