[algogeeks] Re: Symantec ques - Find max without comparing

2011-09-17 Thread Dave
@Silva:

AND A,0  // sets register A to zero
NOT A // complements all bits of A

The result is that A is filled with 1-bits, giving MAXINT.

Dave

On Sep 17, 6:06 am, siva viknesh sivavikne...@gmail.com wrote:
  Two registers A and B. Initial Contents of the registers are unknown.
 Write a program to find MAXINT - The maximum positive unsigned integer
 The instructions available are:
 SHR reg1, op1
 ADD reg1, op1
 AND reg1, op1
 NOT reg1.
 Op1 may represent any number or register.
 (Hint: The Shift operation is a logical shift, not arithmetic shift.)

 ..solution plz .. i tried but unable to arrive

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Symantec ques - Find max without comparing

2011-09-17 Thread siva viknesh
@dave .. I think we should find maximum of 2 no.s (present in 2
registers)plz provide solution for this...correct me if i m wrong

On Sep 17, 8:50 pm, Dave dave_and_da...@juno.com wrote:
 @Silva:

 AND A,0              // sets register A to zero
 NOT A                 // complements all bits of A

 The result is that A is filled with 1-bits, giving MAXINT.

 Dave

 On Sep 17, 6:06 am, siva viknesh sivavikne...@gmail.com wrote:







   Two registers A and B. Initial Contents of the registers are unknown.
  Write a program to find MAXINT - The maximum positive unsigned integer
  The instructions available are:
  SHR reg1, op1
  ADD reg1, op1
  AND reg1, op1
  NOT reg1.
  Op1 may represent any number or register.
  (Hint: The Shift operation is a logical shift, not arithmetic shift.)

  ..solution plz .. i tried but unable to arrive

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Symantec ques - Find max without comparing

2011-09-17 Thread Dave
@Siva: The problem clearly states that we are to find MAXINT - The
maximum positive unsigned integer. It doesn't say that we are to find
the maximum of any particular integers. In particular, it says that
the initial contents of A and B are unknown, not that the initial
contents are two integers that we are to find the greater of.

Dave

On Sep 17, 11:01 am, siva viknesh sivavikne...@gmail.com wrote:
 @dave .. I think we should find maximum of 2 no.s (present in 2
 registers)plz provide solution for this...correct me if i m wrong

 On Sep 17, 8:50 pm, Dave dave_and_da...@juno.com wrote:



  @Silva:

  AND A,0              // sets register A to zero
  NOT A                 // complements all bits of A

  The result is that A is filled with 1-bits, giving MAXINT.

  Dave

  On Sep 17, 6:06 am, siva viknesh sivavikne...@gmail.com wrote:

    Two registers A and B. Initial Contents of the registers are unknown.
   Write a program to find MAXINT - The maximum positive unsigned integer
   The instructions available are:
   SHR reg1, op1
   ADD reg1, op1
   AND reg1, op1
   NOT reg1.
   Op1 may represent any number or register.
   (Hint: The Shift operation is a logical shift, not arithmetic shift.)

   ..solution plz .. i tried but unable to arrive- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Symantec ques - Find max without comparing

2011-09-17 Thread siva viknesh
thanks a lot dave for clarification :) but this is there any
possibility to find max of 2 no.s using those instructions
alone(assuming contents of registers are +ve ) ?

I found a solution finding difference of 2 no.s (SUB is required) and
checking for the whether a-b is +ve or -ve using '' and SHR
operatorIs there any possibility with these instructions?

On Sep 17, 9:08 pm, Dave dave_and_da...@juno.com wrote:
 @Siva: The problem clearly states that we are to find MAXINT - The
 maximum positive unsigned integer. It doesn't say that we are to find
 the maximum of any particular integers. In particular, it says that
 the initial contents of A and B are unknown, not that the initial
 contents are two integers that we are to find the greater of.

 Dave

 On Sep 17, 11:01 am, siva viknesh sivavikne...@gmail.com wrote:







  @dave .. I think we should find maximum of 2 no.s (present in 2
  registers)plz provide solution for this...correct me if i m wrong

  On Sep 17, 8:50 pm, Dave dave_and_da...@juno.com wrote:

   @Silva:

   AND A,0              // sets register A to zero
   NOT A                 // complements all bits of A

   The result is that A is filled with 1-bits, giving MAXINT.

   Dave

   On Sep 17, 6:06 am, siva viknesh sivavikne...@gmail.com wrote:

 Two registers A and B. Initial Contents of the registers are unknown.
Write a program to find MAXINT - The maximum positive unsigned integer
The instructions available are:
SHR reg1, op1
ADD reg1, op1
AND reg1, op1
NOT reg1.
Op1 may represent any number or register.
(Hint: The Shift operation is a logical shift, not arithmetic shift.)

