LC3大会按位右移 [英] LC3 Assembly Bitwise Right Shift

查看:625
本文介绍了LC3大会按位右移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做什么它同时实现按位左移和按位右移使用的 LC-3组装。基本上,每一个位已经被移动超过一空间在换档的方向上,和一个零填充产生的空的空间中。

What I need to do it implement both a bitwise left shift, and a bitwise right shift using LC-3 Assembly. Basically, every bit has to be moved over one space in the direction of the shift, and a zero fills the empty space created.

例如:

右Shift:

 01001001
 00100100→

左移:

 01001001
←10010010

我已经成功地实现了一个左移,通过采取二进制字符串,并将其添加到自己。

I've successfully implemented a left shift, by taking the binary string, and adding it to itself.

我难倒如何执行右移。任何想法,将大大AP preciated。我有AND,NOT,加运算,数据移动操作,七个寄存器来存储值和内存的整个范围。我只是需要一些基本的想法如何可以实现的。

I'm stumped on how to perform a right shift. Any thoughts would be greatly appreciated. I have AND, NOT, ADD operations, data movement operations, seven registers to store values and whole range of memory. I just need some basic ideas how it could be implemented.

如果你需要一个LC-3指令集的参考,有的一个在这里

If you need a LC-3 Instruction Set reference, there is one here.

推荐答案

假设你设置了 R2 ,这样它只有一个位集。然后,如果你做了一个上的以Z 条件另一个寄存器和分支,您正在测试是否该位是组。如果是,你要设置的previous位在你的结果注册。

Suppose you set up R2 so that it has just a single bit set. Then, if you do an AND with another register and branch on the Z condition, you are testing whether that bit is set. If it is, you want to set the previous bit in your "result" register.

如果你那么改变你的单位的寄存器在一个地方,在一个循环中重复,你应该有你所需要的。

If you then shift your single-bit register over one place and repeat in a loop, you should have what you need.

(道歉,如果这是模糊的,因为这是presumably功课我试图避免只是给你答案)

(Apologies if this is vague; since this is presumably homework I'm trying to avoid just giving you the answer)

编辑:

因此​​,假设您的输入是01001011.你先从00000000输出的00000010输入掩码和00000001输出面膜你做AND和发现,这是为零,所以你添加的输出面膜输出。然后,你既转移了口罩获得00000100和00000010。

So, suppose your input is 01001011. You start with an output of 00000000, an input mask of 00000010, and an output mask of 00000001. You do the AND and find that it is nonzero, so you add your output mask to the output. Then you shift both masks over to get 00000100 and 00000010.

在通过循环下一次时,与是零,因此,在添加什么,等等。在变速面膜使得零的循环终止。

On the next time through the loop, the AND is zero, so you add nothing, and so forth. The loop terminates when shifting the mask makes it zero.

这篇关于LC3大会按位右移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