mips

MIPS - getting array values

房东的猫 提交于 2019-12-22 12:29:31
问题 Ok, so I have an array stored in memory and I want to essentially create a variable "i" and get the array value at index i. How do I do this in MIPS? Thanks in advance! Here is my code. .data array: .word 0:100 .text li $t0, 5 #this is my representation of "i" la $t2, array lw $t1, i($t2) #this is where i am messed up. 回答1: You should add the base and index together, and remember to scale by 4 for the word size. Something like this: li $t0, 5 # this is my representation of "i" la $t2, array

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 "

Storing values in HI and LO registers of MIPS

久未见 提交于 2019-12-22 08:08:02
问题 I am writing certain code in MIPS and I've come to the point where the requirement is to store the result, temporarily, in HI and LO special registers (both are 4 bytes wide). These instructions are at my disposal: divu s,t lo <-- s div t ; hi <-- s mod t multu s,t hi / lo < -- s * t ; So, divu stores result of division in LO and remainder in HI , while multu stores result of multiplication in LO (lower 4 bytes) and HI (higher 4 bytes). Later, to retrieve result from HI and LO registers, I

MIPS: Calculating BEQ into Hexadecimal Machine Code

戏子无情 提交于 2019-12-22 07:57:13
问题 I have an assignment where I have to convert MIPS instructions into its hexadecimal machine code. I know how to convert the add, addi, lw, etc. instructions just fine, but when it gets to instructions like beq, I get confused. How would I convert this beq to hex? 0x00400108 beq $t3, $t5, NEXT 0x0040010C j END where the address of NEXT is 0x0040011C ? What I've tried: beq opcode = 4 $t3 = register 11 $t5 = register 13 NEXT = 0x0040011C - 0x0040010C = 10 (hex) = 16 (decimal) 4 11 13 16 (decimal

MIPS labels storage location

痞子三分冷 提交于 2019-12-22 01:32:34
问题 In MIPS, while using a jump instruction, we use a label. again: nop $j again So when we reach the jump instruction, we use the label again to show where to go and the value of the actual address there is used. I wanted to know where the label again is stored. Meaning, say nop is stored at 0x00400000, and the jump instruction is at 0x00400004. Where, then is again kept, how does MIPS know again is pointing to 0x00400000? Is it stored in the Dynamic Data area of the memory map? This is the

How to convert a three address code to MIPS Assembly language?

我的梦境 提交于 2019-12-22 00:26:30
问题 I am doing a project in which I have to create a translator that would generate a MIPS assembly code for a C code. The programming language that am using is C++ and I have done till generation of three address code and am really confused about how to proceed further. 回答1: As already stated, it's a direct translation. There's really nothing to clarify. As an example, take the following three-address code: i := 0 ; assignment L1: if i >= 10 goto L2 ; conditional jump t0 := i*i t1 := &b ;

Need help in adding more functionality to MIPS Single Cycle Datapath

两盒软妹~` 提交于 2019-12-21 06:17:49
问题 I am trying to add jal functionality to the following but I am stuck with how does it work. I know that it stores the old PC+4 value in the $ra register and then transfers the control to the function which transfers back the control by return $ra but how do I implement it in the hardware? 回答1: There are two things you need to do. Add a mux at the input of the Registers so that the PC+4 value can be selected as the data to be written. With the appropriate control signal this will allow you to

What does func means in R-Format instruction set?

孤街醉人 提交于 2019-12-21 04:21:22
问题 I am very new to Assembly language . I was reading about MIPS architecture and I am stuck with the last field of the Register Format (R-Format) . Here is its visual representation, Can anyone please help me out with what does the sixth field means and how do we calculate it? Thanks in advance. 回答1: As the description mentions all R-type instructions (e.g. ADD , AND , SLL and others) have the 6 most significant bits (= op) set to 0, that means the only way to distinguish between them is to

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

Translating a mips pseudo instruction 'rol'

删除回忆录丶 提交于 2019-12-20 07:19:13
问题 I'm trying to translate the mips pseudo instruction rol (rotate left). I need to translate it before I can submit an assignment, which is unfortunate because the pseudo instruction worked quite well for me. The instruction was, rol $s4,$s4, 1 #goes to the left most bit (which as it says, gets the left most bit) the way I translated it was, lui $s4, 0x8001 ori $t0, $s4, 0x0004 srl $s4, $t0, 31 sll $s5, $t0, 1 or $s5, $s5, $s3 but it completely messes up my code, can someone please help me