mars-simulator

How to change the assembly code %hi and %lo to run in 'MARS'?

自闭症网瘾萝莉.ら 提交于 2019-12-20 07:30:32
问题 I used 'compiler explorer' to convert c++ to MIPS but it doesn't work well in the MARS because of %hi and %lo I know I should change the part, but I don't know how to change... Please help $L5: lui $2,%hi($LC1) lwc1 $f0,%lo($LC1+4)($2) lwc1 $f1,%lo($LC1)($2) b $L3 $LC1: .word 1100470148 .word 0 $L17: lw $2,16($fp) addiu $3,$2,1 sw $3,16($fp) lui $4,%hi(savepath) sll $3,$2,2 addiu $2,$4,%lo(savepath) addu $2,$3,$2 li $3,1 # 0x1 sw $3,0($2) move $sp,$fp lw $fp,36($sp) addiu $sp,$sp,40 j $31 回答1

String to int conversion and String manipulation MIPS

有些话、适合烂在心里 提交于 2019-12-20 06:20:03
问题 For my homework I need to use MIPS to take an input with an arbitrary letter at the front followed by numbers(e.g. x123) and add 5 to the number then print out the final number (from the example the output would be 128) 回答1: .data entmsg: .asciiz "Enter a string:\n" ui1: .space 20 counter: .space 20 outmsg: .asciiz "The value +5 is:\n" .text main: #Printing the message li $v0, 4 la $a0, entmsg syscall #Saving the text li $v0, 8 la $a0, ui1 li $a1, 20 syscall #Count the length of the string la

setting input variables

做~自己de王妃 提交于 2019-12-13 18:05:30
问题 Question asks: Write a piece of MIPS code that, given values in $s0 and $s1, put into the $t* registers the following: $t0 = $s0 $t1 = $s1 $t2 = $t0 + $t1 $t3 = $t1 + $t2 ... $t7 = $t5 + $t6 In other words, for each register from $t2 to $t7, it stores the sum of the previous two $t* register values. The $s0 and $s1 registers contain the initial values. Don't set the value of $s0 and $s1 in your code. Instead, learn how to set it manually with MARS. Save your code into sum.s. ok that's not

Show division result in MIPS

眉间皱痕 提交于 2019-12-11 23:20:10
问题 Merged with Use the floating point instructions to get results in decimal. Hi I'm coding a small program in MIPS and I have this code li $v0, 2 div $t0,$t2,$t1 move $a0,$t0 syscall (it's not the full code, just the section handling division) Where $t1 is 2, $t2 is 9. So, 2/9 is 0.2222222222222222 But when I run it I only get 0.0 Why?, how I show the true result? Thanks in advance. 来源: https://stackoverflow.com/questions/6513610/show-division-result-in-mips

Using a random number generator in MIPS?

不羁的心 提交于 2019-12-11 19:46:53
问题 So I was reading a few threads on this site and I found one on how to make one.. But I can't really find a link that explains more about how to code it.. My textbook for the course didn't provide any information about RNG at all so no help there. The code was li $a1, 4 li $v0, 42 add $a0, $a0, 1 is this correct for asking for a range between 1-3? I tried outputting what random number it was but it gave me the same number constantly. #sw $a0, 0($s0) li $a1, 4 li $v0, 42 add $a0, $a0, 1

Generating random numbers using a syscall

╄→尐↘猪︶ㄣ 提交于 2019-12-11 15:35:38
问题 I'm trying to generate a random integer from 0-99 (inclusive) but I'm having some difficulty finding where it stores the value to when using the 42 syscall. So far I have: li $a1, 100 li $v0, 42 syscall I'm not sure where the value generated is stored so I can use it though. 回答1: From a syscall help page: $a0 is the pseudorandom number generator id, $a1 is the upper bound, and the returned random number will also be contained in $a0 . 来源: https://stackoverflow.com/questions/8394537/generating

How to create a file using user input with assembly

*爱你&永不变心* 提交于 2019-12-11 13:25:12
问题 I'm trying to record in a file an user input, using assembly. I'm working with this code but when the file is created, the input isn't recorded on the file correctly. Someone can help me with this? Here is my code: .data file1: .asciiz "file1.txt" prompt: .asciiz "User entry\n" buffer: .space 45 .text la $a0,prompt li $v0,4 syscall li $v0, 8 li $a1, 454 syscall move $s1, $v0 j writeFile1 writeFile1: li $v0, 13 la $a0, file1 li $a1, 1 li $a2, 0 syscall move $s6, $v0 #write li $v0, 15 move $a0,

How to print to the screen from MIPS assembly

☆樱花仙子☆ 提交于 2019-12-11 07:28:40
问题 .text emitchar: lui $t0,0xffff polling: lw $t1,8($t0) andi $t1,$t1,0x0001 beq $t1,$zero,polling sw $a0,0xc($t0) .data I was told this is how to do it but when I run the simulator with the display and keyboard add in I still get not output on the screen. What am I doing wrong? 回答1: Did you click "Connect to MIPS" in the Keyboard window after starting your code? From the Help button: IMPORTANT NOTE: The Transmitter Controller Ready bit is set to its initial value of 1 only when you click the

MIPS Assembly, lui 0x1001

时光毁灭记忆、已成空白 提交于 2019-12-11 05:52:24
问题 I have an assignment in which I have to explain some things about the following MIPS Assembly code: .data x: .word 4711 y: .word 10 z: .word 0x0A91 e: .word 0 .text .globl main main: lw $2, x lw $3, y lw $4, z add $2, $2, $3 sub $3, $2, $4 sw $3, e li $2, 10 syscall The first instruction lw $2, x is separated into two instructions when assembled. The instructions are lui $1, 0x00001001 followed by lw $2, 0x00000000($1) . I understand that lui moves the hex value 1001 into the upper part of

Reading files with MIPS assembly

…衆ロ難τιáo~ 提交于 2019-12-05 15:49:36
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 "" .text #open a file for writing li $v0, 13 # system call for open file la $a0, fin # board file name