Back to Browse

RISC programming swapping example

5 views
Apr 24, 2026
24:45

This problem gives a list of 32-bit numbers stored in memory. For each number, we need to: Swap the upper 16 bits and lower 16 bits Example: Input : 0xAAAA5555 Output : 0x5555AAAA So basically: Top half ↔ Bottom half (exchange) What the Program Does 1️Read the list and number of elements (N) 2️Take one number from the list 3️Extract lower 16 bits ANDI R4, R3, 0xFFFF 4️Move it to upper position SLL R4, R4, 16 5️Extract upper 16 bits SRL R5, R3, 16 6️ Clean extra bits ANDI R5, R5, 0xFFFF 7️ Combine both parts OR R6, R4, R5 8️Store result back and move to next number Simple Logic (Easy to Remember) Lower part → shift left → becomes upper Upper part → shift right → becomes lower Combine both → final swapped number 🔹 Summary “The program swaps the upper and lower 16-bit halves of each 32-bit number in a list using masking and shifting operations.”

Download

0 formats

No download links available.

RISC programming swapping example | NatokHD