Skip to content

Commit

Permalink
Merge pull request #11 from dhwanish-3/cur_branch
Browse files Browse the repository at this point in the history
Max memory usage done
  • Loading branch information
dhwanish-3 authored Oct 23, 2023
2 parents 03150fc + dd73288 commit 1570554
Show file tree
Hide file tree
Showing 29 changed files with 3,908 additions and 581 deletions.
11 changes: 11 additions & 0 deletions Stage22/Assgn2/int15.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
alias taskManager R0;
taskManager = SYSTEM_STATUS_TABLE + 24;
print "contextSwitches:-";
print [taskManager];
print "------------";
print "maxMemUsage:-";
print [taskManager + 1];
print "------------";
print "diskAccesses:-";
print [taskManager + 2];
halt;
34 changes: 34 additions & 0 deletions Stage22/Assgn2/int15.xsm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
MOV R16, 29560
ADD R16, 24
MOV R0, R16
MOV R16, "contextSwitches:-"
PORT P1, R16
OUT
MOV R16, R0
MOV R16, [R16]
PORT P1, R16
OUT
MOV R16, "------------"
PORT P1, R16
OUT
MOV R16, "maxMemUsage:-"
PORT P1, R16
OUT
MOV R16, R0
ADD R16, 1
MOV R16, [R16]
PORT P1, R16
OUT
MOV R16, "------------"
PORT P1, R16
OUT
MOV R16, "diskAccesses:-"
PORT P1, R16
OUT
MOV R16, R0
ADD R16, 2
MOV R16, [R16]
PORT P1, R16
OUT
HALT
HALT
98 changes: 98 additions & 0 deletions Stage22/Assgn2/mod0.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
alias functionNum R1;
alias currentPID R2;

// Acquire Disk
if (functionNum == 3) then
while ([DISK_STATUS_TABLE] == 1) do
[PROCESS_TABLE + currentPID * 16 + 4] = WAIT_DISK;
multipush(R1, R2);
call MOD_5;
multipop(R1, R2);
endwhile;
// disk accesses
[SYSTEM_STATUS_TABLE + 26] = [SYSTEM_STATUS_TABLE + 26] + 1;
[DISK_STATUS_TABLE] = 1;
[DISK_STATUS_TABLE + 4] = currentPID;
return;
endif;

if (functionNum == 6) then // acquire semaphore
alias i R3;
i = 0;
while(i < MAX_SEM_COUNT && [SEMAPHORE_TABLE + 4 * i + 1] != 0) do
i = i + 1;
endwhile;

if (i == MAX_SEM_COUNT) then
R0 = -1;
else
[SEMAPHORE_TABLE + 4 * i] = -1;
[SEMAPHORE_TABLE + 4 * i + 1] = 1;
R0 = i;
endif;
return;
endif;

if (functionNum == 7) then // Release semaphore
alias semId R2;
alias currentPID R3;

if (currentPID == [SEMAPHORE_TABLE + semId * 4]) then
[SEMAPHORE_TABLE + semId * 4] = -1;
alias i R4;

i = 0;
while (i < 16) do
if ([PROCESS_TABLE + i * 16 + 4] == WAIT_SEMAPHORE && [PROCESS_TABLE + i * 16 + 5] == semId) then
[PROCESS_TABLE + i * 16 + 4] = READY;
[PROCESS_TABLE + i * 16 + 5] = -1;
endif;
i = i + 1;
endwhile;

[SEMAPHORE_TABLE + 4 * semId + 1] = [SEMAPHORE_TABLE + 4 * semId + 1] - 1;
endif;
return;
endif;

// Acquire Terminal
if (functionNum == 8) then
while ([TERMINAL_STATUS_TABLE] != 0) do
[PROCESS_TABLE + currentPID * 16 + 4] = WAIT_TERMINAL;
multipush(R1, R2);

call MOD_5;

multipop(R1, R2);
endwhile;

[TERMINAL_STATUS_TABLE] = 1;
[TERMINAL_STATUS_TABLE + 1] = currentPID;
return;
endif;

