Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 随机字扰频器_String_Assembly_Random_Mips_Permutation - Fatal编程技术网

String 随机字扰频器

String 随机字扰频器,string,assembly,random,mips,permutation,String,Assembly,Random,Mips,Permutation,我正在尝试编写代码,使用MARS(我的MIPS模拟器)伪随机数生成器在字符串中选择一个随机字符,将其从内存中取出并放入寄存器,然后用星号“*”替换内存中的该字符 到目前为止,它只扰乱了这个词的一部分,让我发疯。我找不到此代码中有什么不起作用。我甚至不需要一个直接的答案,只要提示/提示就可以了 代码如下: #this loop extracts a char at random from a string in memory, stores it in a register, and replac

我正在尝试编写代码,使用MARS(我的MIPS模拟器)伪随机数生成器在字符串中选择一个随机字符,将其从内存中取出并放入寄存器,然后用星号“*”替换内存中的该字符

到目前为止,它只扰乱了这个词的一部分,让我发疯。我找不到此代码中有什么不起作用。我甚至不需要一个直接的答案,只要提示/提示就可以了

代码如下:

#this loop extracts a char at random from a string in memory, stores it in a register, and replaces the char in the string with an asterisk '*'

.data

.align 2
string0: .ascii "Tyler\n"

.align 2
endString: .asciiz "Loop completed!\n"
.align 2
scrambleString: .asciiz


.text

#counter
li $t0, 5

#pointer to string0
la $s0, string0




loop2:

#is counter = 0? go to loop3 if so
beq $t0, $0, loop3

#seed & prepare randomized number generator
li $v0, 30 
syscall

li $v0, 40 #sets seed
syscall

#generates random number in $a0, with the coUnter $t0 being the upper bound
addi $a1, $t0, 1
li $v0, 42
syscall


#add STRING POINTER by random number in $a0, store this new address in $t1
#addi $a0, $a0, 1
add $t1, $s0, $a0
#srlv $t1, $s0, $a0

#isolates that bytesized char, puts it into $t2
lbu $t2, ($t1)
#beq $t2, 0x5c, loop2

#replaces char in original string with "*"
li $t3, 0x2a
sb $t3, ($t1)

beq $t1, $t3, loop2
#decrement counter
addi $t0, $t0, -1

#loop return
j loop2


loop3:
la $a0, string0
li $v0, 4
syscall

li $v0, 10
syscall
  • 每次迭代时都会重置随机数种子 您的循环(loop2:)
  • 系统调用40和42分别采用2个参数,这些参数应在
    $a0
    中,并且
    $a1
    。看
  • 临时寄存器
    $t0,…$t9
    会被每个寄存器更改
    syscall
    。您应该使用被叫方保存的寄存器
    $s0,$s8

  • 我根本不知道MIPS asm,也不知道syscall使用的调用约定,但是您确定$t0和其他临时寄存器在syscall期间会被保留吗?