( Reverse and Array ) .. in Assembly language ?

Hi everyone !

I just started studying the assembly language ..
I have this question in my assignment but I'm not sure if my answer is correct
I'm afraid that I didn't get the question very well -_-

so please help me guys


this is the question

Use a loop with indirect or indexed addressing to reverse "
the elements of an integer array. Do not copy the elements to another array.
Use the SIZEOF, TYPE and LENGTHOF operators to make the program.



and this is my answer

TITLE " question 3 - revese and array"
.686
.model flat, stdcall
.stack
INCLUDE irvine32.inc

.DATA                                   
array  dword  1, 2, 3, 4

.CODE
main PROC

mov ecx, 2
mov esi, 3
mov edi, 0


L1:
     mov eax, array[esi * type array ]
     xchg eax, array[edi]
     mov array[esi * lengthof array ], eax
      mov edi, type array
      mov esi, 2

loop L1
call dumpregs

; check
mov eax, array
mov ebx, array[4]
mov ecx, array[8]
mov edx, array[12]
call dumpregs


exit
main ENDP
END main





waiting for your help 
thank you 

dreams,,

sort by: active | newest | oldest
1.) No comments,
2.) No assembler specified.
3.) Using an unknown library call,
4.) Using an unspecified processor.

5.) Don't you have a simulator to test your code in ?

CSE251 (author)  steveastrouk5 years ago
I'm working with ' Macro Assembler from Microsoft '
actually I run my programs on DOS prompt ^-^"

did you get the question ? I hope you can explain the concept to me
So does your answer work, or not ?
CSE251 (author)  steveastrouk5 years ago
yes it works
So you've copied it from somewhere and don't understand it ? Do you understand indirect addressing ?

Steve
CSE251 (author)  steveastrouk5 years ago
no Mr.Steve .. I did it by myself
but I'm asking to make sure that my answer is what the question want

I mean in the question he said use the type, lengthof and sizeof operators
is it mean that I have to use them in the index ? or something else !

and does the array reverse mean for example
if the array was 1,2,3,4
should the output be 4,3,2,1 ??
If you've written it, and it "works", did it give you 4321 ? Then you've reversed the array.

You've used the commands suggested too, so it looks OK to me. It would be a better test IMHO, if you ran 10 elements or more in the test.
CSE251 (author)  steveastrouk5 years ago
yes it gave me 4,3,2,1

OK I'll try it with more elements now
thank you very much Mr.Steve ^^
I really appreciate your help


For something instructional like this, and in general anyway USE COMMENTS in your code, to remind you what's happening, especially if you're doing something for the first time. Admittedly, it can get a bit stupid. I've seen code like this;

INC X ;Add 1 to X
- which, while true, isn't terribly useful !

If you can use meaningful variable names, using EQU, you can also improve code legibility.

Steve
CSE251 (author)  steveastrouk5 years ago
You know I used to write comments in JAVA
and honestly it was very useful for me

thank you for reminding me about it ^-^ .. I'll make sure to not forget them

dreams,