// Release Terminal
if (functionNum == 9) then
if (currentPID != [TERMINAL_STATUS_TABLE + 1]) then
alias returnValue R0;
returnValue = -1;
return;
else
[TERMINAL_STATUS_TABLE] = 0;
alias i R3;
i = 0;
while (i < 16) do
if ([PROCESS_TABLE + i * 16 + 4] == WAIT_TERMINAL) then
[PROCESS_TABLE + 16 * i + 4] = READY;
endif;
i = i + 1;
endwhile;
alias returnValue R0;
returnValue = 0;
return;
endif;
else
alias returnValue R0;
returnValue = -1;
return;
endif;
239 changes: 239 additions & 0 deletions Stage22/Assgn2/mod0.xsm
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
MOV R16, 3
EQ R16, R1
JZ R16, _L1
_L3:
MOV R16, 29552
MOV R16, [R16]
MOV R17, 1
EQ R16, R17
JZ R16, _L4
MOV R16, 28672
MOV R17, R2
MUL R17, 16
ADD R16, R17
ADD R16, 4
MOV [R16], 5
PUSH R1
PUSH R2
CALL 25600
POP R2
POP R1
JMP _L3
_L4:
MOV R16, 29560
ADD R16, 26
MOV R17, 29560
ADD R17, 26
MOV R17, [R17]
ADD R17, 1
MOV [R16], R17
MOV [29552], 1
MOV R16, 29552
ADD R16, 4
MOV [R16], R2
RET
JMP _L2
_L1:
_L2:
MOV R16, 6
EQ R16, R1
JZ R16, _L5
MOV R3, 0
_L7:
MOV R16, 32
GT R16, R3
MOV R17, 29056
MOV R18, 4
MUL R18, R3
ADD R17, R18
ADD R17, 1
MOV R17, [R17]
MOV R18, 0
NE R17, R18
MUL R16, R17
JZ R16, _L8
MOV R16, R3
ADD R16, 1
MOV R3, R16
JMP _L7
_L8:
MOV R16, 32
EQ R16, R3
JZ R16, _L9
MOV R0, -1
JMP _L10
_L9:
MOV R16, 29056
MOV R17, 4
MUL R17, R3
ADD R16, R17
MOV [R16], -1
MOV R16, 29056
MOV R17, 4
MUL R17, R3
ADD R16, R17
ADD R16, 1
MOV [R16], 1
MOV R0, R3
_L10:
RET
JMP _L6
_L5:
_L6:
MOV R16, 7
EQ R16, R1
JZ R16, _L11
MOV R16, 29056
MOV R17, R2
MUL R17, 4
ADD R16, R17
MOV R16, [R16]
EQ R16, R3
JZ R16, _L13
MOV R16, 29056
MOV R17, R2
MUL R17, 4
ADD R16, R17
MOV [R16], -1
MOV R4, 0
_L15:
MOV R16, 16
GT R16, R4
JZ R16, _L16
MOV R16, 28672
MOV R17, R4
MUL R17, 16
ADD R16, R17
ADD R16, 4
MOV R16, [R16]
MOV R17, 10
EQ R16, R17
MOV R17, 28672
MOV R18, R4
MUL R18, 16
ADD R17, R18
ADD R17, 5
MOV R17, [R17]
EQ R17, R2
MUL R16, R17
JZ R16, _L17
MOV R16, 28672
MOV R17, R4
MUL R17, 16
ADD R16, R17
ADD R16, 4
MOV [R16], 1
MOV R16, 28672
MOV R17, R4
MUL R17, 16
ADD R16, R17
ADD R16, 5
MOV [R16], -1
JMP _L18
_L17:
_L18:
MOV R16, R4
ADD R16, 1
MOV R4, R16
JMP _L15
_L16:
MOV R16, 29056
MOV R17, 4
MUL R17, R2
ADD R16, R17
ADD R16, 1
MOV R17, 29056
MOV R18, 4
MUL R18, R2
ADD R17, R18
ADD R17, 1
MOV R17, [R17]
SUB R17, 1
MOV [R16], R17
JMP _L14
_L13:
_L14:
RET
JMP _L12
_L11:
_L12:
MOV R16, 8
EQ R16, R1
JZ R16, _L19
_L21:
MOV R16, 29568
MOV R16, [R16]
MOV R17, 0
NE R16, R17
JZ R16, _L22
MOV R16, 28672
MOV R17, R2
MUL R17, 16
ADD R16, R17
ADD R16, 4
MOV [R16], 8
PUSH R1
PUSH R2
CALL 25600
POP R2
POP R1
JMP _L21
_L22:
MOV [29568], 1
MOV R16, 29568
ADD R16, 1
MOV [R16], R2
RET
JMP _L20
_L19:
_L20:
MOV R16, 9
EQ R16, R1
JZ R16, _L23
MOV R16, 29568
ADD R16, 1
MOV R16, [R16]
NE R16, R2
JZ R16, _L25
MOV R0, -1
RET
JMP _L26
_L25:
MOV [29568], 0
MOV R3, 0
_L27:
MOV R16, 16
GT R16, R3
JZ R16, _L28
MOV R16, 28672
MOV R17, R3
MUL R17, 16
ADD R16, R17
ADD R16, 4
MOV R16, [R16]
MOV R17, 8
EQ R16, R17
JZ R16, _L29
MOV R16, 28672
MOV R17, 16
MUL R17, R3
ADD R16, R17
ADD R16, 4
MOV [R16], 1
JMP _L30
_L29:
_L30:
MOV R16, R3
ADD R16, 1
MOV R3, R16
JMP _L27
_L28:
MOV R0, 0
RET
_L26:
JMP _L24
_L23:
MOV R0, -1
RET
_L24:
HALT
Loading

0 comments on commit 1570554

Please sign in to comment.