|
1 | | -/* |
2 | | - R10 is set to the address of arr, and R11 is set to the address of arr2. |
| 1 | +;---------------------------------------------- |
| 2 | +; R10 is set to the address of arr, and R11 is set to the address of arr2. |
3 | 3 |
|
4 | | - R12 is used as the index for the last element of arr (assuming that arr has 50 elements, 0-based index). |
| 4 | +; R12 is used as the index for the last element of arr (assuming that arr has 50 elements, 0-based index). |
5 | 5 |
|
6 | | - The loop (reverseLoop) copies elements from the end of arr to the beginning of arr2, |
7 | | - effectively reversing the order of the elements. |
| 6 | +; The loop (reverseLoop) copies elements from the end of arr to the beginning of arr2, |
| 7 | +; effectively reversing the order of the elements. |
8 | 8 |
|
9 | | - After running this code, arr2 will contain the reverse order of the elements that were originally in arr. |
| 9 | +; After running this code, arr2 will contain the reverse order of the elements that were originally in arr. |
10 | 10 |
|
11 | | - You can adjust the size and starting addresses of arr and arr2 based on your specific requirements. |
12 | | -*/ |
13 | | - |
14 | | - |
15 | | -; Allocate space in memory for arr and arr2 |
16 | | -a r r . s p a c e 100 |
17 | | -a r r 2 . s p a c e 100 |
| 11 | +; You can adjust the size and starting addresses of arr and arr2 based on your specific requirements. |
| 12 | +;---------------------------------------------- |
18 | 13 |
|
19 | 14 | ; Initialize registers |
20 | 15 | mov.w #arr, R10 ; Set R10 to the address of arr |
21 | 16 | mov.w #arr2, R11 ; Set R11 to the address of arr2 |
22 | 17 | mov.w #49d, R12 ; Set R12 as the index for the last element of arr (0-based index) |
23 | 18 |
|
24 | 19 | ; Start the loop to reverse arr and store it in arr2 |
25 | | -reverseLoop: |
26 | | - ; Copy the element from arr to arr2 |
27 | | - mov.w 0(R10), R13 ; Load the element from arr |
28 | | - mov.w R13, 0(R11) ; Store it in arr2 |
| 20 | +reverseLoop ; Copy the element from arr to arr2 |
| 21 | + mov.w 0(R10), R13 ; Load the element from arr |
| 22 | + mov.w R13, 0(R11) ; Store it in arr2 |
29 | 23 |
|
30 | | - ; Move the pointers |
31 | | - add #2d, R10 ; Move R10 to the next element in arr |
32 | | - sub #2d, R11 ; Move R11 to the previous position in arr2 |
| 24 | + ; Move the pointers |
| 25 | + add #2d, R10 ; Move R10 to the next element in arr |
| 26 | + sub #2d, R11 ; Move R11 to the previous position in arr2 |
33 | 27 |
|
34 | | - ; Check if we have copied all elements |
35 | | - cmp.w R10, R11 ; Compare R10 with R11 |
36 | | - jl reverseLoop ; If R10 is less than R11, continue the loop |
| 28 | + ; Check if we have copied all elements |
| 29 | + cmp.w R10, R11 ; Compare R10 with R11 |
| 30 | + jl reverseLoop ; If R10 is less than R11, continue the loop |
37 | 31 |
|
38 | 32 | ; End of the program |
39 | 33 |
|
40 | 34 |
|
| 35 | +; Allocate space in memory for arr and arr2 |
| 36 | +arr .space 100 |
| 37 | +arr2 .space 100 |
41 | 38 |
|
0 commit comments