diff --git a/code/userprog/consoledriver.cc b/code/userprog/consoledriver.cc index 50a58b3..e409caa 100644 --- a/code/userprog/consoledriver.cc +++ b/code/userprog/consoledriver.cc @@ -70,13 +70,11 @@ void ConsoleDriver::PutInt(int n) delete [] buffer; } -int ConsoleDriver::GetInt() +void ConsoleDriver::GetInt(int * n) { - int n; char *buffer = new char[MAX_STRING_SIZE]; GetString(buffer,MAX_STRING_SIZE); - sscanf(buffer, "%d", &n); + sscanf(buffer, "%d", n); delete [] buffer; - return n; } #endif // CHANGED diff --git a/code/userprog/consoledriver.h b/code/userprog/consoledriver.h index a313f77..caf9a4c 100644 --- a/code/userprog/consoledriver.h +++ b/code/userprog/consoledriver.h @@ -19,7 +19,7 @@ class ConsoleDriver:dontcopythis { void PutString(const char *s); // Behaves like fputs(3S) void GetString(char *s, int n); // Behaves like fgets(3S) void PutInt(int n); - int GetInt(); + void GetInt(int * n); private: Console *console; }; diff --git a/code/userprog/exception.cc b/code/userprog/exception.cc index 8da8f1f..948f6a7 100644 --- a/code/userprog/exception.cc +++ b/code/userprog/exception.cc @@ -190,9 +190,11 @@ ExceptionHandler (ExceptionType which) case SC_GetInt: { DEBUG('s', "GetInt\n"); - int n = consoledriver->GetInt(); + int n; + int addr = machine->ReadRegister(4); + consoledriver->GetInt(&n); DEBUG('s', "Number entered: %d\n", n); - machine->WriteRegister(2,n); + machine->WriteMem(addr,sizeof(n),n); break; } #endif diff --git a/code/userprog/syscall.h b/code/userprog/syscall.h index 4ba2c36..96c9d33 100644 --- a/code/userprog/syscall.h +++ b/code/userprog/syscall.h @@ -143,7 +143,7 @@ void PutString (char *s); char GetChar(); void GetString(char *s, int n ); void PutInt(int n); -int GetInt(); +void GetInt( int * n); #endif // CHANGED