mips

Service Calls Executing Based on User Input

折月煮酒 提交于 2019-12-25 04:26:32
问题 I've just written my first MIPS addition program. My output is expected ($t0 + $t1 = $t2), but I have a question regarding some strange behavior that I believe should be avoidable. On the lines where I gather the user input ( li $v0, 5 ), the value of the $v0 service call gets set to the value of my user input. So for example, if I enter "10" as user input, $v0 is assigned the value 10, which is the service code to terminate the program. Is there something I can do to ensure that my user

Assembly MIPS: Checking if a string is palindromic or not

孤街浪徒 提交于 2019-12-25 04:09:30
问题 Palindromic is a string that can be read both ways. like "radar", "wow" etc. From C we know that we can check a given string with a "for" loop and an "if" expression: for(i=0; i<length; i++) if(str[i] == str[length-i-1]) printf("Palindromic"); else print("Non Palindromic"); so that way we can reach to the center of the string by both sides. This code requires that we have counted the characters to know the length of the string. On MIPS, this "for" loop seems quite complex. Here's where I got

Push Each Character of a String Into a Stack MIPS

拥有回忆 提交于 2019-12-25 01:56:04
问题 So I'm working on a project in MIPS to check if a string input by the user is a palindrome or not. The part I'm stuck on is reading the string and pushing each character of the string into the stack one by one (the PushLoop part of the code). When I debug it, the program seems to think I haven't entered anything at all. Here's what I have so far: .text main: li $v0, 4 # Prints str1 la $a0, str1 syscall jal Init # Sets $s0 equal to $sp to compare if the stack is empty later li $v0, 8 # Read

MIPS program is finished running (dropped off bottom) error

家住魔仙堡 提交于 2019-12-25 01:54:12
问题 It's my first time doing MIPS assembly and I'm trying to create a program that (1) accepts user's input (2) pre-store it in a specific address (3) multiply using repeated addition Here's my program: #Data Segment# .data 0x10010000 x: .word 1988 y: .word 1923 .text #Main Segment main: sub $t3, $t3, $t3 #initialize counter sub $t4, $t4, $t4 #initialize product multiloop: lui $t0, 0x1001 lw $t1, 0($t0) #load first integer value; variable for addition lw $t2, 4($t0) #load second integer value;

How do you print an array of strings in MIPS?

半腔热情 提交于 2019-12-25 01:44:22
问题 I'm having an array of strings and I want to print them out. Here's currently what I have: data: .asciiz "foo", "bar", "hello", "elephant"...(16 of these strings) size: .word 16 move $s0, $zero # i = 0 la $s1, data # load array la $s2, size #load size print_array: bge $s0, $s2, exit # i >= size -> exit la $a0, 0($s1) #load the string into a0 li $v0, 4 #print string syscall addi $s0, $s0, 1 # i++ addi $s1, $s1, 4 j print_array exit: jr $ra I know this won't work because li $v0, 4 is for

How to multiply two numbers in MIPS which gives product that is larger than 32bits?

只谈情不闲聊 提交于 2019-12-25 01:34:16
问题 Actually, my task is to multiply two 32bits number in MIPS which then generate the output of 64bits. Least significant 32bits are to be saved in 'lo' register and the remaining in 'hi' register to my understanding. When I multiply 100000 and 200000 I get a817c800 in 'lo' register and 4 in 'hi' register mult $t1, $t2 mflo $s0 mfhi $s1 回答1: When I multiply 100000 and 200000 I get a817c800 in 'lo' register and 4 in 'hi' register Correct. Because the result is 64 bits wide and you are using a 32

Trying to write a program that prints prime numbers in MIPS Assembly language

三世轮回 提交于 2019-12-25 00:27:13
问题 This program needs to take user input and print out that quantity of prime numbers, so if the user in puts "5" it will output "2,3,5,7,11" I'm trying to do it like so: boolean isPrime(int n) { for(int i=2;i<n;i++) { if(n%i==0) return false; } return true; } This is my assembly code. Right now it appears to never leave the test_prime procedure. .globl main .text main: li $v0, 4 # print welcome message la $a0, welcome syscall la $a0, prompt # prompt for user input syscall #receive input li $v0,

Compare the last binary digit to 1 in MIPS assembly

五迷三道 提交于 2019-12-25 00:17:59
问题 I have to check if a number is even or odd. My strategy: a number is even if ends with 0 a number is odd if ends with 1 How do I compare the last digit of a register value to a 0 or to a 1 ? I tried: andi $t7, $t0, 0 # where $t0 = 3 in decimal so should be 0b11 it doesnt work :( Any hint? 来源: https://stackoverflow.com/questions/13772552/compare-the-last-binary-digit-to-1-in-mips-assembly

MIPS jump instruction delay slot

一曲冷凌霜 提交于 2019-12-24 20:27:01
问题 I found in the net something about jump instruction (j, jr, jal): Always use a delay slot (A noop on the next offset) when using Jump commands Is it correct? I can't understand why should i use noop after jump. Source 来源: https://stackoverflow.com/questions/47423368/mips-jump-instruction-delay-slot

What is wrong with MIPS Fibonacci Recursion?

£可爱£侵袭症+ 提交于 2019-12-24 20:16:11
问题 I am working in converting a fibonacci function written in C to MIPS. My MIPS code is currently not working and I can not identify the issue. I am new to assembly and I hope you can help me identifying the main problem in my MIPS code. Look at my function fibonacci under my MIPS code. When I compile my MIPS code I get the following error : "Can't expand stack segment by 24 bytes to 5242888 bytes. I have a C code as following: int fib(int n) { if (n == 0) { return 0; } else if (n == 1) {