# PIC res and rrf/rrl question

Status
Not open for further replies.

#### throbscottle

##### Well-Known Member
If I assign a block of bytes using res, eg

Code:
BCD res 4
and I then want to shift the bits, eg

Code:
rrf BCD
will this shift all 4 bytes, or do I also need to do
Code:
rrf BCD+1
rrf BCD+2
rrf BCD+3
????????

#### throbscottle

##### Well-Known Member
That's what I originally thought, then wondered if it was different where a whole block was reserved. I'd been using equ and lots of labels so this way feels a bit alien to me.
Thanks Ian

#### jpanhalt

##### Well-Known Member
You can set up a loop and use indirect addressing to do it. Not any quicker though. Also, if you use rrf be sure to clear the carry bit if you don't want it in your first byte. If you use an enhanced midrange chip (e.g., 16F1xxx) you can use lsrf, which avoids rotating the carry bit into your byte.

#### throbscottle

##### Well-Known Member
I'm using indirect addressing to do more complicated manipulation where an arbitrary nibble is selected, but it's only 4 bytes so agreed a loop doesn't help for rotation.
One day I'll look at those mid-range chips...

#### jpanhalt

##### Well-Known Member
Doesn't that depend on endian? (Edit: Assuming byte+1 refers to a ram location.)

While on the topic (so to speak), is there standardized nomenclature for naming the four bytes?
For example, with just 2 bytes MSB and LSB seem pretty widely accepted. Three bytes: USB,MSB, and LSB (In that case, U= uppermost.) But that is not universal. Awhile back, I came across MMSB, MSB, and LSB (high to low).

For four bytes, I have seen, high to low, MSB,MMSB,MLSB, and LSB. In that case, the leading M of a pair = middle.

Last edited:

#### atferrari

##### Well-Known Member
Doesn't that depend on endian?

While on the topic (so to speak), is there standardized nomenclature for naming the four bytes?
For example, with just 2 bytes MSB and LSB seem pretty widely accepted. Three bytes: USB,MSB, and LSB (In that case, U= uppermost.) But that is not universal. Awhile back, I came across MMSB, MSB, and LSB (high to low).

For four bytes, I have seen, high to low, MSB,MMSB,MLSB, and LSB. In that case, the leading M of a pair = middle.

#### jpanhalt

##### Well-Known Member
atferrari

Sorry, I was being picky and/or read the identifiers differently. I doubt there is little disagreement that ACC0, ACC1,...is low to high. However, byte+1 might refer to a ram location. There is no standard that the most significant byte be at a higher ram location. I modified my comment accordingly. I need to wait until my second cup of coffee in the mornings.

#### Pommie

##### Well-Known Member
I've always preferred little endian but was happy either way. What confuses me is middle endian like the US uses for dates - middle number first - 1st April = 4,1,2015!!

Mike.

#### jpanhalt

##### Well-Known Member
It's the way it was done in 1776. Worked then, so why change it?

#### throbscottle

##### Well-Known Member
It's because "April first" is easier to say than "the first of April". It saves two whole words so you can convey more information in the same time. So it just got written that way. Well, presumably, who am I to say?
It's a good point about how you name the bytes. I got confused. I originally used four labels bcd0 to bcd3 (for 8 digits of packed bcd) before I looked into the res directive a bit more, and forgot which end was which.
It gets even more confusing because I realised if I write to the display msb first leading zero blanking becomes much easier (so, in a big endian way).
On the same subject, when updating a display by keying in numbers, the cursor should automatically move to the next digit. I'm not sure which is best or more natural, have it move left or right? I'm inclined to right, but what's "normal"?
Remember using rrf start at BCD4
Yeah I'd have worked it out eventually...

Status
Not open for further replies.