0

Write a MIPS program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.

the answer must be MIPS code

wang
  • 1
  • By what you're showing, you haven't started or tried, instead just copied a homework problem statement. Do you want someone to do your assignment for you, or, do you have an actual technical question. – Erik Eidt Nov 24 '22 at 16:51
  • That's a tricky one, since MIPS has no carry flag. – puppydrum64 Nov 28 '22 at 15:59
  • You can use the `ror` pseudo-instruction to rotate bits and `andi $reg,$reg,1` to test a bit. That should get you started. – puppydrum64 Dec 02 '22 at 12:08

1 Answers1

0

just XOR the target number with a 1 string of the same length, eg to flip 1010, 1010 XOR 1111 = 0101 docs

nero
  • 1
  • 3
  • I don't think that works, since it sounds to me as though it's less of a bit flip and more of a rotate, e.g. if you start with `11` and you exchange those two you still get `11` – puppydrum64 Nov 28 '22 at 15:58