Hi everyone!
I was wondering how to switch bits in the 68000. By this I mean that if I have lets say 3FE0 hex, which is 0011 1111 1110 0000 in binary, I need it to become 7FC, which is 0000 0111 1111 0011 binary.
I don't know if I should put it on the stack (which I don't really know how that works). I've tried rotating, but without success. I've tried many many other things, but I just can't seem to get a grasp on this.
Any help would be appreciated.
I was wondering how to switch bits in the 68000. By this I mean that if I have lets say 3FE0 hex, which is 0011 1111 1110 0000 in binary, I need it to become 7FC, which is 0000 0111 1111 0011 binary.
I don't know if I should put it on the stack (which I don't really know how that works). I've tried rotating, but without success. I've tried many many other things, but I just can't seem to get a grasp on this.
Any help would be appreciated.
Isn't the SWAP instruction for that ? I think it's equivalent to BSWAP in the x86 family.
I had thought of that.
But the swap instruction swaps register halves. So if I use that instruction on 3FE0, I end up with E03F.
Thanks anyway!
But the swap instruction swaps register halves. So if I use that instruction on 3FE0, I end up with E03F.
Thanks anyway!
680x0 instructions for bits shifts are: lsl/lsr/asl/asr/rol/ror
move.w #$3fe0,d0
lsr.w #3,d0
d0 will be equal to $7fc
All simply.
h.
move.w #$3fe0,d0
lsr.w #3,d0
d0 will be equal to $7fc
All simply.
h.
Thanks, that works for that case, but it doesn't "switch" the last bit with the first bit, so it doesn't work in every case. Maybe I didnt explain myself properly.
Basically I have an "image" made out of 1's that needs to be flipped around.
If I have 3FE0 hex, which is 0011 1111 1110 0000 in binary, I need to switch bit 0 with bit 15, then bit 1 with bit 14, and so on. In this case it gives me 7FC hex, which is 0000 0111 1111 0011 binary. So using LSR does work, but only for this one.
What I need to do is a loop that will change 16 successive different lines in this fashion. Some could be changed using LSR, but the number of shifts to make is different in different cases.
But when I get to this next line for example, 3878 hex, or 0011 1000 0111 1000 binary, the end result has to be 0001 1110 0001 1100 or 1E1C hex.
As you can see, because this is in a loop, I don't see how the lsl/lsr/asl/asr/rol/ror instructions can be used since every case is different.
That is just the first part, after that I have to rotate the image 90 degrees and for that, I don't think I'll ever get it done!!!
But if anyone can help with the "switching" of the bits, I would truly appreciate it. I am at my wits end, I've tried so many different things at this point that I'm starting to repeat things that I've done..... I think I'm going mad!!!
Basically I have an "image" made out of 1's that needs to be flipped around.
If I have 3FE0 hex, which is 0011 1111 1110 0000 in binary, I need to switch bit 0 with bit 15, then bit 1 with bit 14, and so on. In this case it gives me 7FC hex, which is 0000 0111 1111 0011 binary. So using LSR does work, but only for this one.
What I need to do is a loop that will change 16 successive different lines in this fashion. Some could be changed using LSR, but the number of shifts to make is different in different cases.
But when I get to this next line for example, 3878 hex, or 0011 1000 0111 1000 binary, the end result has to be 0001 1110 0001 1100 or 1E1C hex.
As you can see, because this is in a loop, I don't see how the lsl/lsr/asl/asr/rol/ror instructions can be used since every case is different.
That is just the first part, after that I have to rotate the image 90 degrees and for that, I don't think I'll ever get it done!!!
But if anyone can help with the "switching" of the bits, I would truly appreciate it. I am at my wits end, I've tried so many different things at this point that I'm starting to repeat things that I've done..... I think I'm going mad!!!
Simplest way to reverse bits is with a lookup table.
In MASM:Posted on 2003-11-18 20:11:25 by bitRAKE
In MASM:Posted on 2003-11-18 20:11:25 by bitRAKE
Thanks but I have no idea what that table means :) I am relatively new at this. I'm sure your pointing me in the right direction, but I am still struggling and absolutely not understanding how this can be done.
I have been trying and trying to use btst, bset, bclr, bchg. The first image I had to do was the negative of the original image. So I used bchg on that without a problem.....
Now I understand that BTST tests the bit without changing anything, BCLR puts the bit to 0 and BSET puts it to 1. But I don't see how that helps me in anyway.
For example, I'll shorten the binary numbers here, I have 0001 0111 and have to make it 1110 1000. Now if I test bit #4 (we start at bit 0 right?) I find that bit is 0. Then I test bit #3 which is 1. I need to switch these 2 bits. I can't say if 0 then set to 1 or if 1 then clear to 0 because I may have to switch two 1's or 2 0's. That throws my IF THEN idea right out the door!
How can I say "put bit 4 into bit 3" and "put bit 3 into bit 4"? That's the only way I can see how to do this.
Or, I'm thinking if I could just store in memory the binary number itself, then I could retrieve it backwards. But I don't know how to do that. Everytime I store a number I get a hex number. I can't figure out how to store a binary number. I tried to put it in the status register, but that was a flop too......
I've looked all over the net, message boards, my textbook, tutorials, etc.... nothing tells me how I can do this.
I am including the image so that anyone reading this may understand what I mean. Obviously, the periods are 0's.
If anyone has any idea, I'm willing to try anything at this point. I trully appreciate everybody reading this post.
I have been trying and trying to use btst, bset, bclr, bchg. The first image I had to do was the negative of the original image. So I used bchg on that without a problem.....
Now I understand that BTST tests the bit without changing anything, BCLR puts the bit to 0 and BSET puts it to 1. But I don't see how that helps me in anyway.
For example, I'll shorten the binary numbers here, I have 0001 0111 and have to make it 1110 1000. Now if I test bit #4 (we start at bit 0 right?) I find that bit is 0. Then I test bit #3 which is 1. I need to switch these 2 bits. I can't say if 0 then set to 1 or if 1 then clear to 0 because I may have to switch two 1's or 2 0's. That throws my IF THEN idea right out the door!
How can I say "put bit 4 into bit 3" and "put bit 3 into bit 4"? That's the only way I can see how to do this.
Or, I'm thinking if I could just store in memory the binary number itself, then I could retrieve it backwards. But I don't know how to do that. Everytime I store a number I get a hex number. I can't figure out how to store a binary number. I tried to put it in the status register, but that was a flop too......
I've looked all over the net, message boards, my textbook, tutorials, etc.... nothing tells me how I can do this.
I am including the image so that anyone reading this may understand what I mean. Obviously, the periods are 0's.
IMAGE DC.W $AAAA ;................
DC.W $0000 ;................
DC.W $3FE0 ;..111111111.....
DC.W $3FF0 ;..1111111111....
DC.W $3878 ;..111....1111...
DC.W $3838 ;..111.....111...
DC.W $3838 ;..111.....111...
DC.W $3870 ;..111....111....
DC.W $3FE0 ;..111111111.....
DC.W $3FE0 ;..111111111.....
DC.W $3870 ;..111....111....
DC.W $3870 ;..111....111....
DC.W $3838 ;..111.....111...
DC.W $3838 ;..111.....111...
DC.W $0000 ;................
DC.W $0000 ;................
DC.L $C0C0C0C0 ;Marker at the end of original image
If anyone has any idea, I'm willing to try anything at this point. I trully appreciate everybody reading this post.
Thanks but I have no idea what that table means :) I am relatively new at this. I'm sure your pointing me in the right direction, but I am still struggling and absolutely not understanding how this can be done.
I have been trying and trying to use btst, bset, bclr, bchg. The first image I had to do was the negative of the original image. So I used bchg on that without a problem.....
Now I understand that BTST tests the bit without changing anything, BCLR puts the bit to 0 and BSET puts it to 1. But I don't see how that helps me in anyway.
For example, I'll shorten the binary numbers here, I have 0001 0111 and have to make it 1110 1000. Now if I test bit #4 (we start at bit 0 right?) I find that bit is 0. Then I test bit #3 which is 1. I need to switch these 2 bits. I can't say if 0 then set to 1 or if 1 then clear to 0 because I may have to switch two 1's or 2 0's. That throws my IF THEN idea right out the door!
How can I say "put bit 4 into bit 3" and "put bit 3 into bit 4"? That's the only way I can see how to do this.
Or, I'm thinking if I could just store in memory the binary number itself, then I could retrieve it backwards. But I don't know how to do that. Everytime I store a number I get a hex number. I can't figure out how to store a binary number. I tried to put it in the status register, but that was a flop too......
I've looked all over the net, message boards, my textbook, tutorials, etc.... nothing tells me how I can do this.
I am including the image so that anyone reading this may understand what I mean. Obviously, the periods are 0's.
IMAGE DC.W $AAAA ;................
DC.W [QUOTE][i]Originally posted by stimpyzu [/i]
[B]Thanks but I have no idea what that table means :) I am relatively new at this. I'm sure your pointing me in the right direction, but I am still struggling and absolutely not understanding how this can be done.
I have been trying and trying to use btst, bset, bclr, bchg. The first image I had to do was the negative of the original image. So I used bchg on that without a problem.....
Now I understand that BTST tests the bit without changing anything, BCLR puts the bit to 0 and BSET puts it to 1. But I don't see how that helps me in anyway.
For example, I'll shorten the binary numbers here, I have 0001 0111 and have to make it 1110 1000. Now if I test bit #4 (we start at bit 0 right?) I find that bit is 0. Then I test bit #3 which is 1. I need to switch these 2 bits. I can't say if 0 then set to 1 or if 1 then clear to 0 because I may have to switch two 1's or 2 0's. That throws my IF THEN idea right out the door!
How can I say "put bit 4 into bit 3" and "put bit 3 into bit 4"? That's the only way I can see how to do this.
Or, I'm thinking if I could just store in memory the binary number itself, then I could retrieve it backwards. But I don't know how to do that. Everytime I store a number I get a hex number. I can't figure out how to store a binary number. I tried to put it in the status register, but that was a flop too......
I've looked all over the net, message boards, my textbook, tutorials, etc.... nothing tells me how I can do this.
I am including the image so that anyone reading this may understand what I mean. Obviously, the periods are 0's.
[code]
IMAGE DC.W $AAAA ;................
DC.W $0000 ;................
DC.W $3FE0 ;..111111111.....
DC.W $3FF0 ;..1111111111....
DC.W $3878 ;..111....1111...
DC.W $3838 ;..111.....111...
DC.W $3838 ;..111.....111...
DC.W $3870 ;..111....111....
DC.W $3FE0 ;..111111111.....
DC.W $3FE0 ;..111111111.....
DC.W $3870 ;..111....111....
DC.W $3870 ;..111....111....
DC.W $3838 ;..111.....111...
DC.W $3838 ;..111.....111...
DC.W $0000 ;................
DC.W $0000 ;................
DC.L $C0C0C0C0 ;Marker at the end of original image
[/code]
If anyone has any idea, I'm willing to try anything at this point. I trully appreciate everybody reading this post. [/B][/QUOTE]00 ;................
DC.W FE0 ;..111111111.....
DC.W FF0 ;..1111111111....
DC.W 78 ;..111....1111...
DC.W 38 ;..111.....111...
DC.W 38 ;..111.....111...
DC.W 70 ;..111....111....
DC.W FE0 ;..111111111.....
DC.W FE0 ;..111111111.....
DC.W 70 ;..111....111....
DC.W 70 ;..111....111....
DC.W 38 ;..111.....111...
DC.W 38 ;..111.....111...
DC.W [QUOTE][i]Originally posted by stimpyzu [/i]
[B]Thanks but I have no idea what that table means :) I am relatively new at this. I'm sure your pointing me in the right direction, but I am still struggling and absolutely not understanding how this can be done.
I have been trying and trying to use btst, bset, bclr, bchg. The first image I had to do was the negative of the original image. So I used bchg on that without a problem.....
Now I understand that BTST tests the bit without changing anything, BCLR puts the bit to 0 and BSET puts it to 1. But I don't see how that helps me in anyway.
For example, I'll shorten the binary numbers here, I have 0001 0111 and have to make it 1110 1000. Now if I test bit #4 (we start at bit 0 right?) I find that bit is 0. Then I test bit #3 which is 1. I need to switch these 2 bits. I can't say if 0 then set to 1 or if 1 then clear to 0 because I may have to switch two 1's or 2 0's. That throws my IF THEN idea right out the door!
How can I say "put bit 4 into bit 3" and "put bit 3 into bit 4"? That's the only way I can see how to do this.
Or, I'm thinking if I could just store in memory the binary number itself, then I could retrieve it backwards. But I don't know how to do that. Everytime I store a number I get a hex number. I can't figure out how to store a binary number. I tried to put it in the status register, but that was a flop too......
I've looked all over the net, message boards, my textbook, tutorials, etc.... nothing tells me how I can do this.
I am including the image so that anyone reading this may understand what I mean. Obviously, the periods are 0's.
[code]
IMAGE DC.W $AAAA ;................
DC.W $0000 ;................
DC.W $3FE0 ;..111111111.....
DC.W $3FF0 ;..1111111111....
DC.W $3878 ;..111....1111...
DC.W $3838 ;..111.....111...
DC.W $3838 ;..111.....111...
DC.W $3870 ;..111....111....
DC.W $3FE0 ;..111111111.....
DC.W $3FE0 ;..111111111.....
DC.W $3870 ;..111....111....
DC.W $3870 ;..111....111....
DC.W $3838 ;..111.....111...
DC.W $3838 ;..111.....111...
DC.W $0000 ;................
DC.W $0000 ;................
DC.L $C0C0C0C0 ;Marker at the end of original image
[/code]
If anyone has any idea, I'm willing to try anything at this point. I trully appreciate everybody reading this post. [/B][/QUOTE]00 ;................
DC.W [QUOTE][i]Originally posted by stimpyzu [/i]
[B]Thanks but I have no idea what that table means :) I am relatively new at this. I'm sure your pointing me in the right direction, but I am still struggling and absolutely not understanding how this can be done.
I have been trying and trying to use btst, bset, bclr, bchg. The first image I had to do was the negative of the original image. So I used bchg on that without a problem.....
Now I understand that BTST tests the bit without changing anything, BCLR puts the bit to 0 and BSET puts it to 1. But I don't see how that helps me in anyway.
For example, I'll shorten the binary numbers here, I have 0001 0111 and have to make it 1110 1000. Now if I test bit #4 (we start at bit 0 right?) I find that bit is 0. Then I test bit #3 which is 1. I need to switch these 2 bits. I can't say if 0 then set to 1 or if 1 then clear to 0 because I may have to switch two 1's or 2 0's. That throws my IF THEN idea right out the door!
How can I say "put bit 4 into bit 3" and "put bit 3 into bit 4"? That's the only way I can see how to do this.
Or, I'm thinking if I could just store in memory the binary number itself, then I could retrieve it backwards. But I don't know how to do that. Everytime I store a number I get a hex number. I can't figure out how to store a binary number. I tried to put it in the status register, but that was a flop too......
I've looked all over the net, message boards, my textbook, tutorials, etc.... nothing tells me how I can do this.
I am including the image so that anyone reading this may understand what I mean. Obviously, the periods are 0's.
[code]
IMAGE DC.W $AAAA ;................
DC.W $0000 ;................
DC.W $3FE0 ;..111111111.....
DC.W $3FF0 ;..1111111111....
DC.W $3878 ;..111....1111...
DC.W $3838 ;..111.....111...
DC.W $3838 ;..111.....111...
DC.W $3870 ;..111....111....
DC.W $3FE0 ;..111111111.....
DC.W $3FE0 ;..111111111.....
DC.W $3870 ;..111....111....
DC.W $3870 ;..111....111....
DC.W $3838 ;..111.....111...
DC.W $3838 ;..111.....111...
DC.W $0000 ;................
DC.W $0000 ;................
DC.L $C0C0C0C0 ;Marker at the end of original image
[/code]
If anyone has any idea, I'm willing to try anything at this point. I trully appreciate everybody reading this post. [/B][/QUOTE]00 ;................
DC.L $C0C0C0C0 ;Marker at the end of original image
If anyone has any idea, I'm willing to try anything at this point. I trully appreciate everybody reading this post.
So you want to reverse the bit patterns in the image so that the R is flipped horizontally ? Am I correct?
Well this is how I would do it :
-Clear a 16-bit register or memory space to zero
-Initialize one byte mask (one that is equal to one) -Use this to test low byte (If I remember correctly the 68000 is big endian so you'll have to remember this fact).
-Initialize another byte mask to 80h
Basically what you do is you test the upper bit mask (one that is equal to 80h) with the high byte of the 16-bit WORD row in your character map. And if the bit is set, set bit 0 then shift the upper bit mask right, etc.
I'll have to think about it, LOL! but you can see where I'm going, use a mask, test each individual bit then if the bit is set the opposite bit in the zeroed 16-bit register or memory location. If someone else hasn't helped you or you haven't reached a solution I'll think about it and let you know.
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
oops, better with code tags.... my bad...
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
Originally posted by stimpyzu
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
00 ;................
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
Originally posted by stimpyzu
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
00 ;................
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
FC ;.....111111111..
$FFC ;....1111111111..
Originally posted by stimpyzu
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
E1C ;...1111....111..
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
Originally posted by stimpyzu
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
C1C ;...111.....111..
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
Originally posted by stimpyzu
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
C1C ;...111.....111..
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
$E1C ;....111....111..
FC ;.....111111111..
FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
Originally posted by stimpyzu
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
C1C ;...111.....111..
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
Originally posted by stimpyzu
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
C1C ;...111.....111..
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
Originally posted by stimpyzu
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
00 ;................
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
Originally posted by stimpyzu
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
00 ;................
That's right. It's gotta end up like this: (sorry the first line should of been 0000.....AAAA was for testing purpuses)
$0000 ;................
$0000 ;................
$7FC ;.....111111111..
$FFC ;....1111111111..
$1E1C ;...1111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$E1C ;....111....111..
$7FC ;.....111111111..
$7FC ;.....111111111..
$E1C ;....111....111..
$E1C ;....111....111..
$1C1C ;...111.....111..
$1C1C ;...111.....111..
$0000 ;................
$0000 ;................
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
Although it doesn't look it, the "R" is left side right (flipped on the y-axis).
After I have to do another one that rotates the "R" 90 degrees to the clockwise.... but that's another storie :) ... I figure if I can understand this one, maybe I'll figure out the other one.
I must admit you have a tricky problem on your hand, I wrote x86 assembly code to do something like this except the data wasn't bitmapped but each pixel was represented with byte data
Hold on, maybe I got something here try this:
(I'm sorry my friend but I'm not too familiar with 68K code so I can't help you code wise)
BitSet: 01h (byte)
MaskL: 01h (byte)
MaskH: 80h (byte)
Out: 0000h (WORD)
Read High byte of row into a register (D0?)
Load MaskH into another register (D1?)
Do a AND (or an instruction equivalent to the x86 TEST instruction) D0 with D1
so maybe like
AND.B D1,D0 ? (Save registers if you cannot find equivalent to x86 TEST)
If ZeroFlag==0 THEN OR OutLow,BitSet
Shift D0 to the right one place
Shift Bitset to the left by one place
Jump if Zero flag is not set to the AND instruction
Read low byte into register (D0 ?)
Read MaskL into register (D1)
AND.B D1,D0 ? (Save registers if you cannot find equivalent to x86 TEST)
Reload Bitset with 01h
If ZeroFlag==0 THEN OR OutHigh,BitSet
Shift D0 to the left one place
Shift Bitset to the left by one place
Ihavent tested this code but I think it may do the trick
simply loop this code for every line.
Let me know if you have any problems. I've always wanted to code for the 68K :D
I'm quite sleepy now, I would have stayed onlinme to see if it worked for you, but I must go to sleep good night!
Please let us know how it goes thanks
Happy Coding :alright:
Please let us know how it goes thanks
Happy Coding :alright:
I'll kindda getting where your coming from, I had thought of a mask, but couldn't figure out what to use. I will look at it later (I've had enough for now) I'm pretty sleepy too.....
I will let you know how it goes..... thanks for all your help!!!!
I will let you know how it goes..... thanks for all your help!!!!
I would have made it like that, the principle is to swap the bits first 4 by 4 then 2 by 2 and at last 1 by 1 using bits masking. I wrote it for the intel proc so my conversion to the 68k may not be accurate.
(and this probably could be optimized).
68000 version:
Intel version:
But i think a byte based lookup table will be *much* faster, especially on a 68000.
The table would be composed of 256 bytes written in reverse order, you still have to swap the 2 lo/hi bytes tho and use them as indexes.
h.
(and this probably could be optimized).
68000 version:
; In: word in d0
; Out: swapped word in d0
ror.b #4,d0 ; swap bits 4 by 4
ror.w #8,d0
ror.b #4,d0
move.w d0,d1 ; swap bits 2 by 2
and.w #$3333,d0
and.w #$cccc,d1
add.w d0,d0
add.w d0,d0
lsr.w #2,d1
or.w d1,d0
move.w d0,d1 ; swap bits 1 by 1
and.w #$5555,d0
and.w #$aaaa,d1
add.w d0,d0
lsr.w #1,d1
or.w d1,d0
Intel version:
; In: word in ax
; Out: swapped word in ax
ror al,4
ror ah,4
ror ax,8
mov bx,ax
and ax,03333h
and bx,0cccch
shl ax,2
shr bx,2
or ax,bx
mov bx,ax
and ax,05555h
and bx,0aaaah
add ax,ax
shr bx,1
or ax,bx
But i think a byte based lookup table will be *much* faster, especially on a 68000.
The table would be composed of 256 bytes written in reverse order, you still have to swap the 2 lo/hi bytes tho and use them as indexes.
h.
Are you guys trying to code for speed???
The simplest way (without using a lookup table) is to use two registers.
Load one register with the value you want to bit reverse. You may want to clear the second register.
Shift the first register right once to move the rightmost bit into the C or X flag.
Shift (you probably need to use a rotate instruction) the other register left to shift in the C or X flag into the rightmost bit. It will shift the previous bits left.
Repeat the two shifts until you are done.
The first register won't have the number anymore, and the second register will contain the bit-reversed image.
(Design tactic illustrated here: separate the source of your computations from the result.)
The simplest way (without using a lookup table) is to use two registers.
Load one register with the value you want to bit reverse. You may want to clear the second register.
Shift the first register right once to move the rightmost bit into the C or X flag.
Shift (you probably need to use a rotate instruction) the other register left to shift in the C or X flag into the rightmost bit. It will shift the previous bits left.
Repeat the two shifts until you are done.
The first register won't have the number anymore, and the second register will contain the bit-reversed image.
(Design tactic illustrated here: separate the source of your computations from the result.)
I would have made it like that, the principle is to swap the bits first 4 by 4 then 2 by 2 and at last 1 by 1 using bits masking. I wrote it for the intel proc so my conversion to the 68k may not be accurate.
(and this probably could be optimized).
68000 version:
; In: word in d0
; Out: swapped word in d0
ror.b #4,d0 ; swap bits 4 by 4
ror.w #8,d0
ror.b #4,d0
move.w d0,d1 ; swap bits 2 by 2
and.w #33,d0
and.w #$cccc,d1
add.w d0,d0
add.w d0,d0
lsr.w #2,d1
or.w d1,d0
move.w d0,d1 ; swap bits 1 by 1
and.w #55,d0
and.w #$aaaa,d1
add.w d0,d0
lsr.w #1,d1
or.w d1,d0
Intel version:
; In: word in ax
; Out: swapped word in ax
ror al,4
ror ah,4
ror ax,8
mov bx,ax
and ax,03333h
and bx,0cccch
shl ax,2
shr bx,2
or ax,bx
mov bx,ax
and ax,05555h
and bx,0aaaah
add ax,ax
shr bx,1
or ax,bx
But i think a byte based lookup table will be *much* faster, especially on a 68000.
The table would be composed of 256 bytes written in reverse order, you still have to swap the 2 lo/hi bytes tho and use them as indexes.
h.
It would also be a lot easier to do so as well, are you short on RAM stimpyzu?
the principle is to swap the bits first 4 by 4 then 2 by 2 and at last 1 by 1 using bits masking.
That's exactly what I needed to know, thanks hitchhikr. You have any ideas how to rotate it 90 degrees clockwise? I know that I'm going to have to get every bit from the 16 columns and then turn them into a row. But I need to work on flipping the image first. I'm going to look at your code and break it down so that I can understand what you did.
x86asm The object is to get it to work and to get us to know how the instructions work, so speed is not an issue. We haven't discussed the byte based lookup table yet.
tenkey as I said to x86asm, speed is of no importance. Thanks for your input, it gave me a new perspective on all of this.
Again, if anyone has any ideas on how to rotate the image 90 degrees clockwise, comments and suggestions would truly be appreciated.
You guys are the best. :alright: I've learned more here in a day than I have in 2 weeks of searching like a fool.
The simplest way is still to shift (or rotate) one bit out and rotate it into the byte(s) where you want to store the image. You will need to build the new image in a separate location. I would not be surprised if there are faster ways (after all, this is a pixel-by-pixel method), but this way is simple and easy to validate.
(Oops, this is counterclockwise, but you should be able to convert this procedure into a clockwise version.)
Remember to use the rotate version that uses the X or C flag to shift in the bit that's being copied.
I will illustrate one iteration of the process with a 4x4 matrix:
The above might be called a "collection" method. Below is the "distribution" method.
(Oops, this is counterclockwise, but you should be able to convert this procedure into a clockwise version.)
Remember to use the rotate version that uses the X or C flag to shift in the bit that's being copied.
I will illustrate one iteration of the process with a 4x4 matrix:
[b]initial data[/b]
line 1 = 1234 row 1 = ....
line 2 = 5678 row 2 = ....
line 3 = abcd row 3 = ....
line 4 = efgh row 4 = ....
rotate line 1 right
rotate row 1 left
line 1 = .123 row 1 = ...4
line 2 = 5678 row 2 = ....
line 3 = abcd row 3 = ....
line 4 = efgh row 4 = ....
rotate line 2 right
rotate row 1 left
line 1 = .123 row 1 = ..48
line 2 = .567 row 2 = ....
line 3 = abcd row 3 = ....
line 4 = efgh row 4 = ....
rotate line 3 right
rotate row 1 left
line 1 = .123 row 1 = .48d
line 2 = .567 row 2 = ....
line 3 = .abc row 3 = ....
line 4 = efgh row 4 = ....
rotate line 4 right
rotate row 1 left
line 1 = .123 row 1 = 48dh
line 2 = .567 row 2 = ....
line 3 = .abc row 3 = ....
line 4 = .efg row 4 = ....
Repeat the process with the other rows.
The above might be called a "collection" method. Below is the "distribution" method.
rotate line 1 right
rotate row 1 left
line 1 = .123 row 1 = ...4
line 2 = 5678 row 2 = ....
line 3 = abcd row 3 = ....
line 4 = efgh row 4 = ....
rotate line 1 right
rotate row 2 left
line 1 = ..12 row 1 = ...4
line 2 = 5678 row 2 = ...3
line 3 = abcd row 3 = ....
line 4 = efgh row 4 = ....
rotate line 1 right
rotate row 3 left
line 1 = ...1 row 1 = ...4
line 2 = 5678 row 2 = ...3
line 3 = abcd row 3 = ...2
line 4 = efgh row 4 = ....
rotate line 1 right
rotate row 4 left
line 1 = .... row 1 = ...4
line 2 = 5678 row 2 = ...3
line 3 = abcd row 3 = ...2
line 4 = efgh row 4 = ...1
Repeat the process with the other lines and you will get this rotated image:
48dh
37cg
26bf
15ae
Thanks TENKEY, that part I understand. What I don't know how to do is to "save" the bits, bit by bit so that I can end up putting them all back together to give me a hex number. With a 4x4 matrix I can see that the way you did it is possible, but I don't see how it works with a 16x16 matrix. Unless I'm missing something ?
What I have done, and maybe it's not the right way to do it, is to check every line and then to just "keep" the 1st bits of every line to get my first row.... loop, do the same and keep the 2nd bits of every line for the second column .... and so on.....
But I don't know how to "keep" or store the individual bits to bring the 16 bits back again to create my rows.....aarrrrgg!!!
Maybe I should do it by groups of 4 bits?
Once again, any comments would be appreciated and thank you all for your time!!
What I have done, and maybe it's not the right way to do it, is to check every line and then to just "keep" the 1st bits of every line to get my first row.... loop, do the same and keep the 2nd bits of every line for the second column .... and so on.....
But I don't know how to "keep" or store the individual bits to bring the 16 bits back again to create my rows.....aarrrrgg!!!
Maybe I should do it by groups of 4 bits?
Once again, any comments would be appreciated and thank you all for your time!!
The only difference between 4x4 and 16x16 is that you need to do 16 times, what I've done only 4 times.
=====
There are only two kinds of places that you can "keep" data - registers and memory.
It sounds like you are "unpacking" the bits - testing the bits and storing copies of them somewhere, each in a different location.
If so, then you need to "pack" them to get the images you want - store a copy of each bit in the bit positions you want them at. Clear the destination to all zeroes, and then you can OR a bit mask to set a particular bit position to 1.
=====
The shift-out, shift-in procedure doesn't do any packing/unpacking. Shift a destination enough times and the bit you insert at one end of the row will end up in the right position.
The shift-out, shift-in procedure uses the ROXR and ROXL instructions. The X flag is stored in the CCR, just like the condition codes N, Z, V, and C.
=====
There are only two kinds of places that you can "keep" data - registers and memory.
It sounds like you are "unpacking" the bits - testing the bits and storing copies of them somewhere, each in a different location.
If so, then you need to "pack" them to get the images you want - store a copy of each bit in the bit positions you want them at. Clear the destination to all zeroes, and then you can OR a bit mask to set a particular bit position to 1.
=====
The shift-out, shift-in procedure doesn't do any packing/unpacking. Shift a destination enough times and the bit you insert at one end of the row will end up in the right position.
The shift-out, shift-in procedure uses the ROXR and ROXL instructions. The X flag is stored in the CCR, just like the condition codes N, Z, V, and C.