Skip to content

Commit

Permalink
Merge pull request #7 from dhwanish-3/stage21+
Browse files Browse the repository at this point in the history
Stage22 done
  • Loading branch information
dhwanish-3 authored Oct 20, 2023
2 parents 1968899 + ab9af39 commit 6f07c1a
Show file tree
Hide file tree
Showing 27 changed files with 6,121 additions and 78 deletions.
2 changes: 1 addition & 1 deletion Stage20/fork.spl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ else

multipop(R0, R1, R2, R3);

[PROCESS_MANAGER + newPID * 16 + 11] = R5;
[PROCESS_TABLE + newPID * 16 + 11] = R5;

// initialization per process resourse table child
alias i R4;
Expand Down
108 changes: 52 additions & 56 deletions Stage20/fork.xsm
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,30 @@ JMP _L4
_L3:
_L4:
MOV R16, 29696
MOV R17, R2
MUL R17, 20
MOV R17, 20
MUL R17, R2
ADD R16, R17
MOV R4, R16
MOV R3, R16
PUSH R0
PUSH R1
PUSH R2
PUSH R3
PUSH R4
MOV R1, 1
CALL 22528
MOV R16, R4
MOV R16, R3
ADD R16, 16
MOV [R16], R0
MOV R16, R4
MOV R16, R3
ADD R16, 17
MOV [R16], "0110"
MOV R1, 1
CALL 22528
MOV R16, R4
MOV R16, R3
ADD R16, 18
MOV [R16], R0
MOV R16, R4
MOV R16, R3
ADD R16, 19
MOV [R16], "0110"
POP R4
POP R3
POP R2
POP R1
Expand Down Expand Up @@ -235,11 +233,9 @@ PUSH R0
PUSH R1
PUSH R2
PUSH R3
PUSH R4
MOV R1, 1
CALL 22528
MOV R5, R0
POP R4
POP R3
POP R2
POP R1
Expand All @@ -252,10 +248,10 @@ ADD R16, 11
MOV [R16], R5
MOV R16, 512
SUB R16, 16
MOV R3, R16
MOV R4, R16
_L5:
MOV R16, 512
GT R16, R3
GT R16, R4
JZ R16, _L6
MOV R16, 28672
MOV R17, R2
Expand All @@ -264,7 +260,7 @@ ADD R16, R17
ADD R16, 11
MOV R16, [R16]
MUL R16, 512
ADD R16, R3
ADD R16, R4
MOV R17, 28672
MOV R18, 29560
ADD R18, 1
Expand All @@ -274,71 +270,71 @@ ADD R17, R18
ADD R17, 11
MOV R17, [R17]
MUL R17, 512
ADD R17, R3
ADD R17, R4
MOV R17, [R17]
MOV [R16], R17
MOV R16, R3
MOV R16, R4
ADD R16, 1
MOV R3, R16
MOV R4, R16
JMP _L5
_L6:
MOV R3, 0
MOV R4, 0
_L7:
MOV R16, 10
GT R16, R3
GT R16, R4
JZ R16, _L8
MOV R16, 30032
MOV R17, R2
MUL R17, 10
MOV R17, 10
MUL R17, R2
ADD R16, R17
ADD R16, R3
ADD R16, R4
MOV R17, 30032
MOV R18, 29560
ADD R18, 1
MOV R18, [R18]
MUL R18, 10
ADD R17, R18
ADD R17, R3
ADD R17, R4
MOV R17, [R17]
MOV [R16], R17
MOV R16, R3
MOV R16, R4
ADD R16, 1
MOV R3, R16
MOV R4, R16
JMP _L7
_L8:
MOV R3, 0
MOV R4, 0
_L9:
MOV R16, 16
GT R16, R3
GT R16, R4
JZ R16, _L10
MOV R16, R4
ADD R16, R3
MOV R16, R3
ADD R16, R4
MOV R17, PTBR
ADD R17, R3
ADD R17, R4
MOV R17, [R17]
MOV [R16], R17
MOV R16, R4
ADD R16, R3
MOV R16, R3
ADD R16, R4
ADD R16, 1
MOV R17, PTBR
ADD R17, R3
ADD R17, R4
ADD R17, 1
MOV R17, [R17]
MOV [R16], R17
MOV R16, R4
ADD R16, R3
MOV R16, R3
ADD R16, R4
MOV R16, [R16]
MOV R17, -1
NE R16, R17
JZ R16, _L11
MOV R16, 29184
MOV R17, R4
ADD R17, R3
MOV R17, R3
ADD R17, R4
MOV R17, [R17]
ADD R16, R17
MOV R17, 29184
MOV R18, R4
ADD R18, R3
MOV R18, R3
ADD R18, R4
MOV R18, [R18]
ADD R17, R18
MOV R17, [R17]
Expand All @@ -347,61 +343,61 @@ MOV [R16], R17
JMP _L12
_L11:
_L12:
MOV R16, R3
MOV R16, R4
ADD R16, 2
MOV R3, R16
MOV R4, R16
JMP _L9
_L10:
MOV R16, PTBR
ADD R16, 16
MOV R16, [R16]
MOV R5, R16
MOV R16, R4
MOV R16, R3
ADD R16, 16
MOV R16, [R16]
MOV R6, R16
MOV R3, 0
MOV R4, 0
_L13:
MOV R16, 512
GT R16, R3
GT R16, R4
JZ R16, _L14
MOV R16, R6
MUL R16, 512
ADD R16, R3
ADD R16, R4
MOV R17, R5
MUL R17, 512
ADD R17, R3
ADD R17, R4
MOV R17, [R17]
MOV [R16], R17
MOV R16, R3
MOV R16, R4
ADD R16, 1
MOV R3, R16
MOV R4, R16
JMP _L13
_L14:
MOV R16, PTBR
ADD R16, 18
MOV R16, [R16]
MOV R5, R16
MOV R16, R4
MOV R16, R3
ADD R16, 18
MOV R16, [R16]
MOV R6, R16
MOV R3, 0
MOV R4, 0
_L15:
MOV R16, 512
GT R16, R3
GT R16, R4
JZ R16, _L16
MOV R16, R6
MUL R16, 512
ADD R16, R3
ADD R16, R4
MOV R17, R5
MUL R17, 512
ADD R17, R3
ADD R17, R4
MOV R17, [R17]
MOV [R16], R17
MOV R16, R3
MOV R16, R4
ADD R16, 1
MOV R3, R16
MOV R4, R16
JMP _L15
_L16:
MOV R16, 28672
Expand Down Expand Up @@ -438,7 +434,7 @@ MOV R17, R0
SUB R17, 1
DIV R17, 512
MUL R16, R17
ADD R16, R4
ADD R16, R3
MOV R16, [R16]
MUL R16, 512
MOV R17, R0
Expand Down
83 changes: 83 additions & 0 deletions Stage22/Assgn1/test4.expl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
type
Share
{
int isempty;
int data;
}
endtype

