[英]Shifting a Binary String to the right in machine code/assembly language
I understand that doing 15 shifts to the left would shift a binary sequence to the right by one. 我知道向左移动15个位移会使二进制序列向右移动1。 However after setting the initial register values, if register 1 is equal to 1;
但是,在设置初始寄存器值之后,如果寄存器1等于1,则设置为0。 the programs gives the correct solution.
该程序提供了正确的解决方案。 Anything larger stored in register 1 causes the program to give the wrong solutions.
寄存器1中存储的任何较大内容都会导致程序给出错误的解决方案。 I'm Working with the LC-3;
我正在使用LC-3; here is my bin file code:
这是我的bin文件代码:
0011000000000000 ; Orig
0010000011111111 ; R0 <- mem[x3100]
0010001011111111 ; R1 <- mem[x3101]
0101010010100000 ; R2 <- R2 AND #0
0001001001100000 ; R1 <- R1 + #0
0000010000001101 ; BRz R1
0001010010101111 ; R2 <- R2+15
0000010000001001 ; BRz R2
0001000000100000 ; R0 = R0 + #0
0000100000000011 ; BRn
0001000000000000 ; R0 <- R0+R0
0001010010111111 ; R2--
0000111111111010 ; BRnzp PCOffset
0001000000000000 ; R0 <- R0 + R0
0001000000000001 ; R0 <- R0 + #1
0001010010111111 ; R2--
0000111 111110110 ; BRnzp PCOffset
0001001001111111 ; R1--
0000 111 111110001 ; BRnzp PCOffset
0011 000 011101111 ; St R0 -> mem[x3102]
1111000000100101 ; Halt
Found the line of code that's giving you trouble 找到了给您带来麻烦的代码行
0001000000000001 ; R0 <- R0 + #1
this isn't adding 1 to R0 it's actually adding R1 to R0. 这不是在R0上加1,实际上是在R0上加R1。
0001000000000001 ; R0 <- R0 + R1
What you need to replace that line with is: 您需要用以下内容替换该行:
0001000000100001 ; R0 <- R0 + #1
You're missing the add immediate bit [5]. 您缺少立即添加位[5]。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.