Skip to content

Commit

Permalink
Stage19 Assgn complete
Browse files Browse the repository at this point in the history
  • Loading branch information
dhwanish-3 committed Oct 5, 2023
1 parent 4efd16a commit 8728ec5
Show file tree
Hide file tree
Showing 10 changed files with 556 additions and 760 deletions.
41 changes: 41 additions & 0 deletions Stage19/Assgn1/list.expl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
type
list {
int val;
list next;
}
endtype

decl
list head, tempNode, node;
enddecl

int main() {
decl
int temp, n, x, i;
enddecl
begin
temp = initialize();
temp = exposcall("Write", -2, "Enter n: ");
temp = exposcall("Read", -1, n);
head = alloc();
tempNode = head;
i = 0;
while (i < n) do
node = alloc();
temp = exposcall("Read", -1, x);
node.val = x;
tempNode.next = node;
tempNode = node;
i = i + 1;
endwhile;
temp = exposcall("Write", -2, "Linked List:");
head = head.next;
i = 0;
while (i < n) do
temp = exposcall("Write", -2, head.val);
head = head.next;
i = i + 1;
endwhile;
return 0;
end
}
254 changes: 254 additions & 0 deletions Stage19/Assgn1/list.xsm
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
0
2056
0
0
0
0
0
0
MOV SP,4098
MOV BP,4099
PUSH R0
CALL 2066
INT 10
PUSH BP
MOV BP,SP
PUSH R0
PUSH R0
PUSH R0
PUSH R0
MOV R0,"Heapset"
PUSH R0
ADD SP,3
PUSH R0
CALL 0
SUB SP,5
MOV R1,BP
MOV R0,1
ADD R1,R0
MOV [R1],R0
MOV R0,"Write"
PUSH R0
MOV R0,-2
PUSH R0
MOV R0,"Enter n: "
PUSH R0
PUSH R0
PUSH R0
CALL 0
SUB SP,5
MOV R0,5
MOV R1,SP
ADD R1,R0
MOV R0,[R1]
MOV R2,BP
MOV R1,1
ADD R2,R1
MOV [R2],R0
MOV R0,"Read"
PUSH R0
MOV R0,-1
PUSH R0
MOV R1,BP
MOV R0,2
ADD R1,R0
MOV R0,[R1]
MOV R0,R1
MOV R0,R0
PUSH R0
PUSH R0
PUSH R0
CALL 0
SUB SP,5
MOV R0,5
MOV R1,SP
ADD R1,R0
MOV R0,[R1]
MOV R2,BP
MOV R1,1
ADD R2,R1
MOV [R2],R0
MOV R0,"Alloc"
PUSH R0
MOV R0,8
PUSH R0
ADD SP,2
PUSH R0
CALL 0
SUB SP,5
MOV R0,5
MOV R1,SP
ADD R1,R0
MOV R0,[R1]
MOV [4096],R0
MOV R0,[4096]
MOV [4097],R0
MOV R0,0
MOV R2,BP
MOV R1,4
ADD R2,R1
MOV [R2],R0
MOV R1,BP
MOV R0,4
ADD R1,R0
MOV R0,[R1]
MOV R2,BP
MOV R1,2
ADD R2,R1
MOV R1,[R2]
LT R0,R1
JZ R0,2372
MOV R0,"Alloc"
PUSH R0
MOV R0,8
PUSH R0
ADD SP,2
PUSH R0
CALL 0
SUB SP,5
MOV R0,5
MOV R1,SP
ADD R1,R0
MOV R0,[R1]
MOV [4098],R0
MOV R0,"Read"
PUSH R0
MOV R0,-1
PUSH R0
MOV R1,BP
MOV R0,3
ADD R1,R0
MOV R0,[R1]
MOV R0,R1
MOV R0,R0
PUSH R0
PUSH R0
PUSH R0
CALL 0
SUB SP,5
MOV R0,5
MOV R1,SP
ADD R1,R0
MOV R0,[R1]
MOV R2,BP
MOV R1,1
ADD R2,R1
MOV [R2],R0
MOV R1,BP
MOV R0,3
ADD R1,R0
MOV R0,[R1]
MOV R1,[4098]
MOV R2,1
ADD R2,R1
MOV R1,[R2]
MOV R1,R2
MOV [R1],R0
MOV R0,[4098]
MOV R1,[4097]
MOV R2,2
ADD R2,R1
MOV R1,[R2]
MOV R1,R2
MOV [R1],R0
MOV R0,[4098]
MOV [4097],R0
MOV R1,BP
MOV R0,4
ADD R1,R0
MOV R0,[R1]
MOV R1,1
ADD R0,R1
MOV R2,BP
MOV R1,4
ADD R2,R1
MOV [R2],R0
JMP 2220
MOV R0,"Write"
PUSH R0
MOV R0,-2
PUSH R0
MOV R0,"Linked List:"
PUSH R0
PUSH R0
PUSH R0
CALL 0
SUB SP,5
MOV R0,5
MOV R1,SP
ADD R1,R0
MOV R0,[R1]
MOV R2,BP
MOV R1,1
ADD R2,R1
MOV [R2],R0
MOV R0,[4096]
MOV R1,2
ADD R1,R0
MOV R0,[R1]
MOV [4096],R0
MOV R0,0
MOV R2,BP
MOV R1,4
ADD R2,R1
MOV [R2],R0
MOV R1,BP
MOV R0,4
ADD R1,R0
MOV R0,[R1]
MOV R2,BP
MOV R1,2
ADD R2,R1
MOV R1,[R2]
LT R0,R1
JZ R0,2524
MOV R0,"Write"
PUSH R0
MOV R0,-2
PUSH R0
MOV R0,[4096]
MOV R1,1
ADD R1,R0
MOV R0,[R1]
MOV R0,R0
PUSH R0
PUSH R0
PUSH R0
CALL 0
SUB SP,5
MOV R0,5
MOV R1,SP
ADD R1,R0
MOV R0,[R1]
MOV R2,BP
MOV R1,1
ADD R2,R1
MOV [R2],R0
MOV R0,[4096]
MOV R1,2
ADD R1,R0
MOV R0,[R1]
MOV [4096],R0
MOV R1,BP
MOV R0,4
ADD R1,R0
MOV R0,[R1]
MOV R1,1
ADD R0,R1
MOV R2,BP
MOV R1,4
ADD R2,R1
MOV [R2],R0
JMP 2428
MOV R0,0
MOV R1,BP
MOV R2,2
SUB R1,R2
MOV [R1],R0
POP R0
POP R0
POP R0
POP R0
MOV BP,[SP]
POP R0
RET
58 changes: 32 additions & 26 deletions Stage19/exhandler.spl
Original file line number Diff line number Diff line change
@@ -1,57 +1,62 @@
alias currentPID R0;
currentPID = [SYSTEM_STATUS_TABLE + 1];
breakpoint;

