private bool Sys_Write() { // get fd index UInt64 fd_index = RBX; if (fd_index >= (UInt64)FDCount) { Terminate(ErrorCode.OutOfBounds); return(false); } // get fd IFileWrapper fd = FileDescriptors[fd_index]; if (fd == null) { Terminate(ErrorCode.FDNotInUse); return(false); } // make sure we can write if (!fd.CanWrite()) { Terminate(ErrorCode.FilePermissions); return(false); } // make sure we're in bounds if (RCX >= MemorySize || RDX >= MemorySize || RCX + RDX > MemorySize) { Terminate(ErrorCode.OutOfBounds); return(false); } // attempt to write from memory to the file - success = num written, fail = -1 try { RAX = (UInt64)fd.Write(Memory, (int)RCX, (int)RDX); } catch (Exception) { RAX = ~(UInt64)0; } return(true); }