mips

Recursion greatest common divisor in MIPS

心已入冬 提交于 2019-12-24 19:32:58
问题 In MIPS, I am trying to calculates the greatest common divisor (GCD) of pairs of positive integer numbers using the Euclidean algorithm. For example, the GCD of 6 and 9 is 3, while the GCD of 10 and 25 is 5. The C code is something like this uint32_t m_w = 50000; uint32_t m_z = 60000; uint32_t hcf(uint32_t n1, uint32_t n2) { if (n2 != 0) return hcf(n2, n1%n2); else return n1; } And I am writing the MIPS program and I am not sure how to use n1 % n2. And this is my first time to do the

Overflow problems with summing squares

倾然丶 夕夏残阳落幕 提交于 2019-12-24 18:22:37
问题 I'm tackling an assignment which asks us to: Write a program in MIPS assembly which, given a memory address in $a0 to the first element of an array of n 32-bit unsigned numbers (n is stored in $a1 ), it should square each one of them and sum the squares. The 32 most significant bits should be returned on $v1 , while the least significant ones on $v0 . Special returns (on v0 ): Zero if the array has no elements (n = 0) DEADBEEF (hex) = 3735928559 (dec) if the result can't fit in 64 bits. What

Convert hex character to decimal equivalent in MIPS

梦想的初衷 提交于 2019-12-24 16:06:48
问题 How do I take a single ASCII character and convert it to its decimal equivelant in MIPs? Do I simply have to have some conditions to subtract a certain amount from the ascii code to make it its decimal representation? 回答1: Here's a simplistic implementation of what Pax wrote (it assumes that hexadecimal digits - A to F are always upper case) File hextodec.c #include <stdio.h> /* *Converts an ASCII char to its decimal equivalent. *Returns -1 on error. * */ extern int hextodec(char* c); int

MIPS multiplication using addition

纵饮孤独 提交于 2019-12-24 15:59:23
问题 sorry, I try to multiply two integers but it doesn't work. I can't find where the problem is.Maybe because of register' names but I don't know how to correct it. I correct many times but it is not successful. Could anyone give me some points? .data prompt1: .asciiz "Please enter the first signed (decimal) integer: " prompt2: .asciiz "Please enter the second signed (decimal) integer: " result_msg: .asciiz "The result of these two 16-bit integers\' multiplication is: " .text .globl main main:

Assembly language - third element points to

这一生的挚爱 提交于 2019-12-24 14:33:56
问题 would really appreciate if someone can tell me what the third element in the strong list reads. This is NOT HW, I am merely preparing myself. Thank you. 回答1: Our StringList is a linked list. The 1st pointer goes to the string value of the current element, the 2nd pointer goes to the next node. The head of the list is at location 0x000010000 : at 0x00001000 : value = ..., next = 0x00003000 (the head element) at 0x00003000 : value = ..., next = 0x00000010 at 0x00000010 : value = 0x4024FFA4,

Stuck on a MIPS recursive function

夙愿已清 提交于 2019-12-24 11:35:11
问题 I'm doing an assignment in MIPS and I feel like my logic is sound but I just can't get the code to produce the correct output. Can anyone look over what I've got and help? This is the corresponding function in C that I'm trying to implement. int function1(int n) { if (n <= 3) { int ans1 = (3*n)-5; return ans1; } else { int ans1 = (n-1)*function1(n-1) + function1(n-2) - n; return ans1; } } This is what I've got in MIPS. For the sample output, when the user enters 8 the output is supposed to be

Convert decimal to base 4 assembly (MIPS)

这一生的挚爱 提交于 2019-12-24 10:15:04
问题 How to convert integers in an array that are in decimal to base 4 (signed and unsigned)? 回答1: You can use the algorithm of dividing the number by the desired base repeatedly until the quotient is zero, using the remainders as the final result in reverse order, example : QUOTIENTS OF EACH DIVISION ▼ ▼ ▼ 23÷4 = 5÷4 = 1÷4 = 0 3 1 1 ▲ ▲ ▲ REMAINDERS OF EACH DIVISION The remainders are the digits in the new base (in reverse order) : "113". Your code will require two blocks : One block to make the

using multiple mips arguments >4

空扰寡人 提交于 2019-12-24 09:25:10
问题 Im trying to program a function to use extra arguments besides 4 (since my version of mips only supports $a0-$a3) by pushing them on the stack, but my code is incorrect. Here is my code in main (snippet): li $t0,40 #temp value for our 5th arg. addi $sp, $sp, -4 #decrement stack pointer by 4 sw $t0, 0($sp) #save the value of $t0 on the stack. jal printf which sets a temporary value of 40, gives space on the stack, and saves it. My function is then called. As a test to see if this worked,

Why does the lw instruction's second argument take in both an offset and regSource?

做~自己de王妃 提交于 2019-12-24 08:49:36
问题 So the lw instruction is in the following format: lw RegDest, Offset(RegSource) . Why does the second argument take in both an offset and register source? Why not only one (i.e. only register source)? 回答1: Because what else are you going to do with the rest of the 32-bit instruction word? (Assuming you're the CPU architect designing the MIPS instruction set). Leaving out the 16-bit immediate displacement can't make the instruction shorter, because MIPS is a RISC with fixed-length instruction

MIPS Is it elegant to use $s0… etc reginsters inside the procedure and restore it on end

爷,独闯天下 提交于 2019-12-24 05:08:08
问题 I read in MIPS tutorial, that only reginsters $s0-$s7 are preserved across procedure calls. But I think (maby I am wrong?) that it is not elegant to create procedures that have side effects - I think procedures should change only $v0, $v1 reginsters and stack if it is needed (am I right?). So in my opinion inside my procedure I can use only $t0-$t9 reginsters. But when I call some prodedures in my procedure it can change $t0-$t9 reginsters. So I have to store temporary reginsters and restore