..solution plz .. i tried but unable to arrive- Hide quoted text -

  - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Symantec ques - Find max without comparing

2011-09-17 Thread Dave
@Siva: Note that in 2-s complement arithmetic, -b = ~b + 1.
So a - b = a + (-b) = a + (~b + 1) = (a + ~b) + 1.
Thus, a - b can be written as

NOT B
ADD A,B  // reading this as add B to A, i.e., result is in A.
ADD A,1

Dave

On Sep 17, 11:15 am, siva viknesh sivavikne...@gmail.com wrote:
 thanks a lot dave for clarification :) but this is there any
 possibility to find max of 2 no.s using those instructions
 alone(assuming contents of registers are +ve ) ?

 I found a solution finding difference of 2 no.s (SUB is required) and
 checking for the whether a-b is +ve or -ve using '' and SHR
 operatorIs there any possibility with these instructions?

 On Sep 17, 9:08 pm, Dave dave_and_da...@juno.com wrote:



  @Siva: The problem clearly states that we are to find MAXINT - The
  maximum positive unsigned integer. It doesn't say that we are to find
  the maximum of any particular integers. In particular, it says that
  the initial contents of A and B are unknown, not that the initial
  contents are two integers that we are to find the greater of.

  Dave

  On Sep 17, 11:01 am, siva viknesh sivavikne...@gmail.com wrote:

   @dave .. I think we should find maximum of 2 no.s (present in 2
   registers)plz provide solution for this...correct me if i m wrong

   On Sep 17, 8:50 pm, Dave dave_and_da...@juno.com wrote:

@Silva:

AND A,0              // sets register A to zero
NOT A                 // complements all bits of A

The result is that A is filled with 1-bits, giving MAXINT.

Dave

On Sep 17, 6:06 am, siva viknesh sivavikne...@gmail.com wrote:

  Two registers A and B. Initial Contents of the registers are unknown.
 Write a program to find MAXINT - The maximum positive unsigned integer
 The instructions available are:
 SHR reg1, op1
 ADD reg1, op1
 AND reg1, op1
 NOT reg1.
 Op1 may represent any number or register.
 (Hint: The Shift operation is a logical shift, not arithmetic shift.)

 ..solution plz .. i tried but unable to arrive- Hide quoted text -

   - Show quoted text -- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Symantec ques - Find max without comparing

2011-09-17 Thread siva viknesh
thats a nice solution dave :)

On Sep 17, 9:26 pm, Dave dave_and_da...@juno.com wrote:
 @Siva: Note that in 2-s complement arithmetic, -b = ~b + 1.
 So a - b = a + (-b) = a + (~b + 1) = (a + ~b) + 1.
 Thus, a - b can be written as

 NOT B
 ADD A,B      // reading this as add B to A, i.e., result is in A.
 ADD A,1

 Dave

 On Sep 17, 11:15 am, siva viknesh sivavikne...@gmail.com wrote:







  thanks a lot dave for clarification :) but this is there any
  possibility to find max of 2 no.s using those instructions
  alone(assuming contents of registers are +ve ) ?

  I found a solution finding difference of 2 no.s (SUB is required) and
  checking for the whether a-b is +ve or -ve using '' and SHR
  operatorIs there any possibility with these instructions?

  On Sep 17, 9:08 pm, Dave dave_and_da...@juno.com wrote:

   @Siva: The problem clearly states that we are to find MAXINT - The
   maximum positive unsigned integer. It doesn't say that we are to find
   the maximum of any particular integers. In particular, it says that
   the initial contents of A and B are unknown, not that the initial
   contents are two integers that we are to find the greater of.

   Dave

   On Sep 17, 11:01 am, siva viknesh sivavikne...@gmail.com wrote:

@dave .. I think we should find maximum of 2 no.s (present in 2
registers)plz provide solution for this...correct me if i m wrong

On Sep 17, 8:50 pm, Dave dave_and_da...@juno.com wrote:

 @Silva:

 AND A,0              // sets register A to zero
 NOT A                 // complements all bits of A

 The result is that A is filled with 1-bits, giving MAXINT.

 Dave

 On Sep 17, 6:06 am, siva viknesh sivavikne...@gmail.com wrote:

   Two registers A and B. Initial Contents of the registers are 
  unknown.
  Write a program to find MAXINT - The maximum positive unsigned 
  integer
  The instructions available are:
  SHR reg1, op1
  ADD reg1, op1
  AND reg1, op1
  NOT reg1.
  Op1 may represent any number or register.
  (Hint: The Shift operation is a logical shift, not arithmetic 
  shift.)

  ..solution plz .. i tried but unable to arrive- Hide quoted text -

- Show quoted text -- Hide quoted text -

  - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.