Skip to content

Commit

Permalink
Add syscall PrintInt
Browse files Browse the repository at this point in the history
  • Loading branch information
thangtq139 committed Oct 19, 2017
1 parent b7488dc commit 7dda801
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
Binary file modified src/nachos-3.4/code/test/halt
Binary file not shown.
Binary file modified src/nachos-3.4/code/test/matmult
Binary file not shown.
Binary file modified src/nachos-3.4/code/test/printchar
Binary file not shown.
Binary file modified src/nachos-3.4/code/test/shell
Binary file not shown.
Binary file modified src/nachos-3.4/code/test/sort
Binary file not shown.
27 changes: 27 additions & 0 deletions src/nachos-3.4/code/userprog/exception.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
// are in machine.h.
//----------------------------------------------------------------------

#define ABS(x) ((x) < 0 ? -(x) : (x))

void
AdjustPCRegs()
{
Expand Down Expand Up @@ -110,6 +112,31 @@ SyscallPrintChar()
AdjustPCRegs();
}

void
SyscallPrintInt()
{
int number, abs_number, len, i, j;
char tmp;
number = machine->ReadRegister(4);
abs_number = ABS(number);
len = 0;
char *str = new char[13];
do {
str[len++] = (char)(abs_number % 10 + '0');
abs_number /= 10;
} while (abs_number);
if (abs_number < 0)
str[len++] = '-';
for (i = 0; i < len / 2; ++i) {
j = len - i - 1;
tmp = str[i];
str[i] = str[j];
str[j] = tmp;
}
str[len++] = '\0';
}


void
ExceptionHandler(ExceptionType which)
{
Expand Down

0 comments on commit 7dda801

Please sign in to comment.