-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq2.c
64 lines (53 loc) · 1.19 KB
/
q2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <stdlib.h>
struct B_B{
int base;
int bound;
};
int Add_Translation(struct B_B seg, int offset){
if(offset>= seg.bound)return -1;
return seg.base+offset;
}
int main(){
struct{
struct B_B Code;
struct B_B Heap;
struct B_B Stack;
}Add_Space;
Add_Space.Code.base = 0x8000;
Add_Space.Code.bound = 0x0800;
Add_Space.Heap.base = 0x8800;
Add_Space.Heap.bound = 0x0C00;
Add_Space.Stack.base = 0x7000;
Add_Space.Stack.bound = 0x0800;
int address;
printf("Enter the address (Hex): \n");
scanf("%x", &address);
int choice;
printf("Choose which segment to translate: \n");
printf("1. Code\n");
printf("2. Heap\n");
printf("3. Stack\n");
scanf("%i", &choice);
int addPhysical = -1;
if(choice == 1){
addPhysical = Add_Translation(Add_Space.Code, address);
}
else if(choice == 2){
addPhysical = Add_Translation(Add_Space.Code, address);
}
else if(choice == 3){
addPhysical = Add_Translation(Add_Space.Code, address);
}
else{
printf("Invalid Choice\n");
}
if(addPhysical!= -1){
printf("Physical Address: 0x%X", addPhysical);
}
else{
printf("Segmentation Fault\n");
abort();
}
return 0;
}