我一直在使用Mars的MIPS中停留在我的实验室的一部分,在那里以十六进制ASCII字符串输入3个程序参数并将其存储在寄存器中(与提示和用户输入不同;没有提示)。参数的格式为0x12345678、0xABCDEF01等。它们需要按升序输出,先以单精度浮点形式输出,然后以十进制形式输出。我在实验中的方法是使“ 0x”偏移并遍历字符串的其余部分。对于每个数字,减去48,对于每个大写字母,减去55。然后继续下一个字符串,然后继续下一个字符串并将它们存储在寄存器中。然后我的计划是对它们进行排序,然后以某种方式转换为单精度浮点,然后以某种方式转换为十进制。
我不确定十六进制整数的存储方式。
我是该语言的新手,并且背景较弱/不存在。到目前为止,这是我所坚持的:
# convert ASCII strings to hexadecimal integer
lh $a0, 2($a1) # offset the "0x" portion
lb $t1, 0($a1)
addi $t0, $zero, 0 # i = 0
addi $t1, $zero, 8 # x = 8, to iterate thru the 8 bits
While:
bge $t0, $t1, Done # while (i < y)
# if number subtract 48
# if letter subtract 55
addi $t0, $t0, 1 # i = i + 1, update to next byte
j While
Done:
# tempreg1 = 1st byte
# #need to offset by 2 for "0x" *2($a0)
# for (i = 0; i < 8; i++) *loop through the 1st string:
# if (0 < tempreg1 < 9)
# {
# arg1value += tempreg1 - ASCII value of '0'
# }
# if (A < tempreg1 < F)
# {
# arg1value += tempreg1 - ASCII value of 'A' + 10
# }
我很失落,所以任何帮助。预先谢谢你!