[PROCESS_TABLE + currentPID * 16 + 9] = -1;
[PROCESS_TABLE + [SYSTEM_STATUS_TABLE + 1] * 16 + 9] = -1;

[PROCESS_TABLE + currentPID * 16 + 13] = SP;
[PROCESS_TABLE + [SYSTEM_STATUS_TABLE + 1] * 16 + 13] = SP;

SP = [PROCESS_TABLE + currentPID * 16 + 11] * 512 - 1;
SP = [PROCESS_TABLE + [SYSTEM_STATUS_TABLE + 1] * 16 + 11] * 512 - 1;

backup;

multipush(EIP);

print "ex";

if ((EC != 0) || ([PROCESS_TABLE + currentPID * 16 + 13] == (PTLR * 512 - 1))) then
print "Fatal Error";

multipush(R0, R1);
if ((EC != 0) || ([PROCESS_TABLE + [SYSTEM_STATUS_TABLE + 1] * 16 + 13] == (PTLR * 512 - 1))) then
if (EC == 0) then
print "Stack overflow";
endif;
if (EC == 1) then
print "Illegal instruction";
endif;
if (EC == 2) then
print "Illegal memory access";
endif;
if (EC == 3) then
print "Arithmetic Exception";
endif;

multipush(R0);

R1 = 3;
R2 = currentPID;
R2 = [SYSTEM_STATUS_TABLE + 1];
call MOD_1;

call MOD_5;

multipop(R0, R1);
endif;

multipop(R0);
else
alias blockNumber R2;
if ((EPN > 3) && (EPN < 8)) then // code page
blockNumber = [DISK_MAP_TABLE + currentPID * 10 + EPN];
if (EPN > 3 && EPN < 8) then // code page
blockNumber = [DISK_MAP_TABLE + [SYSTEM_STATUS_TABLE + 1] * 10 + EPN];

multipush(R0, R1, R2);

multipush(EPN);
R1 = 5;
R2 = blockNumber;
call MOD_2;
print "page fault";

[PTBR + 2 * EPN] = R0;
[PTBR + 2 * EPN + 1] = "1100";
multipop(EPN);
[PAGE_TABLE_BASE + [SYSTEM_STATUS_TABLE + 1] * 20 + 2 * EPN] = R0;
[PAGE_TABLE_BASE + [SYSTEM_STATUS_TABLE + 1] * 20 + 2 * EPN + 1] = "1100";

multipop(R0, R1, R2);
endif;

if (EPN > 1 && EPN < 4) then // Heap
else
// Heap page
multipush(R0, R1, R2);

R1 = 1;
call MOD_2;
[PTBR + 4] = R0;
[PTBR + 5] = "1110";
print "heap";

R1 = 1;
call MOD_2;
Expand All @@ -60,8 +65,9 @@ if (EPN > 1 && EPN < 4) then // Heap

multipop(R0, R1, R2);
endif;
endif;

[PROCESS_TABLE + currentPID * 16 + 9] = 0;
[PROCESS_TABLE + [SYSTEM_STATUS_TABLE + 1] * 16 + 9] = 0;

multipop(EIP);

Expand Down
Loading

0 comments on commit 8728ec5

Please sign in to comment.