Question

What values will be written to the array when the following code executes? .data array DWORD...

What values will be written to the array when the following code executes?
.data
array DWORD 4 DUP(0)
.code
main PROC
mov eax,10
mov esi,0
call proc_1
add esi,4
add eax,10
mov array[esi],eax
INVOKE ExitProcess,0
main ENDP
proc_1 PROC
call proc_2
add esi,4
add eax,10
mov array[esi],eax
ret
proc_1 ENDP
proc_2 PROC
call proc_3
add esi,4
add eax,10
mov array[esi],eax
ret
proc_2 ENDP
proc_3 PROC
mov array[esi],eax
ret
proc_3 ENDP

Homework Answers

Answer #1

Note: for simplicity purpose , instead of assigning the address in mov command, I have moved the value.

As you are well aware program execution starts from main. Let's debug step by step.

main PROC

mov eax,10 ( implies adrress of 10 is moved into eax, eax=10)

mov esi,0 (implies adrress of 0 is moved into esi , esi=0)

call proc_1 */ proc_1 is called /*

In proc_1 , proc_2 is called and in return which calls proc_3

proc_3 assigns address of eax to array[0] ( mov array[esi],eax) which implies array[0]=10) and we retrun to proc_2

In proc_2

add esi,4 ( add 0 and 4 and assign to esi , esi=4)

add eax,10 ( add 10 and 10 and assign to eax, eax=20)

mov array[esi],eax ( eax value 20 is moved into array[4])

ret ( return to procedure 1)

In proc_1 ( as of now we have following data, esi=4, eax=20 and array[0]=10,array[4]=20)

add esi,4 ( now esi+4=4+4=8)

add eax,10 ( eax+10=20+10=30)

mov array[esi],eax ( implies array[8]=30)

ret(return to main)

In main after call proc_1 statement we have below values, esi=8,eax=30 , array[0]=10,array[4]=20 and array[8]=30

add esi,4 ( esi+4=8+4=12)

add eax,10 (eax+10=30+10=40)

mov array[esi],esx ( 40 is assigned array to array[12])

Then by invoking exit process, we exit it and values of array is as follows array[0]=10,array[4]=20,array[8]=30 and array[12]=40

please like

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
6. (True/False): The RET instruction pops the top of the stack into the instruction pointer. 8....
6. (True/False): The RET instruction pops the top of the stack into the instruction pointer. 8. (True/False): In protected mode, each procedure call uses a minimum of 4 bytes of stack space. 1. Which instruction pushes all of the 32-bit general-purpose registers on the stack? 20. What values will be written to the array when the following code executes? .data array DWORD 4 DUP(0) .code main PROC mov eax,10 mov esi,0 call proc_1 add esi,4 add eax,10 mov array[esi],eax INVOKE...
A) Is the code below secure? Explain your rationale. ExitProcess PROTO .data firstval qword 20002000h secondval...
A) Is the code below secure? Explain your rationale. ExitProcess PROTO .data firstval qword 20002000h secondval qword 11111111h thirdval qword 22222222h sum qword 0 .code main proc      mov rax,firstval                         add rax,secondval             add    rax,thirdval      mov    sum,rax      mov    ecx,0      invoke ExitProcess main endp end main b) Transmitted messages often include a parity bit, whose value is combined with a data byte to produce an even number of 1 bits. Suppose a message byte in the AL...
In assembly masm use the code below! Write a program that reverse a string using indirect...
In assembly masm use the code below! Write a program that reverse a string using indirect addressing (may not use the stack - push/pop). The string will be given by the user and be up to 64 characters long INCLUDE Irvine32.inc INCLUDE macros.inc MAX = 64 .data source BYTE MAX DUP('#'),0 destination BYTE LENGTHOF source DUP('*'),0 actual_length DWORD ? ask BYTE "Enter a String: ",0 .code main proc ; ask user for input mov edx, OFFSET ask call WriteString ;...
7. (True/False): Nested procedure calls are not permitted by the Microsoft assembler unless the NESTED operator...
7. (True/False): Nested procedure calls are not permitted by the Microsoft assembler unless the NESTED operator is used in the procedure definition. 15. What will be the final value in EAX after these instructions execute? push 5 push 6 pop eax pop eax 3. Which instruction pops the stack into the EFLAGS register? 17. Which statement is true about what will happen when the example code runs? 1: main PROC 2: mov eax,30 3: push eax 4: push 40 5:...
13. (True/False): The register list in the USES directive must use commas to separate the register...
13. (True/False): The register list in the USES directive must use commas to separate the register names. 11. (True/False): The USES operator lets you name all registers that are modified within a procedure. 2. Which instruction pushes the 32-bit EFLAGS register on the stack? 18. Which statement is true about what will happen when the example code runs? 1: main PROC 2: mov eax,40 3: push offset Here 4: jmp Ex4Sub 5: Here: 6: mov eax,30 7: INVOKE ExitProcess,0 8:...
;Assembly x86-64 ;Q9: What is the value of eax (in decimal) after the function call in...
;Assembly x86-64 ;Q9: What is the value of eax (in decimal) after the function call in _start returns? global _start _start: mov edi, 4 call function1 global function1 function1: push rdi inc edi mov esi, 2 call function2 pop rdi mul edi ret global function2 function2: mov eax, edi mov edx, 0 div esi add eax, edi add eax, edx ret ;Q10: A function uses 10 integer arguments. What is the appropriate value for the blank operand to clear the...
Write a sequence of two instructions that copies bits 0-5 from AL to bits 0-5 in...
Write a sequence of two instructions that copies bits 0-5 from AL to bits 0-5 in BL. Bits 6-7 in BL should be cleared, and AL should be unchanged             Mov al, bl       And 00111111, bl       Write a sequence of two instructions that copies the integer in bits 4-7 from AL register into bits 0-3 of the BL register. Upper 4 bits of AL and BL will be cleared             Shr al, 4       Mov bl,...
Please complete in MASM (x86 assembly language). Use the code below to get started. Write a...
Please complete in MASM (x86 assembly language). Use the code below to get started. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n – 1) + Fib(n – 2). .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD .data    ; define your variables here .code main PROC    ; write your assembly code here    INVOKE ExitProcess,0 main...
Consider the program below The initial value of the Stack Pointer ESP = 0018 FF8C. What...
Consider the program below The initial value of the Stack Pointer ESP = 0018 FF8C. What is the value of the STACK POINTER (ESP) after each CALL instruction and each RET instruction below. INCLUDE Irvine32.inc .DATA .CODE main PROC mov ax,val1 call proc1 (1) ESP=____________(After the CALL) nop exit main ENDP proc1 PROC ;Begin Procedure nop call proc2 (2) ESP=____________(After the CALL) nop ret (3) ESP=____________(After the RET) proc1 ENDP proc2 PROC ;Begin Procedure nop call proc3 (4) ESP=___________(After the...
PLEASE COMMENT CODE AND TEST THAT IT WORKS: Write a assembly program to find the largest...
PLEASE COMMENT CODE AND TEST THAT IT WORKS: Write a assembly program to find the largest item in an array and store it in a AX. Hint: Use both Jump and loop instruction to write the program. logic: Assume that the first item of the array is the minimum and store it in AX Write a loop. Inside the loop, compare the each array item with the AX If the array item is less than the AX, update AX with...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT