【问题标题】:MIPS Trouble Detecting Null Terminating CharacterMIPS 检测空终止字符的问题
【发布时间】:2014-02-25 01:46:51
【问题描述】:

一点背景故事: 这是一个应用程序,旨在获取一个字符串,并为每个字符添加一个键 (1-26) 到 ascii 值并将其放回字符串中。唯一的问题是我的结束字符也总是被操纵,即使我的程序设计为以空字符终止 (beqz)。

encrypt:
# store string address in $t0
la $t0, ($a0)
#store key in $t1
move $t1, $a1   
# initialize index, $t2 to 0
add $t2, $zero, $zero
li $t4, 26

encrypt_loop:
# load the byte at index in $t3
lb $t3, ($t0)

# check if it's the end of the string
beqz $t3, encrypt_end
# also check if it's a space
beq $t3, 32, incr

# subtract to make a = 0 etc
addi $t3, $t3, -97
# add key
add $t3, $t3, $t1
# modulo to make sure that it isn't over 26
div $t3, $t4
mfhi $t3
# add 97 back to get it back to its position
addi $t3, $t3, 97

# store byte back where you found it
sb $t3, ($t0)

#la $a0, ($t3)
#jal _put_char

incr:
# increment address
la $t0, 1($t0)

#jump back to beginning of the loop
j encrypt_loop

示例 ->

输入信息:超级开心

输入一个键:5

加密消息:xzujw mfuud]

谁能发现这段代码会操纵最后一个字符并将其更改为结束括号的原因?谢谢。

【问题讨论】:

  • 你是如何指定一个字符串的?它对我来说很好,所以我怀疑你使用的字符串不是空终止的。

标签: assembly mips null-terminated mars-simulator


【解决方案1】:

原来字符串正确终止,但我没有看到输入到控制台的字符串末尾的回车。一旦我考虑到这一点,我就能摆脱神秘人物。

【讨论】:

    猜你喜欢
    • 2012-01-11
    • 1970-01-01
    • 1970-01-01
    • 2021-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2012-08-14
    相关资源
    最近更新 更多