I am trying load a word from a data block and transfer it to an output byte,
You are trying to load a 16-bit word into an 8-bit byte... hmmmm....
however I only want to write the first 4 bits of the db-word to the first 4 bits of the output word
However, you only want to copy the first four bits of the original double-word??? or double-byte-word??? into the first four bits of the output word... a 16-bit word?
My first comment is that you are pretty sloppy with your terminology. You would do yourself a great favor to clear up your thinking and use the right terms... it can only help you, if you do.
Now, If I read you right, I think you want to copy the first 4-bits from one word into the first four bits of another word. Is that so?
Let's try it with bytes...
(It works the same with words)
This is in generic terms rather than S7-specific.
Source Byte (V.b100)
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
| H | G | F | E | D | C | B | A |
+---+---+---+---+---+---+---+---+
AND MASK (V.b200)
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
+---+---+---+---+---+---+---+---+
AND Result (V.b300)
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
| 0 | 0 | 0 | 0 | D | C | B | A |
+---+---+---+---+---+---+---+---+
V.b300 = V.b100 AND V.b200
The source word V.b100 is still intact as...
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
| H | G | F | E | D | C | B | A |
+---+---+---+---+---+---+---+---+
.
Now, if you want to use the rest of the source word somewhere else,
the word is there and you can mask-off the source as you need to
draw out any other bits.
If you then want to acquire the other four bits...
Source Byte (V.b100)
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
| H | G | F | E | D | C | B | A |
+---+---+---+---+---+---+---+---+
AND MASK (V.b210)
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
+---+---+---+---+---+---+---+---+
AND Result (V.b310)
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
| H | G | F | E | 0 | 0 | 0 | 0 |
+---+---+---+---+---+---+---+---+
V.b310 = V.b100 AND V.b210
...or any combination you want.
.
If you then want those bits (5-8), in V.b310, to be in the
first four bits (1-4), in V.b310, use Rotate.
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
| 0 | 0 | 0 | 0 | H | G | F | E |
+---+---+---+---+---+---+---+---+
V.b310 = Rotate (1-nibble) V.b310
.
That is, Rotate V.b310 by 1-nibble and...
write the result back into V.b310
I can't remember if that will work at the byte level...
I think it will...
but it will certainly work at the word level which is where
you seem to be working... maybe... I'm really not sure.
If you only want to extract a single bit and place it into the LSB
position (bit-0) then create a single bit mask, perform the AND and
then use Shift-Right.
Anytime you want to do any kind of exercise like this, do it yourself
first, with a pencil and paper. Pay attention to what you are doing,
step by step. Then tell the processor to do the same thing.
But you must have your terminology straight! If you programmed the
routine in the same manner you asked the question... well, no wonder
it doesn't work.