Main Page   Compound List   File List   Compound Members   File Members  

mipssim.cc File Reference

#include "copyright.h"
#include "machine.h"
#include "mipssim.h"
#include "system.h"

Go to the source code of this file.

Functions

void Mult (int a, int b, bool signedArith, int *hiPtr, int *loPtr)
int TypeToReg (RegType reg, Instruction *instr)


Function Documentation

void Mult int    a,
int    b,
bool    signedArith,
int *    hiPtr,
int *    loPtr
[static]
 

Definition at line 636 of file mipssim.cc.

References FALSE.

Referenced by Machine::OneInstruction.

00637 {
00638     if ((a == 0) || (b == 0)) {
00639         *hiPtr = *loPtr = 0;
00640         return;
00641     }
00642 
00643     // Compute the sign of the result, then make everything positive
00644     // so unsigned computation can be done in the main loop.
00645     bool negative = FALSE;
00646     if (signedArith) {
00647         if (a < 0) {
00648             negative = !negative;
00649             a = -a;
00650         }
00651         if (b < 0) {
00652             negative = !negative;
00653             b = -b;
00654         }
00655     }
00656 
00657     // Compute the result in unsigned arithmetic (check a's bits one at
00658     // a time, and add in a shifted value of b).
00659     unsigned int bLo = b;
00660     unsigned int bHi = 0;
00661     unsigned int lo = 0;
00662     unsigned int hi = 0;
00663     for (int i = 0; i < 32; i++) {
00664         if (a & 1) {
00665             lo += bLo;
00666             if (lo < bLo)  // Carry out of the low bits?
00667                 hi += 1;
00668             hi += bHi;
00669             if ((a & 0xfffffffe) == 0)
00670                 break;
00671         }
00672         bHi <<= 1;
00673         if (bLo & 0x80000000)
00674             bHi |= 1;
00675         
00676         bLo <<= 1;
00677         a >>= 1;
00678     }
00679 
00680     // If the result is supposed to be negative, compute the two's
00681     // complement of the double-word result.
00682     if (negative) {
00683         hi = ~hi;
00684         lo = ~lo;
00685         lo++;
00686         if (lo == 0)
00687             hi++;
00688     }
00689     
00690     *hiPtr = (int) hi;
00691     *loPtr = (int) lo;
00692 }

int TypeToReg RegType    reg,
Instruction   instr
[static]
 

Definition at line 54 of file mipssim.cc.

References Instruction::extra, EXTRA, Instruction::rd, RD, RegType, Instruction::rs, RS, Instruction::rt, and RT.

Referenced by Machine::OneInstruction.

00055 {
00056     switch (reg) {
00057       case RS:
00058         return instr->rs;
00059       case RT:
00060         return instr->rt;
00061       case RD:
00062         return instr->rd;
00063       case EXTRA:
00064         return instr->extra;
00065       default:
00066         return -1;
00067     }
00068 }


Generated on Mon Feb 10 09:54:50 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees