In: Computer Science
Draw the stack (use, word/pdf) before every instruction that is marked red is executed to show your understanding of the call and return functions. Use N/A to represent unpredictable values.
Main Proc 4040018 mov ecx, 0000000Ch 404001C mov ebx, 0000000Bh 4040020 call FADD 4040026 mov eax, ebx … … Main EndP FADD PROC 4041040 Push ecx 4041044 Push ebx 4041048 mov eax, edx … … 404A060 Pop ebx 404A062 Pop ecx 404A064 ret FADD EndP
1). ANSWER :
GIVENTHAT :
Main program start at location 4040018
1)CALL FADD
Call sub procedure at location 4040020
The CALL instruction is used whenever we need to make a call to some procedure or a subprogram. Whenever a CALL is made, the following process takes place inside the microprocessor:
The Syntax for the CALL instruction is as follows:
CALL subprogram_name
FADD/FADDP/FIADD — Add
Adds the destination and source operands and stores the sum in the destination location. The destination operand is always an FPU register; the source operand can be a register or a memory location. Source operands in memory can be in single-precision or double-precision floating-point format or in word or doubleword integer format.
FADDP performs the same function as FADD TO, but pops the register stack after storing the result.
2)move eax,ebx
Mov instruction:
· mov — Move (Opcodes: 88, 89, 8A, 8B, 8C, 8E, ...)
· The mov instruction copies the data item referred to by its second operand (i.e. register contents, memory contents, or a constant value) into the location referred to by its first operand (i.e. a register or memory). While register-to-register moves are possible, direct memory-to-memory moves are not. In cases where memory transfers are desired, the source memory contents must first be loaded into a register, then can be stored to the destination memory address.
Syntax
mov <reg>,<reg>
mov <reg>,<mem>
after execution of this instruction copy the value in ebx
into eax
ebx=0000000bh
After execution eax=0000000bh
3)push ecx
ecx contain 0000000Ch
PUSH - stores 16 bit value in the stack.
Syntax for PUSH instruction:
PUSH REG
• A push operation decrements the stack pointer by 2 or 4
(depending on operands) and copies a value into the location
pointed to by the stack pointer.
After execution of push ecx
contain 0000000Ch goes to location 4041040
4) push ebx
ebx contain 0000000Bh
After execution of push ebx
contain 0000000Bh goes to location 4041044
5)move eax,edx
after execution of this instruction copy the value in edx into eax
edx is N/A
6)POP ebx
POP - gets 16 bit value from the stack.
Syntax for POP instruction:
POP REG
· pop — Pop stack
· The pop instruction removes the 4-byte data element from the top of the hardware-supported stack into the specified operand (i.e. register or memory location). It first moves the 4 bytes located at memory location [SP] into the specified register or memory location, and then increments SP by 4.
POP ebx:
After execution of POP ebx pop contain 0000000Bh at location 4041044
7)POP ecx
After execution of POP ecx ,pop contain 0000000Ch at location 4041040
8)RET
The RET instruction stands for return. This instruction is used at the end of the procedures or the subprograms. This instruction transfers the execution to the caller program. Whenever the RET instruction is called, the following process takes place inside the microprocessor:
The Syntax for the RET instruction is as follows:
RET
After execution of RET instruction The address of the next instruction in the mainline program that is 4040026 which was previously stored inside the stack is now again fetched and is placed inside the instruction pointer (IP).