mips

About negate a sign-integer in mips?

瘦欲@ 提交于 2021-02-08 06:57:22
问题 I'm thinking about how to negate a signed-integer in mips32. My intuition is using definition of 2's complement like: (suppose $s0 is the number to be negated) nor $t0, $s0, $s0 ; 1's complement addiu $t0, $t0, 1 ; 2's = 1's + 1 then I realized that it can be done like: sub $t0, $zero, $s0 so... what's the difference? Which is faster? IIRC sub will try to detect overflow, but would this make is slower? Finally, is there any other way to do so? 回答1: subu $t0, $zero, $s0 is the best way, and is

Least significant bit mips

寵の児 提交于 2021-02-08 06:35:52
问题 How can i change least significant bit in a register in Mips? In another post How to get LSB bit in MIPS? it saws how to get it but i want to change it. 回答1: The following one line should do it: xori $t0, $s0, 1 Explained: the contents in $s0 contains zeros and ones, while the immediate value has zeros and a one in the LSB. Whenever the LSB is 0, it is xored with 1 and outputs a 1. Whenever it is 1, it is xored with 1 and outputs a 0. The remaining bits will output a 1 if they are 1 and a 0

How does processors know the end of program?

血红的双手。 提交于 2021-02-07 19:54:53
问题 I was wondering, how does processors know when to stop executing a program. Or rather, when to stop the "fetch, decode execute" cycle. I have thought of different ways but not sure which is the correct one or if they are all wrong. 1- Maybe there is a special instruction at the end automatically added by the assembler to let the processor know this is the end. 2- When it reach an invalid memory (But how does it recognize that). 3- It loops and re-run the program, but again how does it

What are the advantages of a frame pointer?

我是研究僧i 提交于 2021-02-07 03:51:42
问题 We're studying the MIPS assembler (I guess this question can apply to assembly in general though), and the teacher introduced us to the frame pointer . If I have a function prologue, I used to do directly the stack pointer : addiu $sp, $sp, -8 ; alloc 2 words in the stack sw $s0, 4($sp) ; save caller function $s0 value in the stack sw $ra, ($sp) ; save the return address for the callee function And in the function epilogue: move $v0, $0 ; set 0 as return value lw $s0, 4($sp) ; pick up caller

What are the advantages of a frame pointer?

痴心易碎 提交于 2021-02-07 03:50:26
问题 We're studying the MIPS assembler (I guess this question can apply to assembly in general though), and the teacher introduced us to the frame pointer . If I have a function prologue, I used to do directly the stack pointer : addiu $sp, $sp, -8 ; alloc 2 words in the stack sw $s0, 4($sp) ; save caller function $s0 value in the stack sw $ra, ($sp) ; save the return address for the callee function And in the function epilogue: move $v0, $0 ; set 0 as return value lw $s0, 4($sp) ; pick up caller

Handling non-digit user input to a MARS read-integer system call?

独自空忆成欢 提交于 2021-02-05 12:00:36
问题 I'm doing a simple program of car park that takes the input from the user, and branch to a label in accordance of the input. The problem is, the program always ends abruptly if the user enter an input with different data type than integer (like "a" or any alphabets) Below is my code (that relevant to the input part) : li $v0,5 #system call to get input from user syscall li $t1,2 beq $v0,1,park # go to "park" section of codes if input is 1 beq $v0,2,exit # go to "exit" section of codes if

How to pass an input string from user to a MIPS program

a 夏天 提交于 2021-02-05 11:14:06
问题 I'm trying to solve a problem to write assembly language program to detect if a phrase or characters entered by the user is a palindrome. I've gotten this far, and I believe everything should work, but I'm wondering how I can implement this so that it takes an actual word to test. When I run in MARS, there's simply no input option. .data string_space: .space 1024 is_palin_msg: .asciiz "The string is a palindrome.\n" not_palin_msg: .asciiz "The string is not a palindrome.\n" .text main: la $a0

Difference between adding 0 and moving a register in MIPS

心已入冬 提交于 2021-02-05 09:55:34
问题 What's the difference between: add rd, rs, zero and move rd, rs They both look like they should do the same thing. 回答1: The move is a pseudoinstruction, they do the same job. MIPS is a reduced instruction set computer (RISC), so the instruction size and hardware complexity are minimized by keeping the number of instructions small. However, MIPS defines pseudoinstructions that are not actually part of the instruction set but are commonly used by programmers and compilers. 来源: https:/

Error: Runtime exception … store address not aligned on word boundary

可紊 提交于 2021-02-02 09:54:29
问题 I am trying to print binary digits of any integer input and store them in the array starting at the last index. Then I am trying to print it from the array. .data prompt: .asciiz "Enter an int: " errorLarge: .asciiz "Error Value to large CANNOT be held in 16 bit" errorSmall: .asciiz "Error Value is to small CANNOT be held in 16 bits" # 64bytes =512 bits created (1 int =4 bytes):: (16 int =64 bytes) array: .space 64 newLine: .asciiz "\n" .globl main .text main: li $v0,4 la $a0,prompt syscall

Error: Runtime exception … store address not aligned on word boundary

允我心安 提交于 2021-02-02 09:50:52
问题 I am trying to print binary digits of any integer input and store them in the array starting at the last index. Then I am trying to print it from the array. .data prompt: .asciiz "Enter an int: " errorLarge: .asciiz "Error Value to large CANNOT be held in 16 bit" errorSmall: .asciiz "Error Value is to small CANNOT be held in 16 bits" # 64bytes =512 bits created (1 int =4 bytes):: (16 int =64 bytes) array: .space 64 newLine: .asciiz "\n" .globl main .text main: li $v0,4 la $a0,prompt syscall