Reverse the elements in a given array

Click For Summary

Discussion Overview

The discussion revolves around a homework problem that involves writing a sequence of statements to reverse the elements of an array, specifically in the context of assembly language programming. Participants are seeking feedback on their code attempts and clarifications regarding the implementation.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant presents their attempt at a solution and requests feedback on its correctness.
  • Another participant questions whether the code is in assembly language and if it can be executed.
  • A subsequent reply confirms that the code is indeed assembly.
  • A later response critiques the initial attempt, noting that the code does not work but is close to being correct. It points out the absence of a loop statement at the end of the loop body and suggests using a debugger to verify the program's functionality and inspect the array contents after execution.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the correctness of the initial code, as there are critiques and suggestions for improvement, indicating that multiple views on the solution's validity exist.

Contextual Notes

There are limitations regarding the clarity of the code provided, as well as the specific assumptions about the array's initial state and the expected output format. The discussion does not resolve these aspects.

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 :
reverse.png

Could somebody check my answer please ?
 

Attachments

  • reverse.png
    reverse.png
    6.7 KB · Views: 774
Physics news on Phys.org
Is this assembly? Are you able to run the code?
 
scottdave said:
Is this assembly?
yes
 
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

Similar threads

  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K