Fill a single line with a single character, all the way to the end of the line.

Do a shift left of a number of characters, like "<5". Then do a shift right ">5".

Same thing is happening. Try it swapping the commands around as well if you like.

For your second question, look up the instructions in the POP, if you don't know them, and get an idea there. Search the Assembler forum for EX (Execute). If you get stuck, let use know where. If you get an answer, let us know as well.

1) I did the left shift and right shift as suggested by you. I filled the line completely with 1s. Then on doing left shift (let's say 3 times), first time, 3 charcters (say 111) are removed from the line on extreme left side and 3 blank spaces are filled on extreme right side of the line. Again after doing right shift ( 3 times), the three blank spaces are replaced by three ones and again three blank spaces get created on extreme left side. So, basically it is creating 3 blank spaces (or insert 3 zeroes, in case of SLL/SRL) when we shift it either to right or left.

After one time execution of SRL and SLL, it will contain the same number of ones and zeroes. However, the resultant value of the number will change in each case. I understand the above logic and the way SRL and SLL works but does shifting of n bits to left and then to right make sense in any case or is there any situation in real life, when we make use of it?

2) Coming to my second question, I understand that EX with register 0 as first operand doesn't change anything, it will simply execute the target instruction, (MVC in this case). Since, it works on single instruction, the control after executing the MVC will not execute the XC instruction and will be going back to execute the instruction after the EX instruction. Please let me know if my understanding is correct.

Yep, I think that is about it. Just a little more work on the EX to understand whether the register is relevant for the "doesn't change anything" and the trickiest bit is understanding the "doesn't change anything". Absolutely correct about the XC.

As to uses of the Shifts, and the use like described, they are many.

Take a -ve binary halfword. Want to make it positive with the same absolute value? Shift left one bit, shift right one bit.

it will contain the same number of ones and zeroes.

it will not....

any shift logical operation will lose the shifted out bits, and the <shifted in> bits will all be zeroes.

What I meant by saying "After one time execution of SRL and SLL, it will contain the same number of ones and zeroes. However, the resultant value of the number will change in each case." is that if we have R2 = 0111 and if we execute the following instructions

1) SLL 2,1
After execution, R2 = 1110, which contains 3 ones and 1 zero
Then if we execute the below instruction

2) SRL 2,1
After execution, R2 = 0111, which again contains 3 ones and 1 zero

Hence, in each of the above case, we can see that after one time execution of SRL and SLL, they have same number of ones and zero
i.e. 3 and 1 respectively.

I am aware of the use of shift instruction for the purpose of multiplication and division but what I was seeking was its practical use/purpose with respect to specifically SLL and SRL shifting n bits to left and right side respectively.

Bill,

Thanks for your confirmation with respect to EX question.

I also did as suggested by you for shift instruction. i.e. I had taken a -ve binary halfword for -3 which is
1111 1111 1111 1101

After shifting left one bit, we have
1111 1111 1111 1010

Then after shifting the above resultant to right by one bit, we have
0111 1111 1111 1101

but this obtained value is not equal to the positive value that we want i.e. 3

Can you please help here, is there anything wrong in my calculations?

Peter,

I am sorry, I didn't get what you meant. Can you please explain?

Posted: Thu Aug 04, 2011 11:47 am Post subject: Reply to: SHIFT instructions

Alok,

Because I was unthinking, I'm sorry. I was struggling for an example of why you'd you SLL followed by SRL and thought "aha, clobber the sign", without thinking that you'd end up with a huge positive bearing no useful relationship to the original number. My mistake.

Peter's comment was just a word-play joke, nothing to do with anything.

Posted: Fri Aug 05, 2011 12:19 am Post subject: Reply to: SHIFT instructions

Enrico,

I never said that shifting to left and right will not lose 0/1. It will definitely do that and in my example also it is doing that.

Let me give another example, say
if we have R2 = 1110 and if we execute the following instructions

SLL 2,1
After execution, R2 = 1100, which contains 2 ones and 2 zeros
Then if we execute the below instruction

SRL 2,1
After execution, R2 = 0110, which again contains 2 ones and 2 zeros

In the above example, shifting to left resulted in loss of 1 and introduction of 0 at end and then shifting to right resulted in loss of 0 at extreme right and introduction of 0 in the beginning.
Hence, in each of the above case, we can see that after the execution of SRL and SLL, they have same number of ones and zero
i.e. 2 and 2 respectively.

I think there was some confusion here, when I am saying "After one time execution of SRL and SLL, it will contain the same number of ones and zeroes" I am not comparing the number of 0/1 s produced in the register after execution with the first initial value of the register( 3 ones and 1 zero in this example). I am only comparing the number of 0/1 s produced in the register (R2 = 1100, which contains 2 ones and 2 zeros, in this example) after once SLL executes with that of number of 0/1 s produced in the register (R2 = 0110, which again contains 2 ones and 2 zeros, in this example) after a successive SRL executes.

I also understand the sign propagation in case of arithmetic shifts. But, here my main focus from the beginning was logical shifts (n bit shifts of SLL followed by n bit shifts of SRL). And since, Bill suggested me to take a -ve binary halfword and try out the shifts. I did the same as suggested by him to understand if that can act as a practical use/purpose of shifting n bits to left using SLL and then immediately followed by SRL for shifting n bits to right.