Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Swapping bits 1

Status
Not open for further replies.

Nerdie1234

Programmer
Nov 3, 2005
6
0
0
AU
In accumulator A say I have the hex value 12. I want swap these two numbers, ie getting 21 in A. I can't find a solution for this. Can anyone help?

Thanks!

p.s. I'm programming in assembly for the Motorola 68HC11 board.
 
You're mixing your thought processes about decimal numbers and binary numbers. If you want to swap decimal digits, divide the number by 10, multiply the remainder by 10, and add them back together. That has no relationship to swapping bits, though.

Lee
 
It is a bit long ago but,

clr b
lsl a
rol b
lsl a
rol b
lsl a
rol b
lsl a
rol b
aba

Succes, Tessa

 
Hi Tessa,

Can you please explain what rol b actually does? I ran what you've got on a simulator and the first 3 rol b does nothing but all of a sudden on the fourth rol b, b becomes 01.

My menu just says rol b is rotate left, without any further explanation :(

Thanks for you help!
 
ROL is allmost the same as LSL, but as the LSL shifts
in a 0(zero) on the right and the leftmost bit into the
carry, ROL shifts in the carry on the right and the
leftmost bit into the carry.

I try to make it visable:

LSL

carry <-- D7 <-- D6 <-- D5 .... D1 <-- D0 <-- 0

ROL

new carry <-- D7 <-- D6 .... D1 <-- D0 <-- old carry

So by using the LSL to shifht a bit to the left the
highest is saved in the carry and can be retreved by
the ROR.

Therefor the high 4 bits are shifted into the B register
and the A register is shifted 4 bits to the left.
The result is:

if A was $12 (is 012h for intel users),

A will be $20
B will be $01 and afther the ABA(is a add B to A)
A will be $21

Succes, Tessa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top