mips

When reading file in MIPS, it reads last line twice

给你一囗甜甜゛ 提交于 2020-01-11 12:19:08
问题 I was able to (partly) successfully read in a file in MIPs. Below is my current code. In QtSpim, when I run it, I get a pointer to the file in $a1, but the last few characters of the file are repeated twice. The number of characters that is repeated changes depending on the file. From what I've seen, it seems to be linked to the number of new-line characters in the file unless the new-line chars are at the very end of the file (meaning, if there were 5 new-line characters, the last 5

absolute value in MIPS

假装没事ソ 提交于 2020-01-11 04:45:44
问题 Do you have any simple ways to make a value in a register in MIPS as an absolute value? 回答1: Here is a pretty simple way to do it. #assume you want the absolute value of r1 ori $2, $zero, $1 #copy r1 into r2 slt $3, $1, $zero #is value < 0 ? beq $3, $zero, foobar #if r1 is positive, skip next inst sub $2, $zero, $1 #r2 = 0 - r1 foobar: #r2 now contains the absolute value of r1 回答2: Here's a branch-less variant: # input and output in $t0 sra $t1,$t0,31 xor $t0,$t0,$t1 sub $t0,$t0,$t1 How does

Jump instruction in MIPS Assembly

两盒软妹~` 提交于 2020-01-10 02:55:20
问题 Here is some MIPS assembly code I wrote to test the jump instruction: addi $a0, $0, 1 j next next: j skip1 add $a0, $a0, $a0 skip1: j skip2: add $a0, $a0, $a0 add $a0, $a0, $a0 skip2: j skip3 loop: add $a0, $a0, $a0 add $a0, $a0, $a0 add $a0, $a0, $a0 skip3: j loop When I run the assembler, here's the result: [0x000000] 0x20040001 # addi $a0, $zero, 1 ($a0 = 1) [0x000004] 0x08000002 # j 0x0002 (jump to addr 0x0008) [0x000008] 0x08000004 # j 0x0004 (jump to addr 0x0010) [0x00000C] 0x00842020 #

MIPS Assembly wrong digit

限于喜欢 提交于 2020-01-06 08:07:08
问题 la $a0, number li $t3, 0 #Iterator = 0 li $v1, 0 #Sum = 0 while: add $t1, $a0, $t3 #t1 = &A[i] lb $t1, 0($t1) # A[i] beq $t1, $zero, endwhile add $v1, $v1, $t1 # Sum addi $t3, $t3, 1 # Iterator + 1 subi $v1, $v1, 48 # ???? Every digit is added with 48, so i have to subtract but why ??? j while endwhile: li $v0, 1 #Print the sum move $a0, $v1 syscall Can someone pls help me. Why do i have to subtract every digit with 48 to get the right result? I dont know why its keep adding every time 48 to

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

Understanding how `lw` and `sw` actually work in a MIPS program

十年热恋 提交于 2020-01-06 07:54:36
问题 I'm having bit of a difficulty understanding what sw and lw do in a MIPS program. My understanding of the topic is that we use lw to transfer data from the memory into the register and vice-versa for sw . But how is this exactly accomplished? Let's say we have the following line of code: lw Reg.Dest, Offset(Reg.Source) sw Reg.Source, Offset(Reg.Dest) If we concentrate on lw it's essentially storing the data from the memory, Reg.Source and multiplying the address of that data with the Offset ,

Understanding how `lw` and `sw` actually work in a MIPS program

我只是一个虾纸丫 提交于 2020-01-06 07:54:08
问题 I'm having bit of a difficulty understanding what sw and lw do in a MIPS program. My understanding of the topic is that we use lw to transfer data from the memory into the register and vice-versa for sw . But how is this exactly accomplished? Let's say we have the following line of code: lw Reg.Dest, Offset(Reg.Source) sw Reg.Source, Offset(Reg.Dest) If we concentrate on lw it's essentially storing the data from the memory, Reg.Source and multiplying the address of that data with the Offset ,

Error #5: Unaligned word memory reference

烈酒焚心 提交于 2020-01-06 05:30:11
问题 I am attempting to build an array of integers to represent edges (index of source | index of destination | weight) in an implementation of Dijkstra’s Algorithm using MIPS. On running with rsim, I am getting an “unaligned word memory reference” error. I think I may be misunderstanding what memory alignment refers to. My .data is below .data .align 4 enterNode: .asciiz "Enter the number of nodes: " enterEdges: .asciiz "Enter the number of edges: " enterSource: .asciiz "Enter source: "

MIPS pipeline stalls with and without forwarding

ε祈祈猫儿з 提交于 2020-01-06 04:06:09
问题 In the following sequence of MIPS instructions (entire program not shown): DADDUI R1, R1, #-8 BNE R1, R2, Loop I want to confirm the number of stalls required between the two instructions (in context of 5 stage MIPS pipeline - IF, ID/Reg, EX, MEM, WB) with and without forwarding. My understanding: (a) If there is no forwarding: In this case, 2 stalls are required (in cycle 5, R1 can be read in the ID stage for second instruction using split phase access for registers) (b) If there is

Jump and Link Register MIPS

微笑、不失礼 提交于 2020-01-06 02:18:18
问题 I am studying MIPS instructions and this problem is confusing me a bit because the MIPS documentation seems to be saying something different from the answer provided. Here is the problem and answer: What registers are referred to and/or changed in this instruction at location 0x5000 ? 0x5000 : 0x0140F809 answer: Opcode= 0x00 , R type, Function=0x09 ( jalr ), Rs=10( $t2 ) jumps to address in $t2 puts 0x5004 in $ra However, from the documentation, it says that in register 31 ( $ra ), it puts