Assignment 1:
Create a project called Practice 13. Copy the code you created for Lab 11. In lab 11 you created code to process an array and to show the stack. To show the stack, you created a procedure called ShowStack or ShowParams. This procedure was called immediately after the beginning of the program procedures to show the stack.
In this practice assignment you will add a macro, mDumpMem, a memory dump, which you will find in your textbook section 10.2.5. For this macro you have to provide the address where the memory dump starts, item count, and the type of each element. Therefore, in effect, it does the same thing as your ShowStack procedure only that it will print the values differently on the console.
When you bring mDumpMem into your code it is better to place it into a procedure. Here is how to do it:
You already have a procedure in your code, ShowParams (or ShowStack). You pass to this procedure the number of parameters you need to display. Create another procedure called ShowParams2 (or ShowStack2) for lack of other name. Pass to this procedure the same number of params you need to display. Inside this procedure use mDumpMem to display the stack. Here is an example:
ShowParams2 PROC, numParams:DWORD
mov edx,offset str3 ; print a message to screen
call WriteString
...
mDumpMem , ,
...
ret
ShowParams2 ENDP
Place ShowParams2 immediately after ShowParams, as in this example of PrintArray:
PrintArray PROC, arrayLength:DWORD, arrayType:DWORD, arrayAddress:DWORD
mov edx, OFFSET prompt4 ; print a message to screen
call WriteString
INVOKE ShowParams, 8
INVOKE ShowParams2, 8
...
ret
PrintArray ENDP
This procedure, ShowParams2, is a wrapper around mDumpMem and will create the same stack arrangement as ShowParams does. It will show the same values, except one. Explain in a comment near mDumpMem, in your code, why that parameter is different.
Here is how the console should look for this practice after adding mDumpMem after each ShowStack.
Assignment 2:
Create a macro named mWriteInt that writes a signed integer to standard output by calling the WriteInt procedure. The argument passed to the macro can be a byte, word, or double word. Use conditional operators in the macro so it adapts to the size of the argument.
Write a macro named mSwap32 that receives two 32-bit memory operands. The macro should swap the two operands.
To test your macros, write code for the following program:
• Invoke a procedure called InputArray to fill an integer array that is 10 elements long.
• Invoke a procedure called ReverseArray to reverse the array elements. Inside this procedure call mSwap32 to swap the array elements.
• Invoke a procedure called PrintArray to print the array after the elements were reversed. Use mWriteInt to print the elements to screen. This will show that your mWriteInt macro can handle 32-bit variables.
• Invoke a procedure called InputCharArray to fill a character array that is 10 elements long.
• Invoke a procedure called PrintCharArray to print the character array. Use the same mWriteInt to print the elements to screen. This will show that your mWriteInt macro can handle 8-bit variables.
Requirements:
InputArray
When you invoke InputArray, send to the procedure the following argument list: the array length, type and address. Use only these variables to input the values into the array. Use indirect addressing. Statements like mov myArray[esi],eax are not allowed.
ReverseArray
When you invoke ReverseArray, send to the procedure the following argument list: the array length, size, type and address. Use only these variables to reverse the array. Use indirect addressing and mSwap32 macro to reverse the array.
PrintArray
When you invoke PrintArray, send to the procedure the following argument list: the array length, type and address. Use only these variables to print the array and the mWriteInt macro.
InputCharArray
When you invoke InputCharArray, send to the procedure the following argument list: the array length, type and address. Use only these variables to input the values into the array. Use indirect addressing.
PrintCharArray
When you invoke PrintCharArray, send to the procedure the following argument list: the array length, type and address. Use only these variables to print the decimal values of the array characters, and use the same mWriteInt macro.