mips32

Writing MIPS machine instructions and executing them from C

空扰寡人 提交于 2019-12-24 04:40:35
问题 I'm trying to write some self modifying code in C and MIPS. Since I want to modify the code later on, I'm trying to write actual machine instructions (as opposed to inline assembly) and am trying to execute those instructions. Someone told me that it would be possible to just malloc some memory, write the instructions there, point a C function pointer to it and then jump to it. (I include the example below) I've tried this with my cross compiler (sourcery codebench toolchain) and it doesn't

checking If a number is greater then or Less then using slt and branching using mars

偶尔善良 提交于 2019-12-23 05:23:25
问题 So this is what i have so far I am not sure where to go from here to branch off or just print out the answer. I tried to print out the message but to no avail. Is there a way to use both slt and branching? .data message1: .asciiz "The number is less than. :" message2: .asciiz "/nThe number is greater than. :" .text main: addi $t0, $zero, 20 addi $t1, $zero, 5 slt $s0, $t0, $t1 beq $s0, $zero, printmessage1 sge $s0, $t0, $t1 beq $s0, $zero, printmessage2 li $v0, 10 syscall printmessage1: li

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

Sum of Squares in Mips Assembly

本小妞迷上赌 提交于 2019-12-13 05:21:31
问题 I have to calculate the sum of squares of an array in Mips assembly. I was looking for feedback for my code. The code posted below is just a start and doesn't take into account possible overflow situations. However, I just want to make sure, this basic block of code works as expected # Function to calculate squared sum # # Inputs: # $a0: address of array in memory (*a) # $a1: array size (n) # # Outputs: # $v0: low 32 bytes of result # $v1: high 32 bytes of result # # If the array is empty,

Recursive product mips

走远了吗. 提交于 2019-12-11 15:03:12
问题 I made some changes to the code, but it is still printing a 9digit number. Not sure what's going on here. When I type in 2 * 3, it outputs 268501017. Im having a hard time find out how to get the result from the register and print it. main: #prompt 1 li $v0, 4 # Print the String at Label “Input” la $a0, num1 syscall li $v0, 5 syscall move $a2, $v0 #prompt 2 li $v0, 4 # Print the String at Label “Input” la $a0, num2 syscall li $v0, 5 # Read integer from user syscall move $a1, $v0 # Pass

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

kernel module in not loaded (but insmod returns 0)

空扰寡人 提交于 2019-12-11 02:57:57
问题 I've to add some functionality to an existing device (mips arch) - I've tryed several SDK's and at this moment I have some progress, but: insmod returns 0(success) and lsmod shows them, but aither printk nor create_proc_entry doesn't work .... BUT I've viewed section .gnu.linkonce.this_module: except module name - there is no usefull info - section is filled with 0x0's I've found that in native .ko files in device size of section .gnu.linkonce.this_module is smaller into 8 bytes - but

MIPS Assembly Alignment Align n

此生再无相见时 提交于 2019-12-11 02:32:42
问题 What does the directive .align n do in an array? To be more specific let's say that I have the following part of code: array: .align 2 .space 800 What's its importance and why not just skip it and use .space 800 This is a school's assignment theory question. 回答1: Taken directly from MARS helping tooltips: Align next data item on specified byte boundary (0=byte, 1=halfword, 2=word, 3=double) Consider this code la $t0, array .data .space 3 array: .space 12 This is assembled into lui $at, 0x1001

Does -fomit-frame-pointer *always* omit the fp?

社会主义新天地 提交于 2019-12-11 00:47:50
问题 Does -fomit-frame-pointer always omit the frame pointer? Is there ever a situation where both the pc and fp need to be setup? Does dynamic stack growth force the fp to be setup? Asking specifically for MIPS32. Thanks! 回答1: The frame pointer is not really needed for correct execution, except sometimes for exception unwind. Dynamic stack growth usually requires some kind of a frame pointer, but it is not tied to a particular register, but rather allocated through normal data flow analysis.

Getting result from mult in mips

心不动则不痛 提交于 2019-12-10 19:23:21
问题 I am new to assembly language, and I am really confused over multiplying. I was reading the quick tutorial here:http://logos.cs.uic.edu/366/notes/mips%20quick%20tutorial.htm It says after I use mult $t0, $t1 the results are stored in Hi and Lo, I understand these are special registers for mult and div , but how do I access them? Lets say I do mult $t0, $t1 where $t0 and $t1 are both 2. How do I get the result? (4) 回答1: You have to use MFHI and MFLO to move data from HI and LO to general