Reverse the elements in a given array

3 replies · 2K views · last reply
Fatima Hasan
Messages
315
Reaction score
14

Homework Statement


Write a sequence of statements to REVERSE the elements of array X1.

Homework Equations


-

The Attempt at a Solution


Here's my work :
Assembly language program listing in an Irvine32 x86 style: a .data section defines word array X1 with values 10h through 1Ah, and main PROC contains a loop using ecx, esi and edi to swap elements from both ends.

Could somebody check my answer please ?
 
Attachments
  • Assembly language program listing in an Irvine32 x86 style: a .data section defines word array X1 with values 10h through 1Ah, and main PROC contains a loop using ecx, esi and edi to swap elements from both ends.
    reverse.png
    6.7 KB · Views: 799
Fatima Hasan said:
Could somebody check my answer please ?
Your code doesn't work, but you're not far off.
It looks like you are setting up a loop to run 5 times, and you have a label at the start of your loop, but you are missing a loop statement at the bottom of the loop body, and whose target is the label. After you fix that, I believe your code will do what it's supposed to do.
When you get your code to run, you really should use your debugger to see if the program is working correctly. Set a breakpoint on the first line after the loop statement, and inspect the contents of the array. After the loop finishes the array contents should be 1ah, 90h, 80h, ..., 10h.
 
Last edited:
  • Like
Likes   Reactions: berkeman and scottdave