mips

How to find remainder without division or modulo operator in MIPS assembly

老子叫甜甜 提交于 2020-01-01 19:01:11
问题 I want to find a way to know if an integer is divided by 3 or 7 without using division, because it is very slow in MIPS assembly. I have done a lot of research but found nothing. 回答1: There's a method described by Granlund & Montgomery that requires the modular / multiplicative inverse of the (odd) divisor modulo 2**b . (Some parts of this paper have been improved recently) The divisors: (d) = 3, 7 (odd numbers) are an easy case. Assuming 32 bit (unsigned) arithmetic, the inverses modulo 2*

PcSpim syntax error on pseudo instructions

跟風遠走 提交于 2019-12-31 07:47:23
问题 I keep getting syntax error if i use instructions like li or la. If i try a code without these instructions it works fine, but i need to use them. I tried different versions and i keep getting the same error (I have allowed pseudo instructions). I need to use it for a university project but i can't check if the code i wrote is ok since i can't run the code. Am i missing something? I don't know how to make it work properly, i'm new to assembly and pcspim, so i may be overlooking something

MIPS - implementing a binary search tree

大兔子大兔子 提交于 2019-12-31 04:12:06
问题 As our term project, we're implementing a binary search tree. The thought behind it is as follows: Assume a bst with 3 nodes: 10 / \ / \ 8 14 Its address representation is as follows (value, left node address, right node address, root node address)t: 400:|----------| | 8 | |----------| | 0 | |----------| | 0 | |----------| | 620 | |----------| | . | | . | | . | $a0=620:|----------| | 10 | |----------| | 400 | |----------| | 1000 | |----------| | 0 | |----------| | . | | . | | . | 1000:|------

Convert C++ to MIPS assembly

半腔热情 提交于 2019-12-31 03:31:07
问题 This code is about to find maximum element from an array i want to convert this code into MIPS assembly code can anyone help me...Or just tell me how to initialize an array in MIPS. void max_array() { int a[10]={2,3,421,4,32,4,3,1,4,5},max; for(int i=0;i<9;i++) { cout<<a[i]; } max=a[0]; for(int j=1;j<9;j++) { if (max<a[j]) { max=a[j]; } } return max; } 回答1: Here's an example .data array1: .space 12 # declare 12 bytes of storage to hold array of 3 integers .text __start: la $t0, array1 # load

Is that true if we can always fill the delay slot there is no need for branch prediction?

末鹿安然 提交于 2019-12-31 02:54:06
问题 I'm looking at the five stages MIPS pipeline (ID,IF,EXE,MEM,WB) in H&P 3rd ed. and it seems to me that the branch decision is resolved at the stage of ID so that while the branch instruction reaches its EXE stage, the second instruction after the branch can be executed correctly (can be fetched). But this leaves us the problem of possibly still wasting the 1st instruction soon after the branch instruction. I also encountered the concept of branch delay slot, which means you want to fill the

MIPS understand binary representation

岁酱吖の 提交于 2019-12-31 02:10:51
问题 On the process of learning Assembly i got one question If i do the following: la $a1, 0x3f The number 63 is "putted" on a1. But If I do: la $a1, 63 Its the same. But how can I handle binary? Lets say la $a1, 00111111 How can MIPS understand that 00111111 is the number 63 in binary? 回答1: Binary literal constants are not typically supported. What assembler are you using? If it supports C style preprocessing, there are several options available. Here is one example. 来源: https://stackoverflow.com

How to create a jump table using a jr instruction?

和自甴很熟 提交于 2019-12-30 07:50:22
问题 C++ Program # include < iostream > # include <string > using namespace std; int main () { int resistance ; // in Ohms string partNum ; // Part Number cout << " Enter resistance : " << endl ; cin >> resistance ; switch ( resistance ) { case 3 : partNum = " OD30GJE "; break ; case 10 : partNum = " OD100JE "; break ; case 22 : partNum = " OD220JE "; break ; default : partNum = "No match "; break ; } cout << " Part number : " << partNum << endl ; return 0; } Translate the C code to MIPS assembly

Why do MIPS operations on unsigned numbers give signed results?

﹥>﹥吖頭↗ 提交于 2019-12-30 01:55:12
问题 When I try working on unsigned integers in MIPS, the result of every operation I do remains signed (that is, the integers are all in 2's complement), even though every operation I perform is an unsigned one: addu , multu and so fourth... When I print numbers in the range [2^31, 2^32 - 1] I get their 'overflowed' negative value as if they were signed (I guess they are). Though, when I try something like this: li $v0, 1 li $a0, 2147483648 # or any bigger number syscall the printed number is

Compile time initialized array error

老子叫甜甜 提交于 2019-12-29 09:37:26
问题 I am trying to make an array to which I have provided the data at compile time in MIPS. but I am getting error and thus the code is not getting compiled. Here is the chunk of code which is causing error. .data array: .space 'A','B','C','D','E','F','G','H','I' What is the reason for error? If you know any tutorials which explain arrays of .space , .byte and .word , please mention them in answer. Regards 回答1: You can't use .space directive for initialized arrays. .space is for reserving N

C/C++ to MIPS Assembly

感情迁移 提交于 2019-12-29 08:54:15
问题 I know that to compile to assembly, I should use the -S option with gcc or g++ , but how do I get MIPS assembly? I tried g++ -march=mips2 dll.c but that gives the error dll.c:1:0: error: bad value (mips2) for -march= switch I saw a suggestion of the compile command mips_gcc , but I can't find how to install that compiler. I'm using Ubuntu 64-bit, if that helps. 回答1: You need a version of gcc that is built as a MIPS cross compiler. You can download the free Mentor/Codesourcery MIPS gnu/gcc