View previous topic :: :: View next topic

Author 
Message 
alokagarwaljgd
New User
Joined: 02 Jun 2006 Posts: 28




Hi,
Can any body help me out with below two questions. It was asked in one of the quiz.
1) What will happen if we shift n bits to left using SLL and then again if we use SRL to shift n bits to right?
2) What does the following instruction do?
EX 0,SIGNWK
SIGNWK MVC VAR+4(2),=X'000C'
XC VAR2(5),VAR3
where VAR, VAR2 and VAR3 can be assumed as already defined valid variables.
Any help for the above is highly appreciated.
Thanks,
Alok 

Back to top 




Bill Woodger
DFSORT Moderator
Joined: 09 Mar 2011 Posts: 7236




Try a bit of experimentation.
Open a new member in your editor.
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. 

Back to top 


alokagarwaljgd
New User
Joined: 02 Jun 2006 Posts: 28




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.
Thanks,
Alok 

Back to top 


Bill Woodger
DFSORT Moderator
Joined: 09 Mar 2011 Posts: 7236




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. 

Back to top 


enricosorichetti
Global Moderator
Joined: 14 Mar 2007 Posts: 10203 Location: italy




Quote: 
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.
the shift logical will disregard the sign and work on 32/64 bits
the shift will will work on 31/63 bits and preserve the sign
shift left is the non arithmetic way for the multiplication by two
shift right is the non arithmetic way for the integer division by two
take the time to meditate on the POP SA22783208 

Back to top 


Bill Woodger
DFSORT Moderator
Joined: 09 Mar 2011 Posts: 7236




As enrico is alluding, I've been a little slack with my terminology. Sorry about that. 

Back to top 


PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2422 Location: Netherlands, Amstelveen




Dont use the shift too much else people are going to say :
There are some shifty fellows on this forum.
Especially when you shift leftish. 

Back to top 


alokagarwaljgd
New User
Joined: 02 Jun 2006 Posts: 28




Quote: 
Quote: 
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?
Thanks,
Alok 

Back to top 


Bill Woodger
DFSORT Moderator
Joined: 09 Mar 2011 Posts: 7236




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 wordplay joke, nothing to do with anything. 

Back to top 


dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne




enrico already explained that there is an important difference between the shift bits logical and shift bits instructions.
attention to detail...... 

Back to top 


enricosorichetti
Global Moderator
Joined: 14 Mar 2007 Posts: 10203 Location: italy




just plain stubborness..
Your example of not losing 0/1 s is a specific case, not the general one
and ... I forgot to clarify a shift right ( arithmetical shift right will propagate the sign
(remember negative numbers are in 2s complement )
no shifting will change the sign, read about LNR
again before posting Your wrong conclusions read for the umpteen time the manual
to save some of Your precious time here is the link for the download
https://www304.ibm.com/support/docview.wss?uid=isg2b9de5f05a9d57819852571c500428f9a 

Back to top 


alokagarwaljgd
New User
Joined: 02 Jun 2006 Posts: 28




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.
Thanks,
Alok 

Back to top 


Ed Goodman
Active Member
Joined: 08 Jun 2011 Posts: 556 Location: USA




good use for bit shifting: reading/writing flag bits.
flag byte has 10010001
do this loop
rightmost bit = AND with 00000001
shift right 

Back to top 



