mars-simulator

Reading and printing an integer in mips

时光怂恿深爱的人放手 提交于 2020-07-14 22:36:22
问题 My program is suppose to read an integer and print it back to the user but every time it just prints 268501230 no matter what is entered. Any help would be appreciated. .data prompt2: .asciiz "Please enter value: " array1: .space 40 array2: .space 40 buffer: .space 4 .text main: #Prints the prompt2 string li $v0, 4 la $a0, prompt2 syscall #reads one integer from user and saves in t0 li $v0, 5 la $t0, buffer syscall li $v0, 1 li $t0, 5 # $integer to print syscall exitProgram: li $v0, 10 #

Reading and printing an integer in mips

坚强是说给别人听的谎言 提交于 2020-07-14 22:29:09
问题 My program is suppose to read an integer and print it back to the user but every time it just prints 268501230 no matter what is entered. Any help would be appreciated. .data prompt2: .asciiz "Please enter value: " array1: .space 40 array2: .space 40 buffer: .space 4 .text main: #Prints the prompt2 string li $v0, 4 la $a0, prompt2 syscall #reads one integer from user and saves in t0 li $v0, 5 la $t0, buffer syscall li $v0, 1 li $t0, 5 # $integer to print syscall exitProgram: li $v0, 10 #

Recursion in MIPS with arrays

邮差的信 提交于 2020-06-02 05:37:08
问题 I'm a beginner user of MARS for programming in MIPS language. I started to study the recursion and I wrote a little method in java that take in input an array and an index, and make a recursive sum of all its elements. But I don't know how to write it in mips language, someone can help me? public int recursiveSum(int i, int[] array) { if(i == array.length-1) return array[i]; return array[i]+recursiveSum(i+1, array); } 回答1: When you create a recursive function in mips , you need to save the

Recursion in MIPS with arrays

♀尐吖头ヾ 提交于 2020-06-02 05:36:50
问题 I'm a beginner user of MARS for programming in MIPS language. I started to study the recursion and I wrote a little method in java that take in input an array and an index, and make a recursive sum of all its elements. But I don't know how to write it in mips language, someone can help me? public int recursiveSum(int i, int[] array) { if(i == array.length-1) return array[i]; return array[i]+recursiveSum(i+1, array); } 回答1: When you create a recursive function in mips , you need to save the

Recursion in MIPS with arrays

左心房为你撑大大i 提交于 2020-06-02 05:36:10
问题 I'm a beginner user of MARS for programming in MIPS language. I started to study the recursion and I wrote a little method in java that take in input an array and an index, and make a recursive sum of all its elements. But I don't know how to write it in mips language, someone can help me? public int recursiveSum(int i, int[] array) { if(i == array.length-1) return array[i]; return array[i]+recursiveSum(i+1, array); } 回答1: When you create a recursive function in mips , you need to save the

How do I calculate clock cycles on mips assembly programming?

ぐ巨炮叔叔 提交于 2020-01-06 08:03:57
问题 I've searched up everywhere, and ive gathered pipelines or something. I've checked other programs and it seems like theres a single-cycle & multicycle: Clock cycles of Single-cycle and multi-cycle MIPS How do I tell the difference for what cycle. like for example, how many clock cycles would this be: li $a0, 0 # $a0 = 0 li $t0, 10 # Initialize loop counter to 10 Loop: add $a0, $a0, $t0 addi $t0, $t0, -1 # Decrement loop counter bgt $t0, $zero, Loop # If ($t0 > 0) Branch to loop My professor

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;

MIPS “la” pseudo instruciton

岁酱吖の 提交于 2019-12-23 08:54:35
问题 In MIPS, the la instruction translates into lui and ori . However, MARS Simulator does not seem to do that at all. When I dump the following machine code: .text la $a0, array la $a1, array_size lw $a1, 0($a1) .data array: .word 0:10 array_size: .word 10 message: .asciiz "The sum of numbers in array is: " I get: 00100000000001000010000000000000 00100000000001010010000000101000 10001100101001010000000000000000 Which is obviously. It is dumping la as one instruction. What does MARS do? How can I

Integer Arrays in MIPS : Setting array[index] to iteration value i?

我的未来我决定 提交于 2019-12-23 04:37:39
问题 I'm working on translating the below C++ code to MIPS (this is just a small portion of the program that I'm stuck on), and I understand the gist of how to set $t registers to take the array values given, but I'm completely stuck on pos[count] = i; I've tried sw , lw , but everytime I try these, I get address out of range exceptions/etc. Can someone explain to me what's going wrong here? When the loop gets to pos[count] = i , I need to change pos[count] from 0xffffffff to (i) for each loop

Reading files with MIPS assembly

拜拜、爱过 提交于 2019-12-22 08:38:03
问题 I'm trying to write a program that reads in characters from a .dat file that correspond to different colors to be displayed in the LED simulator; x = off, R = red, etc. My problem is, I cannot figure out what I'm doing wrong with opening the .dat file. I've looked around and tried all I can think of, but each time I assemble and run, I get a -1 in $v0 signifying an error. Here's my code for opening/reading/closing the file: .data fin: .asciiz "maze1.dat" # filename for input buffer: .asciiz "