代写 algorithm math assembly Extra Credit Project – VFC

Extra Credit Project – VFC
Objective:
• Extra Credit (150 points)
• Design, Implement, Assemble, and Execute a program
Project Description
• Write the algorithm (steps to accomplish the task)
• Create the design description
• Implement the algorithm
For example:
Let’s say that you want to create an assembly program that will sum up the elements in an integer array
intarray DWORD 10000h, 20000h, 30000h, 40000h
00010000 + 00020000 + 0030000 + 00040000 = 000A0000 (10 in decimal)
The algorithm steps would be the following:
• Initialize the data section
• load the offset of the integer array in the EDI register
• Initialize the loop counter to the length of the array
• Initialize the sum of the integer array to 0 in the EAX register
• Begin a loop
• Add an integer and store in the eax register
• Point to the next element in the integer array and put it in the edi register
• Repeat step 6 until ecx = 0
• Exit the process successfully
• Terminate the program
The design description would be as follows:
Label
Directives
Instruction
Comments

.data

; Marks to define variables used

intarray DWORD 10000h, 20000h, 30000h, 40000h
; 1. Initialize the intarray of type DWORD (32 bits)

.code

; Marks beginning of code area

MOV edi, OFFSET intarray
; 2. EDI = Address of intarray, OFFSET = distance of intarray from the beginning of its enclosing segment

MOV ecx, LENGTHOF intarray
; 3. Initialize loop counter, LENGTHOF = number of elements in the intarray

MOV eax, 0
; 4. Sum = 0
L1:

; 5. Mark beginning of loop

ADD eax, [edi]
; 6. Add an integer

ADD edi, TYPE intarray
; 7. Point to next element, TYPE returns the size (in bytes) of each element in intarray.

LOOP L1
; 8. Repeat until ECX = 0

invoke ExitProcess, 0
; 9. Exits the process successfully

END
; 10. Marks the end of the program

The implementation would be the following:
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:dword

.data
intarray DWORD 10000h,20000h,30000h,40000h

.code
main proc

mov edi,OFFSET intarray ; 2: EDI = address of intarray
mov ecx,LENGTHOF intarray ; 3: initialize loop counter
mov eax,0 ; 4: sum = 0
L1: ; 5: mark beginning of loop
add eax,[edi] ; 6: add an integer
add edi,TYPE intarray ; 7: point to next element
loop L1 ; 8: repeat until ECX = 0

invoke ExitProcess,0
main endp
end main

Result:
ECX is the counter and starts to count down. Since the length of the array is 4, the countdown for ECX starts at 4 (00000004h). EAX is initialize to be 0 from step 4 above.

EAX loads the first element in the array which is 10000h. This is from step 6 above.

Since the loop counter register ECX is not 0 yet, we will continue with the next iteration. The countdown continues and now ECX is 3 (00000003h). The next element in the integer array (20000h) is added to the contents in the EAX register (10000h) from the screenshot above. This is the sum of 10000h and 20000h which is equal to 30000h (ie. 10000h + 20000h = 30000h). This is from step 6 above.

Since the loop counter register ECX is still not 0, we will continue with the next iteration. The countdown continues and now ECX is 2 (00000002h). The next element in the integer array (30000h) is added to the contents in the EAX register (30000h) from the screenshot above. This is the sum of 30000h and 30000h which is equal to 60000h (ie. 30000h + 30000h = 60000h). This is from step 6 above.

Since the loop counter register ECX is still not 0, we will continue with the next iteration. The countdown continues and now ECX is 1 (00000001h). The next element in the integer array (40000h) is added to the contents in the Eax register (60000h) from the screenshot above. This is the sum of 60000h and 40000h which is equal to 10, but in hex it is A (ie. 60000h + 40000h = A0000h). This is from step 6 above.
So now the program ends because the loop counter register ECX is now 0.

Project Assignment
There are lots of number tricks you can do by using simple math. Mathematics are governed by a fixed set of principles. If you follow the same process, you’ll get the same answer every time. Using math in magic tricks, however, is just as much an art as it is science. Of course, you won’t be able to read someone’s mind literally with these tricks, but if done correctly, you’ll be able to wow your friends by guessing their answer without them telling you. The math will work every time.
For this assignment, you will be working in your group to create a program that will read someone’s mind by performing a few simple mathematical tricks. With this assignment, the answer will always be half of the number that one member of the team chooses. NOTE: This is a simple calculation in which you can hardcode the numbers in the program. You do not have to ask the user to input a value. The requirements are listed below.
• Write up the algorithm steps like the example above.
• Create a design description containing screenshots of the results. Please see the above example.
• Implement and test your program.
• zip up all the necessary files and submit via blackboard under the extra credit section (one team will hand in one assignment)
NOTE: The zip file should contain three files: 1) A word document listing the first and last name of all members of the group. Each member must participate in the project, so list what task the student was responsible for. For example: Jane Doe, responsible for writing the design document. 2) A word document describing the algorithm steps, design document, and result screenshot. 3) The .asm file or your visual studio .sln project file.
Requirements for the program:
• Ask a member of the group to pick a whole number between 1 and 10. For example: 3
• Multiply that number by 2. For example: 4 X 2 = 6
• Ask another member of the group to pick an even number. For example: 52
• Add the numbers from step 2 and step 3 above. For example: 52 + 6 = 58
• Divide that number by 2. For example: 58 / 2 = 29
• Subtract the new number from step 5 with the number from step 1. For example: 29 – 3 = 26. Note that 26 is half of the number from step 3 above (52).
Please note that in looking at the registers, it will be stored as hex digits. You need to convert it in running through your code to see if it is the correct value on paper. This is for testing purposes. You don’t have to convert it in your program. In the above example, 26 (dec) = 1A(hex).

To convert decimal to hexadecimal:
26 / 16 = 1 remainder 10 = A(Hex)
1 / 16 = 0 remainder 1

Therefore, starting with the LSB of the remainder, 1A is the hexadecimal representation of the decimal 26.

DUE
Displayed on blackboard.