mips

MIPS Basic For Loop

Deadly 提交于 2020-05-17 07:04:49
问题 im trying to implement this java code into MIPS assembly language and i am quite confused. this is what i have so far: java code: for (int c = 1; c <= rows; c++) { number = highestValue; // reset number to the highest value from previous line for (i = 0; i < c; i++) { System.out.print(++number + " "); } highestValue = number; // setting the highest value in line assembly code: .text # tells the program where the code begins move $t0, $zero # t0=0 move $t1, $zero # this will be similar to "int

MIPS Basic For Loop

笑着哭i 提交于 2020-05-17 07:04:07
问题 im trying to implement this java code into MIPS assembly language and i am quite confused. this is what i have so far: java code: for (int c = 1; c <= rows; c++) { number = highestValue; // reset number to the highest value from previous line for (i = 0; i < c; i++) { System.out.print(++number + " "); } highestValue = number; // setting the highest value in line assembly code: .text # tells the program where the code begins move $t0, $zero # t0=0 move $t1, $zero # this will be similar to "int

andi vs. addi instruction in MIPS with negative immediate constant

荒凉一梦 提交于 2020-05-16 06:05:28
问题 Assume $t2= 0x55555550 , then executing the following instruction: andi $t2, $t2, -1 $t2 becomes 0x0005550 This is confirmed by the MIPS emulator 1 However, it is not what I expected. I think the answer should be 0x55555550 & 0xFFFFFFFF = 0x55555550. I think the constant -1 was sign extended to 0xFFFFFFFF before the and logic. But it appears that the answer was 0x55555550 & 0x0000FFFF Why -1 is sign extended to 0x0000FFFF instead of 0xFFFFFFFF Footnote 1: Editor's note: MARS with "extended

What is the function of parentheses in MIPS?

旧城冷巷雨未停 提交于 2020-05-16 04:35:32
问题 I've been working through a project book as an introduction to MIPS and I've come across a problem. One of the lines of code in the book is lb $t3, ($t2) . I have no clue what the parentheses do because prior to this, I haven't seen them used, and the book just doesn't mention them to begin with. Why wouldn't the code just be lb $t3, $t2 ? 回答1: MIPS addressing-mode syntax is constant($reg) . ($t2) is allowed as a special case short-hand for 0($t2) . The same instruction could do lb $t3, 13(

MIPS: Translating C code to MIPS problem in function calls and returns

落花浮王杯 提交于 2020-05-15 20:58:10
问题 I need to change C code from below to a MIPS code but I am new to MIPS and stuck with it. Here is the C code: int main() { int a, b, result; if(a == b) result = a*b; else result = assess(a, b); return result; } int assess(int a, int b) { if(b<a) return upgrade(a, b); else return demote(a, b); } int upgrade(int a, int b) { return 4*(a+b); } int demote(int a, int b) { return 4*(b-a); } Here is MIPS code that I wrote, which isn't working (I am aware there are major errors and wrongs). Because I

How to extract values in bits from a register and use them to replace bits in a different register? (MIPs assembly language)

拜拜、爱过 提交于 2020-05-09 17:21:47
问题 I need to extract the value in bits 22 down to 4 from register $t0, compute the half of this value (assumed unsigned integer), and use the new value to replace bits 24 down to 6 in register $t1 without changing the others bits in $t1. The value isn't given but I don't think that should be an issue. There are 32 bits per register I'm a bit new to MIPs so I'm not sure how to go about solving this problem 回答1: I've broken down the invidual steps of the algorithm. I then created a C prototype

How to extract values in bits from a register and use them to replace bits in a different register? (MIPs assembly language)

大兔子大兔子 提交于 2020-05-09 17:21:45
问题 I need to extract the value in bits 22 down to 4 from register $t0, compute the half of this value (assumed unsigned integer), and use the new value to replace bits 24 down to 6 in register $t1 without changing the others bits in $t1. The value isn't given but I don't think that should be an issue. There are 32 bits per register I'm a bit new to MIPs so I'm not sure how to go about solving this problem 回答1: I've broken down the invidual steps of the algorithm. I then created a C prototype

Convert integer to its hexidecimal value to print

前提是你 提交于 2020-05-08 05:57:59
问题 Say I take an integer assigned to $a0, how do I go about and print the integer in its Hexadecimal form? 回答1: Use syscall 34. MARS syscalls If you are using a simulator which does not have that syscall, or you want to see only the necessary bytes, you will need to do it manually. The easiest approach would be iterative. Get a string of 10 bytes (8 hex values and leading 0x). 1) Bitwise and $a0 with constant 15. 2) Convert result to equivalent hex value in ASCII. A lookup table would be clean

Convert integer to its hexidecimal value to print

天涯浪子 提交于 2020-05-08 05:57:48
问题 Say I take an integer assigned to $a0, how do I go about and print the integer in its Hexadecimal form? 回答1: Use syscall 34. MARS syscalls If you are using a simulator which does not have that syscall, or you want to see only the necessary bytes, you will need to do it manually. The easiest approach would be iterative. Get a string of 10 bytes (8 hex values and leading 0x). 1) Bitwise and $a0 with constant 15. 2) Convert result to equivalent hex value in ASCII. A lookup table would be clean

Replace specific character of string using mips

六月ゝ 毕业季﹏ 提交于 2020-04-17 19:28:27
问题 I was trying to replace specific character of string using mips. The program is like the user needs to enter the string which is limited to 40 characters and the program needs to ask the user if they want to replace any character of the string or not. In my code I was able to print only one character, here is my code: .data prompt0: .asciiz " Please Enter any String :" prompt:.asciiz "\n Your current string is: " prompt1:.asciiz "\n Do you want to make any changes to the string? (y/n): "