mips

MIPS assembly: how to declare integer values in the .data section?

岁酱吖の 提交于 2021-01-17 08:05:49
问题 I'm trying to get my feet wet with MIPS assembly language using the MARS simulator. My main problem now is how do I initialize a set of memory locations so that I can access them later via assembly language instructions? For example, I want to initialize addresses 0x1001000 - 0x10001003 with the values 0x99, 0x87, 0x23, 0x45. I think this can be done in the data declaration (.data) section of my assembly program but I'm not sure of the syntax. Is this possible? Alternatively, in the .data

Null-terminating a string in MIPS?

北城余情 提交于 2021-01-05 14:43:26
问题 I'm writing strncpy in MIPS, but I'm having trouble null-terminating the string. If i do not null-terminate it myself, the string goes on and on. I have tried sb $__ 0($0) but that does not seem to work... $a0 = pointer to destination array $a1 = source string $a2 = number of characters to copy strncpy: add $t1 $zero $zero #counter beq $a2 $0 done # if num chars to copy is 0, return. j cpyLoop cpyLoop: beq $t1 $a2 done # if counter == num to copy, end lb $t2 0($a1) # load the character beq

Null-terminating a string in MIPS?

岁酱吖の 提交于 2021-01-05 14:43:23
问题 I'm writing strncpy in MIPS, but I'm having trouble null-terminating the string. If i do not null-terminate it myself, the string goes on and on. I have tried sb $__ 0($0) but that does not seem to work... $a0 = pointer to destination array $a1 = source string $a2 = number of characters to copy strncpy: add $t1 $zero $zero #counter beq $a2 $0 done # if num chars to copy is 0, return. j cpyLoop cpyLoop: beq $t1 $a2 done # if counter == num to copy, end lb $t2 0($a1) # load the character beq

Null-terminating a string in MIPS?

北战南征 提交于 2021-01-05 14:42:26
问题 I'm writing strncpy in MIPS, but I'm having trouble null-terminating the string. If i do not null-terminate it myself, the string goes on and on. I have tried sb $__ 0($0) but that does not seem to work... $a0 = pointer to destination array $a1 = source string $a2 = number of characters to copy strncpy: add $t1 $zero $zero #counter beq $a2 $0 done # if num chars to copy is 0, return. j cpyLoop cpyLoop: beq $t1 $a2 done # if counter == num to copy, end lb $t2 0($a1) # load the character beq

MIPS Input floating point number

大憨熊 提交于 2020-12-26 04:34:10
问题 How do you take in an input of a floating number in MIPS? I have tried using: li.s $f0, 6 syscall But I just keep getting that there is an error with the line. 回答1: li $v0, 6 syscall //the float value that is read will be in $f0 register 回答2: you cannot load-immediate a number into float registers li $t0, 6 # load-immediate 6 into an int register mtc1 $t0, $f0 # copies the bit pattern "...110". It is NOT 6.0!! cvt.s.w. $f12, $f0 # convert word to (single) float. $f12 now contains 6.0 回答3: You

MIPS Input floating point number

ぐ巨炮叔叔 提交于 2020-12-26 04:33:25
问题 How do you take in an input of a floating number in MIPS? I have tried using: li.s $f0, 6 syscall But I just keep getting that there is an error with the line. 回答1: li $v0, 6 syscall //the float value that is read will be in $f0 register 回答2: you cannot load-immediate a number into float registers li $t0, 6 # load-immediate 6 into an int register mtc1 $t0, $f0 # copies the bit pattern "...110". It is NOT 6.0!! cvt.s.w. $f12, $f0 # convert word to (single) float. $f12 now contains 6.0 回答3: You

MIPS Assembly Labels

末鹿安然 提交于 2020-12-25 04:32:47
问题 Does assembly for MIPS read every label? ignore the task and syntax, I just put something together quick. add reg3, reg1, $zero add reg1, reg1, reg2 beq reg1, reg3, BRANCH1 #reg2 contents are zero bne reg1, $zero, BRANCH2 #reg1 doesn't equal zero BRANCH1: add returnReg, reg1, $zero BRANCH2: add returnReg, reg2, $zero jr returnAddress would this read line-by-line, including the labels, unless they were jumped over? For instance, would BRANCH1 be executed every single time, unless the contents

Reading from one file and writing to another - MIPS

↘锁芯ラ 提交于 2020-12-15 05:36:12
问题 I have written some code which opens and reads from a file, input.txt, in a loop. I now want to take each word from the first file, and write it to a new file like so. If file 1 says "This is my file", File 2 would say "This /n is /n my /n file" each on a separate line. I have written a label which opens the file to be written to, now I am unsure of what I should write in order to access each word from my input.txt. file_open: li $v0, 13 la $a0, output_file_name # output.txt li $a1, 1 li $a2,

Why `addi $reg, $0, N` instead of `li $reg N`?

China☆狼群 提交于 2020-12-15 04:30:31
问题 I'm learning MIPS by myself with sources found online* and see a lot of people doing addi $reg, $0, N to store a numerical value N inside a register $reg , and am wondering why is this so ubiquitous when li $reg N would do. What am I missing ? *(so don't have exhaustive while accessible explanations of what I learn) 回答1: Assembler has: directives — .text , .data , .align 2 , others labels — main: regular instructions — addi $a0, $0, 1 and beq $a0, $a1, label pseudo instructions — li $a0, 1

In MIPS, how do I divide register contents by two?

*爱你&永不变心* 提交于 2020-12-13 10:34:55
问题 Let's say I have $t0 , and I'd like to divide its integer contents by two, and store it in $t1 . My gut says: srl $t1, $t0, 2 ... but wouldn't that be a problem if... say... the right-most bit was 1? Or does it all come out in the wash because the right-most bit (if positive) makes $t0 an odd number, which becomes even when divided? Teach me, O wise ones... 回答1: Use instruction sra: Shift right arithmetic !! sra $t1, $t0, 1 Divides the content of $t0 by the first power of 2. Description: