Reference no: EM132598358 , Length: 7 pages
Problem Set
Problem 1. Each of these problems gives "before" conditions and an instruction. Give the indicated "after" state.
|
Before
|
Instruction executed
|
After
|
(a)
|
EBX: 22334455
ESP: 00 63 FB 60
|
push ebx
|
EBX
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ESP
|
|
|
|
|
|
|
|
|
|
|
|
(b)
|
ESP: 00 63 FB 60
|
ret
|
ESP
|
|
|
|
|
|
|
|
|
|
|
|
(c)
|
ESP: 00 63 FB 60
proc3 is a procedure at address 00405B C8
|
call proc3
|
ESP
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(d)
|
EDX: 12AB FF FD
ESP: 00 63 FB 54
|
push edx
|
EDX
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ESP
|
|
|
|
|
|
|
|
|
|
|
|
(e)
|
ESP: 00 63 FB 54
|
ret
|
ESP
|
|
|
|
|
|
|
|
|
|
|
|
(f)
|
ESP: 00 63 FB 54
proc3f is a procedure at address 00405B72
|
call proc3f
|
EIP
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Problem 2. Given the macro definition
swap MACRO dword1, dword2
push eax
mov eax, dword1
xchgeax, dword2
mov dword1, eax
pop eax
ENDM
Show the sequence of statements to which the macro call swap jack, jill expands.
Problem 3. Suppose that procedure examProc has 4 parameters: (1) a doubleword value, (2) a doubleword count, (3) a doublewordnbr, and (4) a doubleword array address arr. The procedure begins with the following code:
examProc PROC NEAR32
push ebp
mov ebp, esp
push ecx
(a) Using the diagram to the right, draw a picture showing the stack following execution of these instructions. Your picture must start with the parameters for the procedure, assuming cdecl protocol. You must label each relevant doubleword and show the bytes to which EBP and ESP point after the above code is executed.
(b) How can the second parameter count be referenced within the body of the procedure? Be specific.
Problem 4. Suppose that procedure examProc has 3 parameters: (1) a doubleword nbr, (2) a doubleword count, and (3) a doublewordvalue. The procedure begins with the following code:
examProc PROC
push ebp
mov ebp, esp
push eax
push ecx
(a) Using the diagram to the right, draw a picture showing the stack following execution of these instructions. Your picture must start with the parameters for the procedure. You must label each relevant doubleword and show the bytes to which EBP and ESP point after the above code is executed. Assume cdecl procedure calling conventions.
(b) How can the third parameter value be referenced within the body of the procedure? Be specific.
Problem 5. The volume of a pyramid with a rectangular base is given by the formula(h(xy))/3where h is the height of the pyramid,x is the length and y is the width of the base.
In C++, the header for a function to calculate this volume could be written
int pVolume(int height, int length, int width);
// return volume of pyramid with rectangular base
(a) Show assembly language code appropriate for "main" that would be equivalent to the C++ statement
volume = pVolume(24, 9, 5);
Assume 32-bit cdecl protocol is used and that volume references a doubleword integer in memory.
(b) Starting with the PROC directive and ending with the ENDP directive, write an 80x86 procedure pVolume that computes the volume of a pyramid. Assume the parameters are doubleword integers, in the order given by the C++ function header above. Follow 32-bit cdecl protocol.
Problem 6. The area of a trapezoid is given by the formula(h(b_1+b_2))/2where h is the height of the trapezoid and b1 and b2 are the lengths of the parallel bases.
In C++, the header for a function to calculate this area could be written
int tArea(int height, int base1, int base2);
// return area of trapezoid
(a) Show assembly language code appropriate for "main" that would be equivalent to the C++ statement
area = tArea(10, 15, 23);
Assume that area references a doubleword in memory.
(b) Starting with the PROC directive and ending with the ENDP directive, write an 80x86 procedure tArea that computes the area of a trapezoid. Assume the parameters are doubleword integers, in the order given by the C++ function header above.
Follow 32-bitcdeclprotocol.
Problem 7. Starting with the PROC directive and ending with the ENP directive, write an 80x86 procedure that implements the function described by the following C++ function header:
int arrMin(int arr[], int count);
// if count > 0 returns minimum of the first count elements of arr
// otherwise returns 99999
Follow 32-bit cdeclprotocol.
Attachment:- Problem Set.rar