位反转68HC12上的一个字节 [英] Bit-reverse a byte on 68HC12

查看:126
本文介绍了位反转68HC12上的一个字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在微处理器课上,我们在Freescale CodeWarrior中使用汇编语言来编程68HCS12微控制器.我们本周的任务是反转一个字节,因此,如果该字节为00000001,则输出将为10000000,或将00101011转换为11010100.我们必须使用汇编语言,并被告知可以使用旋转和移位(但不限于! )来完成此任务.我真的不知道该从哪里开始.

I'm in a microprocessors class and we are using assembly language in Freescale CodeWarrior to program a 68HCS12 micro controller. Our assignment this week is to revers a byte, so if the byte was 00000001, the output would be 10000000, or 00101011 to 11010100. We have to use assembly language, and were told we could use rotates and shifts (but not limited to!) to accomplish this task. I'm really at a loss as to where I should start.

推荐答案

如果可以节省256个字节的额外代码大小,则查找表可能是在68HCS12上反转字节的最有效方法.但是我很确定这不是您的老师所期望的.

If you can spare the 256 bytes extra code size, a lookup table is probably the most efficient way to reverse a byte on a 68HCS12. But I am pretty sure this is not what your instructor is expecting.

对于普通"解决方案,请单独考虑数据位.旋转和移位使您可以移动位.对于第一个解决方案,隔离八个位(使用按位和"操作),将它们移至目标位置(移位,旋转...),然后再次将它们组合在一起(使用按位或"操作).这将不是最有效或最简单的实现,但是您应该首先集中精力获得正确的结果-优化可以等待.

For the "normal" solution, consider the data bits individually. Rotates and shifts allow you to move bits around. For a first solution, isolate the eight bits (with bitwise "and" operations), move them to their destination positions (shifts, rotates...), then combine them together again (with bitwise "or" operations). This will not be the most efficient or simplest implementation, but you should first concentrate on getting a correct result -- optimization can wait.

这篇关于位反转68HC12上的一个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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