decl
Share head;
enddecl

int main()
{
decl
int temp, x, pidone, pidtwo, semid, iter, counter;
enddecl

begin
x = exposcall("Heapset");
semid = exposcall("Semget");
head = exposcall("Alloc", 2);
head.isempty = 1;
pidone = exposcall("Fork");

if (pidone == 0) then
iter = 1;
while(iter <= 100) do
temp = exposcall("SemLock", semid);
temp = head.isempty;

if(temp == 1) then
head.data = iter;
head.isempty = 0;
iter = iter + 2;
endif;

temp = exposcall("SemUnLock", semid);

counter = 0;
while(counter < 50) do
counter = counter + 1;
endwhile;
endwhile;
else
pidtwo = exposcall("Fork");

if(pidtwo == 0) then
iter = 2;
while(iter <= 100) do
temp = exposcall("SemLock", semid);
temp = head.isempty;

if(temp == 1) then
head.data = iter;
head.isempty = 0;
iter = iter + 2;
endif;

temp = exposcall("SemUnLock", semid);
endwhile;
else
iter = 1;
while(iter <= 100) do
temp = exposcall("SemLock", semid);
temp = head.isempty;

if(temp == 0) then
x = head.data;
head.isempty = 1;
temp = exposcall("Write", -2, x);
iter = iter + 1;
endif;

temp = exposcall("SemUnLock", semid);
endwhile;
endif;
endif;

temp = exposcall("Semrelease", semid);
return 0;
end
}
Loading

0 comments on commit 6f07c1a

Please sign in to comment.