You have correctly implemented the first part where the program accepts inputs and fills the array(tab). However, there are issues in the sorting and swapping logic, particularly in how you modify and access memory dynamically.
Key Issues:
Dynamic Address Calculation: When trying to modify the contents of dyn_addr and dyn2_addr, you directly store the value of the calculated address instead of modifying the actual memory content pointed to by those addresses.
Swapping Mechanism: LMC does not allow direct manipulation of arbitrary addresses. To swap two values, you need to correctly load, temporarily store, and overwrite the data at those addresses.
Address Resolution in Self-Modifying Code: Your program attempts to store and retrieve values by calculating dyn_addr and dyn2_addr, but does not resolve them to modify the actual contents of tab.
Suggested Fix:
To fix the issue, you need to:
1.Use a temporary instruction space in the LMC memory to dynamically point and modify array elements.
2.Correctly load and store values during the swapping phase using calculated addresses.