0

I have an task to generate an Random numbers in assembly language just like rand function in c Language but in assembly language i had to extract the B0,B5,B6 bit from the 8 bit data number and perform the following tasks on that bit

  1. EOR B5 and B6
  2. EOR B0 and result of (B5 ^ B6)
  3. And result of task 2 will be replace to MSB bit of the 8 bit data.

I've done the first 2, but can I replace the MSB bit with the result of task 2?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
josh
  • 9
  • 2
  • ARM may have a bit-field insert instruction to replace a bit without the usual AND to clear the old value and ORR to set a new 0 or 1 value. Otherwise do that. The linked duplicate includes an implementation of setting a `newbit` at a given position in an existing value. – Peter Cordes Apr 19 '20 at 08:04
  • That C Q&A had over-complicated looking expressions. I'd recommend https://graphics.stanford.edu/~seander/bithacks.html#MaskedMerge to merge the low bits from the old value with the high bit from another register, as per the other two Q&As I added links to. My answer on [Swapping bits at a given point between two bytes](https://stackoverflow.com/a/50839334) explains the details of how the masked xor bitdiff trick works to implement a bit blend. (Or a bit swap if you apply it both ways). – Peter Cordes Apr 19 '20 at 08:26

0 Answers0