English 中文(简体)
MIPS Assemblysign HELP!
原标题:MIPS Assembly assignment HELP!

我最亲密的朋友正在通过EE课程(他的最后希望:/),我知道大约7年前的Java,但他的

起草一项方案,涉及两种积极的分类(m and n)和计算:

x= (m^n) - (1+2+3+…+n) * min(m,n)!

Both the integers should be greater than zero. I m not allowed to use any R-type arithmetic instructions (add, mult, sub). Instead I m to write the code for their functions using other instructions???? "Your program should continue getting new values for m and n after each computation until the user enters zero which would be the end for your program."

我没有机会接受他以前的任何任务,试图利用(增加、增加、次)时间为我做的工作,将第1位排在编组语言中。

ece.ucdavis.edu/~vojin/CLASSES/EEC70/W2001/pr4.pdf Prof seemed to be using an ols assignment from when he was teaching at UC Davis.

//edit Here is a c++ version of the problem, it does not cover all of the assignment s bases, but it s a starting point:

#include <iostream.h>

//x = (m^n) - (1+2+3+...+n) * ((min(m,n))!)
int m; //User Input
int n; //User Input
double answer; //Answer yo.

int findMin(int, int); //Takes 2 int inputs and outputs the smallest int.
int minFound; //Function output

double factorial(int); //Do eet.
double factOutput; //Function output

double sumN(int); //1+2+3+...+n
double sumFound; //Function output

double expMtoN(int, int); //m^n, float for number size,
double expFound; //Function output, float for number size,

int main(void)
{
    cout << "Please enter a positive integer (m): ";
    cin >> m;

    //Escape if zero.
    if ( m == 0)
    {
        cout << "User input for "m" is equal to zero; escape on zero." << endl;
        return 0;
    }

    cout << "Please enter a positive integer (n): ";
    cin >> n;

    //Escape if zero.
    if ( n == 0)
    {
        cout << "User input for "n" is equal to zero; escape on zero." << endl;
        return 0;
    }

    expFound   = expMtoN(m, n);       //m^n
    sumFound   = sumN(n);             //1+2+3+...+n
    minFound   = findMin(m, n);       //Takes 2 int inputs and outputs the smallest int.
    factOutput = factorial(minFound); //Factorial math for minFound (z!)

    answer = expFound - sumFound * factOutput; //x = (m^n) - (1+2+3+...+n) * ((min(m,n))!)

    cout << endl;
    cout << m << " raised to the power of " << n << " is: " << expFound << endl;
    cout << "Sum of " << n << " is: " << sumFound << endl;
    cout << "Lowest number out of " << m << " and " << n << " is: " << minFound << endl;
    cout << minFound << " factorial is: " << factOutput << endl;

    cout << endl << "x = (m^n) - (1+2+3+...+n) * ((min(m,n))!)" << endl;
    cout << "x = " << answer << endl;
}

//all temp variables below are confined to their respective functions.
//return functions output temp into variable from main.

double expMtoN(int userBase, int userExp)
{
    double temp = 1; //Must establish  1 so you are not multiplying by zero.

    for ( int i = 1; i <= userExp; i++ )
        temp *= userBase;

    return temp;
}

double sumN(int userN)
{
    double temp = 0;

    for ( int i = 1; i <= userN; i++ )
        temp = temp + i;

    return temp;
}

int findMin(int userM, int userN)
{
    if( userM <= userN )
        return userM;
    else
        return userN;
}

double factorial(int minFound)
{
    double temp;

    if ( minFound <= 1 )
        return 1;

    temp = minFound * factorial(minFound - 1);

    return temp;
}

投入。


;-----------------------------------------------------------------------------
;Subprogram call by symbol "InputUnsigned"
;expect the address of a zero-terminated prompt string in R1
;returns the read value in R1
;changes the contents of registers R1,R13,R14
;-----------------------------------------------------------------------------

  .data

  ;*** Data for Read-Trap
ReadBuffer: .space  80
ReadPar: .word  0,ReadBuffer,80

  ;*** Data for Printf-Trap
PrintfPar: .space  4

