I am taking a programming class in college, and I am having a lot of trouble with this assignment the teacher is not willing to help and I don't know where to go for help.
These are the instructions
This project has three loops.
1. Create a DWORD integer array that is 16 elements long.
2. The first loop: Ask the user to enter 16 numbers to fill the array.
3. The second loop: Reverse the second half of the array.
4. The third loop: Use a loop to display the array, to show that the second half was, indeed, reversed. As with step 1, the loop has to access the array from the first element to the last and display the numbers stored in memory. Use a message that reads "The array after the second half was reversed is: "
Use the SIZEOF, TYPE, and LENGTHOF operators to make the program flexible to support the array size and type being changed in the future. If I change the array size in your code to any even number size, say 8, your program should still run correctly, reversing the last 4 elements of the array. Do not use hard-coded numbers like 16 or 8. Use registers and variables for these numbers.
Here is an example:
Please enter 16 numbers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
The array after the second half was reversed is: "
1
2
3
4
5
6
7
8
16
15
14
13
12
11
10
9
Commenting:
You are required to comment every line of code you write. Failure to comment will force a grade reduction of 25%
A Strategy For Solving Problem
This problem asks you to reverse a section of an array. This means that you are not supposed to copy numbers to another array. The best way to approach this is to have addressing that will refer to the first number of the array section to be reversed and addressing that will refer to the last number of the array. You simply swap the numbers at each location then increment the address at the front and decrement the address at the end at each loop pass.
How to determine how much to loop when reversing? Simply divide the length of the array in half, because you need to reverse just the last half of the array. Then divide it again in half, because you swap pairs of numbers.
Division
Here is how to do division:
move into the eax the value you want divided
move into another register the value you want to divide by.
Then simply use div instruction.
The result will be in the eax and the remainder will be in the edx. Since we have here only even numbers and the divide is by 2 or by 4 the reminder will be zero.
Here is an example
mov edx, 0
mov eax 20
mov ecx, 3
div ecx ;Divide eax by 3
eax will have 6 and the the edx will have 2. 20 / 3 is 6 with a remainder of two.
This is what I have so far
.data ;// write your data in this section
Numbers DWORD 16 DUP(?)
count DWORD ?
msg1 BYTE "Enter 16 numbers",0ah,0dh,0
msg2 BYTE "The array after the second half was reversed is",0ah,0dh,0
.code ;// write your program here
main proc
L1:
mov edx, OFFSET msg1
call WriteString
mov edx, OFFSET Numbers
mov ecx, 17
call ReadString
mov ebx, 0
mov edx, OFFSET Numbers
mov ecx, 17
L2:
mov count, ecx
mov ecx, 1
L3:
mov eax, Numbers[ebx]
call WriteChar
inc ebx
loop L3
call crlf
mov ecx, count
loop L2
The biggest thing I do not understand how I reverse the second half of the DWORD storage through the loop, but I am honestly confused with most of it. I have not had trouble with any assignments up till this point, but this one really has me stuck