mips汇编语言中的位屏蔽/移位?
该计划的要求与我的解决方案一起发布在下面的代码中。有人能告诉我我做错了什么,并告诉我如何修复它吗?我每次输入的结果都是0。在大多数情况下,我相信我是在掩盖错误,而不是错误地移位mips汇编语言中的位屏蔽/移位?,mips,Mips,该计划的要求与我的解决方案一起发布在下面的代码中。有人能告诉我我做错了什么,并告诉我如何修复它吗?我每次输入的结果都是0。在大多数情况下,我相信我是在掩盖错误,而不是错误地移位 ########################################################################## ############################ # prompt user to enter an integer, read the integer,
##########################################################################
############################
# prompt user to enter an integer, read the integer, and display a 0 if the bits at the
# 16 and 256 place value positions of the integer are both 1 and display a 1 otherwise
############################ data segment ################################
.data
outputLegend1: .asciiz "0 = both bits at 16 & 256 place value positions are 1\n"
outputLegend2: .asciiz "1 = bits at 16 & 256 place value positions NOT both 1\n\n"
inputPrompt: .asciiz "Enter integer: "
outputLabel: .asciiz "Integer entered is of type "
############################ code segment ################################
.text
.globl main
main:
li $v0, 4
la $a0, outputLegend1
syscall # print output legend part 1
la $a0, outputLegend2
syscall # print output legend part 2
la $a0, inputPrompt
syscall # print integer prompt
li $v0, 5
syscall # read integer
move $t0, $v0 # save integer read in $t0
li $v0, 4
la $a0, outputLabel
syscall # print output label
li $v0, 1
##########################################################
# Insert NO MORE THAN 6 lines of code that involve ONLY
# bit manipulating instructions (ANDing, ORing, XORing,
# NORing and shifting - only whatever that are needed)
# so that the program will work just like the sample runs
# shown at the bottom (some blank lines edited out).
#my solution
sll $t1,$t1,4
andi $t2,$t1,1
sll $t2,$t2,4
andi $t3,$t2,1
xor $a0, $t2,$t3
syscall # display desired output
##########################################################
li $v0, 10 # exit gracefully
syscall
########################## sample test runs ##############################
# 0 = both bits at 16 & 256 place value positions are 1
# 1 = bits at 16 & 256 place value positions NOT both 1
#
# Enter integer: 0
# Integer entered is of type 1
# -- program is finished running --
#
# Reset: reset completed.
#
# 0 = both bits at 16 & 256 place value positions are 1
# 1 = bits at 16 & 256 place value positions NOT both 1
#
# Enter integer: 16
# Integer entered is of type 1
# -- program is finished running --
#
# Reset: reset completed.
#
# 0 = both bits at 16 & 256 place value positions are 1
# 1 = bits at 16 & 256 place value positions NOT both 1
#
# Enter integer: 256
# Integer entered is of type 1
# -- program is finished running --
#
# Reset: reset completed.
#
# 0 = both bits at 16 & 256 place value positions are 1
# 1 = bits at 16 & 256 place value positions NOT both 1
#
# Enter integer: 272
# Integer entered is of type 0
# -- program is finished running --
#
# Reset: reset completed.
#
# 0 = both bits at 16 & 256 place value positions are 1
# 1 = bits at 16 & 256 place value positions NOT both 1
#
# Enter integer: 12349876
# Integer entered is of type 0
# -- program is finished running --
#
# Reset: reset completed.
#
# 0 = both bits at 16 & 256 place value positions are 1
# 1 = bits at 16 & 256 place value positions NOT both 1
#
# Enter integer: 12346789
# Integer entered is of type 1
# -- program is finished running --
#
######################## end sample test runs ############################
你的想法是对的(但是有很多拼写错误),所以继续吧
第一次移动时,
$t1
没有什么有趣的。我认为您最初希望将$t0
转换为$t1
,因此您仍然拥有用户输入的原始值,以便以后进行操作
注意你的注册用法:
- 您需要源代码寄存器,这些寄存器在您的程序中已被锁定
- 如果以后需要一些原始/源代码值(不要删除仍然需要的值),则需要为目标使用新的/不同的寄存器
- 当您需要旧的/原始的值时,您不能简单地寻找新的寄存器
而且,当你想右移时,你正在左移
您只是在猜测何时使用哪个寄存器。因此,这里有一种方法可以帮助您摆脱由于不熟悉的组装而带来的混乱 试着用C编写你的代码,使用——对于这个作业,它不会花费太多,大约5行!但这将帮助您了解何时使用哪个变量。(确保您的C三地址代码正常工作-在某个地方测试并调试它,如有必要,请使用联机C编译器。) 接下来,在编写任何指令之前,将所有这些C(TAC)变量分配(创建映射)到MIPS寄存器 最后,使用变量到寄存器的映射,编写尊重/模拟这三个地址代码的汇编指令