SaveR2:  .space  4
SaveR3:  .space  4
SaveR4:  .space  4
SaveR5:  .space  4


  .text

  .global  InputUnsigned
InputUnsigned: 
  ;*** save register contents
  sw  SaveR2,r2
  sw  SaveR3,r3
  sw  SaveR4,r4
  sw  SaveR5,r5

  ;*** Prompt
  sw  PrintfPar,r1
  addi  r14,r0,PrintfPar
  trap  5

  ;*** call Trap-3 to read line
  addi  r14,r0,ReadPar
  trap  3

  ;*** determine value
  addi  r2,r0,ReadBuffer
  addi  r1,r0,0
  addi  r4,r0,10 ;Decimal system

Loop:  ;*** reads digits to end of line
  lbu  r3,0(r2)
  seqi  r5,r3,10 ;LF -> Exit
  bnez  r5,Finish
  subi  r3,r3,48 ;´0´
  multu  r1,r1,r4 ;Shift decimal
  add  r1,r1,r3
  addi  r2,r2,1  ;increment pointer
  j  Loop

Finish:  ;*** restore old register contents
  lw  r2,SaveR2
  lw  r3,SaveR3
  lw  r4,SaveR4
  lw  r5,SaveR5
  jr  r31  ; Return 
问题回答

不幸的是,如果是《刑法》,那么根据这些限制,《科索沃警察部队法》将至少延长4X年。 这部法律可能同时适用,但我可以让步行走:

页: 1

让我们首先注意到,如同任何其他方案拟订语言一样,我们应当把我们的任务分成尽可能多的方法。 在科索沃警察部队中,我们希望把这项任务分成尽可能多的“程序”。 我们已经看到,我们将需要一个指数、系数等程序。 我们从零开始。 我们可以使用杂质,因为它是R型的,但我们可以使用多种,即I型。 我们可以利用所有现成的第一类替代任务。 因此,我们可以做到:例如,在一次休息时,花了多米时间,并且只花了这个零时间(每一次,我们会把结果从Hi和L的乘数登记册上转移,使用Mmfhi和mflo的指示进行计算,以便他们不会再读书)。 这是我们的第一个程序。

我们现在看一看1+2+3+......+n。 这不是太坏了,我们只是继续使用添加(在登记册中增加“中值”不变值的I类附加指示),例如增加1美元,1美元,1美元,其中1美元在 lo中增加,在结果的零时间上增加,因此达到1+2+3+......+n。

最后,我们需要另一种程序,以min(m,n)的方式来增加。 保理性是休止的,因此,我们需要一种留意程序,以自我为呼声,妥善利用记忆套和登记外溢(IE,首先挽救程序论点,回到 st上来,进入身体,再次呼吁自己)。 我认为,这足以使你开始。 不能确定任务何时到期,而是好的uck!





相关问题
List of suspected Malicious patterns

I am doing an anti-virus project by disassembling its code and analyzing it. So I want a list of the Suspected Malicious pattern codes, so I can observe which is suspected and which is not? So I want ...

Prefetch for Intel Core 2 Duo

Has anyone had experience using prefetch instructions for the Core 2 Duo processor? I ve been using the (standard?) prefetch set (prefetchnta, prefetcht1, etc) with success for a series of P4 ...

How are mutex and lock structures implemented?

I understand the concept of locks, mutex and other synchronization structures, but how are they implemented? Are they provided by the OS, or are these structures dependent on special CPU instructions ...

Installing GNU Assembler in OSX

No matter how hard I google, I can t seem to find a (relatively) easy-to-follow instruction on how to install the GNU Assembler on a mac. I know I can use gcc -c (Apple Clang on a Mac) to assemble .s ...

8086 assembler,INT 16,2

I got stuck at this thing,I want to see if right shift button has been pressed,so I have this assambler code: mov ah,2 int 16h ;calling INT 16,2 - Read Keyboard Flags interrupt mov ah,...

Translate a FOR to assembler

I need to translate what is commented within the method, to assembler. I have a roughly idea, but can t. Anyone can help me please? Is for an Intel x32 architecture: int secuencia ( int n, ...

热门标签