mips32

MIPS Char Array Reversal translation from c++

試著忘記壹切 提交于 2019-12-10 11:59:57
问题 My project is to convert the below code, which reverses the order of a string i.e.( string --> gnirts). I have no understanding of how to start the translation into MIPS assembly. Any help or clarification on how to do this project would be greatly appreciated.Even just a similar example would be awesome. #include <iostream> using namespace std; void reverse(char [], int size); void swap(char *x, char *y); int main() { char array[] = "0123456789"; cout << array << endl; reverse(array, 10);

Integer array indexing with MIPS assembly

随声附和 提交于 2019-12-10 11:29:58
问题 I wanted to convert this C code into MIPS. C Code: f = A[B[h-g]] We assume that h > g and B[h-g] > 0 . h , g , f are integers. Also assume that f is assigned to register $s0 , g to $s1 , h to $s2 . Base addresses of A -> $s6 and B -> $s7 Here is my attempt: sub $t0, $s2, $s1 mult $t0, $t0, 4 lw $t0, $t0($s7) mult $t0, $t0, 4 sw $s0, $t0($s6) 回答1: It looks good, apart from the last line, which should most likely be: lw $s0, $t0($s6) Note that you should always comment your code, particularly

MIPS swap function

試著忘記壹切 提交于 2019-12-08 12:18:44
问题 As is obvious from my question history today, I am working on a MIPS project that will reverse a string, in this case "Hello, World". I think I have my loop and string reversal functions correct, but I cannot figure out the swap function itself, or how to output the manipulated string. I know that the basic swap for something like this would be: sll $t1, $a1, 2 add $t1, $a0,$t1 lb $t0,0($t1) lb $t2, 4($t1) sb $t0,0($t1) sb $t2, 4($t1) jr $ra But I have no idea what that does or how I

what does .space do in mips?

佐手、 提交于 2019-12-08 04:53:46
问题 I got this problem for an assignment in which we have put these number in an array and add them without using a loop. I have solved this problem but .space is confusing me. By making .space 20 do i make space for 5 words or is it doing something else. .data array: .space 20 .text addi $s0, $zero, 2 addi $s1, $zero, 12 addi $s2, $zero, -5 addi $s3, $zero, 7 addi $s4, $zero, 4 addi $t0, $zero,0 #index initialized at 0 sw $s0,array($t0) addi $t0, $t0, 4 sw $s1,array($t0) addi $t0, $t0, 4 sw $s2

MIPS: Size of .asciiz?

一笑奈何 提交于 2019-12-07 12:30:54
问题 When determining the size of .asciiz string, should I take into consideration the terminating character ? For example: .data string: .asciiz "Hello" The size of "string" is 5 or 6 (byte) ? Thank you in advance. 回答1: if you are asking about how many bytes in memory the string is stored in then it's 6 bytes if you are asking about what should be returned by a function that count the string length (strlen C function for example) it should be 5 回答2: This particular asciiz string requires 6 bytes

Data memory unit

眉间皱痕 提交于 2019-12-06 13:30:36
I started Verilog a few weeks ago and now I'm implementing MIPS pipelining on an FPGA board and I'm on the MEM part of the pipelining stage. I'm trying to code the Data memory unit (in picture -> Data memory Unit). I don't understand the use of memread. I understand that if memwrite is 1, the contents of the current address is passed to read data. So far, this is my code: module data_memory ( input wire [31:0] addr, // Memory Address input wire [31:0] write_data, // Memory Address Contents input wire memwrite, memread, output reg [31:0] read_data // Output of Memory Address Contents ); reg [31

Multiplication using Logical shifts in MIPS assembly

狂风中的少年 提交于 2019-12-06 11:49:20
Can someone please give me pointers on how I can go about making a code that multiplies using shifts in MIPS assembly? I don't understand how having a number 2^n can help me multiply using an odd multiplicand I currently have this code, I'm trying to make a calculator .text li $v0, 4 la $a0, ask_1 syscall li $v0,5 syscall move $s1, $v0 li $v0, 4 la $a0, ask_2 syscall li $v0,5 syscall move $s2, $v0 #sll $s2, $s2, 3 #$s2 * $s2^3 = result srl $s2, $s2, 1 li $v0, 1 la $a0, ($s2) syscall .data ask_1: .asciiz "Enter Multiplier\n" ask_2: .asciiz "Enter Multiplicand\n" result: .asciiz "The Answer is:

Casting in MIPS

江枫思渺然 提交于 2019-12-06 10:38:26
I've an interesting question! I implemented a memorizing game in MIPS, The game starts by randomly printing a number between 10-99 on the screen, then ask the user to enter the exact number. If the user enters the number correctly, the game continues by displaying the first number and a second randomly generated number between 10-99. and the two numbers have to displayed one after another with a 3 second delay between them. The users is then is asked to enter the numbers in the correct order as they appeared on the screen. If the user enters the two numbers correctly the game continues with

MIPS: Size of .asciiz?

限于喜欢 提交于 2019-12-05 20:53:07
When determining the size of .asciiz string, should I take into consideration the terminating character ? For example: .data string: .asciiz "Hello" The size of "string" is 5 or 6 (byte) ? Thank you in advance. if you are asking about how many bytes in memory the string is stored in then it's 6 bytes if you are asking about what should be returned by a function that count the string length (strlen C function for example) it should be 5 This particular asciiz string requires 6 bytes of storage. In programming situations, you will measure the string size to be 5. As in strlen() . When using this

MIPS assembly for a simple for loop

非 Y 不嫁゛ 提交于 2019-12-04 11:49:04
问题 I need to translate this C code to MIPS assembly. Here is the C code: int tmp = 0; for (int j = 0; j < 15; ++j) tmp = tmp * 2 + 3 This is my MIPS assembly code. Is it a correct translation? If you see any mistakes I would really like to know. # tmp = $v0 # j = $t0 .globl main main: li $v0,0 loop: bgt $t0,15,exit addi $t0,$t0,1 mul $t1,$v0,2 add $v0,$t1, 3 j loop exit: 回答1: Your loop goes from 0 to 14, so your bgt instruction should be: bgt $t0,14,exit I think. . 回答2: You don't set j ($t0) to