Software > Computer programming

Assembly Language For the x86 Processor college problem

(1/1)

bob2mop:
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

nil:
I don't believe anyone here wants to do your homework for you, but I want to encourage you by helping you find resources.

If you have not already seen them, these online resources might help you.

The Art of Assembly Language (16 and 32 bit): http://www.plantation-productions.com/Webster/www.artofasm.com/index.html

Easy x86-64: http://ian.seyler.me/easy_x86-64/

x86-64 Assembly Language Programming with Ubuntu: http://www.egr.unlv.edu/~ed/assembly64.pdf

Good luck and I hope this helps.


Geek-9pm:
Have you no prior training in computer programming?
Assembly language tends to lack apparent structure. Some, even many, educators think one should start with a tool that encourages one to think of the larger picture.

Free programming  tutorials from Microsoft focus on high level  language with the option of using some assembly language for a few specific needs.
Here is a good example:
C# Fundamentals for Absolute Beginners

To simplify your tech training journey, we are consolidating our learning resources and retiring Microsoft Virtual Academy in phases, with the next phase finishing on April 30, 2019. On that date, courses, learning paths and associated badging are retiring. Complete site retirement is scheduled for later in 2019. Check your MVA Dashboard frequently for courses you have started that are retiring. To earn your certificates of completion, be sure to finish any courses by April 30, 2019. For more learning options, check out Microsoft Learn.

Years ago I did hard core assembly programming on the 8080 CPU using an Intel system. That was a very longtime ago.
Even back then I l found using a higher level design saved a lot of development time and reduced errors. So we eventually used high level code whenever we could.

bob2mop:
Thank you for the links, I will check them out. Have a good day.

Navigation

[0] Message Index

Go to full version