Advertisement
_Black_Panther_

Untitled

Mar 19th, 2021
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct list
  4. {
  5. int seg;
  6. int base;
  7. int limit;
  8. struct list *next;
  9. } *p;
  10. void insert(struct list *q,int base,int limit,int seg)
  11. {
  12. if(p==NULL)
  13. {
  14. p=malloc(sizeof(struct list));
  15. p->limit=limit;
  16. p->base=base;
  17. p->seg=seg;
  18. p->next=NULL;
  19. }
  20. else
  21. {
  22. while(q->next!=NULL)
  23. {
  24. q=q->next;
  25. printf("yes") ;
  26. }
  27. q->next=malloc(sizeof(struct list));
  28. q->next ->limit=limit;
  29. q->next ->base=base;
  30. q->next ->seg=seg;
  31. q->next ->next=NULL;
  32. }
  33. }
  34. int find(struct list *q,int seg)
  35. {
  36. while(q->seg!=seg)
  37. {
  38. q=q->next;
  39. }
  40. return q->limit;
  41. }
  42. int search(struct list *q,int seg)
  43. {
  44. while(q->seg!=seg)
  45. {
  46. q=q->next;
  47. }
  48. return q->base;
  49. }
  50. int main()
  51. {
  52. //p=NULL;
  53. int seg,offset,limit,base,c,s,physical;
  54. printf("Enter segment table\n");
  55. printf("Enter -1 as segment value for termination\n");
  56. do
  57. {
  58. printf("Enter segment number: ");
  59. scanf("%d",&seg);
  60. if(seg!=-1)
  61. {
  62. printf("Enter base value: ");
  63. scanf("%d",&base);
  64. printf("Enter value for limit: ");
  65. scanf("%d",&limit);
  66. insert(p,base,limit,seg);
  67. }
  68. }
  69. while(seg!=-1);
  70. printf("Enter offset: ");
  71. scanf("%d",&offset);
  72. printf("Enter bsegmentation number: ");
  73. scanf("%d",&seg);
  74. c=find(p,seg);
  75. s=search(p,seg);
  76. if(offset<c)
  77. {
  78. physical=s+offset;
  79. printf("Address in physical memory: %d\n",physical);
  80. }
  81. else
  82. {
  83. printf("error");
  84. }
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement