Programming Forums
User Name Password Register

RSS Feed

Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Apr 16th, 2012, 9:35 PM   #1
Hobbyist Programmer
Join Date: Oct 2011
Posts: 127
Rep Power: 7 Troncoso is on a distinguished road
Reversing bits

I have an assignment to write a program in LC-3 assembly. I have to write several sub routines, one of them being to reverse the order of bits in a word and store the result in a register.
An example:

10010101 => 10101001

A mirror, if you will. I can think of a couple ways to do this. My issue comes when I need to store the bits back into a register. My plan is to use a nested loop:

word = 16 bit word

for (int i = 16; 16 > 0; 16--) {
	for (int j = 0; j < i; j++) {
		ADD word to itself to shift bits left by 1
	AND word with x8000 to isolate high order bit

That's my pseudocode to get the job done. The issue comes after this
AND word with x8000 to isolate high order bit

At that point, after each inner loop completes, I have the correct bit. I just don't know how to properly add that to the register.

Sorry, if this sounds complicated. I'll really appreciate any help.
Troncoso is offline   Reply With Quote


« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Data caching for vector of bits vs bytes? iProgrammer C++ 7 Mar 15th, 2010 3:06 PM
Problem with permuting bits kolosick.m188 C 1 Nov 20th, 2009 8:41 AM
String of bits to byte[] hbe02 Java 1 Mar 5th, 2008 11:07 AM
MySQL Datatypes: 2 Bits? Sane PHP 1 Jul 27th, 2006 3:08 AM
Reversing the order of the numbers... ReggaetonKing Java 7 Feb 28th, 2006 6:13 PM

DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC