Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What values will be written to the array when the following code execute? Run th

ID: 2080675 • Letter: W

Question

What values will be written to the array when the following code execute? Run the program on the emulator, to verify your answer.

                .data

                array DW 4 DUP(0)     ;declaring array with 4 word size element

                .code

                main proc

                           mov    ax, 10

                          mov     si, 0

                          call      proc_1

                          add     si, 2

                        add     ax, 10

                        mov     array[si],   ax

                          hlt                                 ; halts the program

                main ENDP

                proc_1    PROC

                        call proc_2

                         add    si, 2

                        add     ax, 10

                        mov   array[si], ax

                        ret

                proc_1 ENDP

                proc_2    PROC

                        call proc_3

                         add    si, 2

                        add     ax, 10

                        mov   array[si], ax

                        ret

                proc_2 ENDP

                proc_3    PROC

                        mov   array[si], ax

                        ret

                proc_3 ENDP

Explanation / Answer

1. main proc      //start proc//

2. mov    ax, 10          //initialise, ax=10//

3. mov     si, 0            //si= 0 ; initialization of array locations with [si]; si starts with [si]=0 (first location)

4. call      proc_1       //go to proc_1 (line 10)// finally goes to line 24

5. add     si, 2           //si= si+2 =4+2=6 , NEW LOCATION ie si[6] //

6. add     ax, 10       //ax=ax+10 =30+10 = 40 //

7. mov array[si], ax    // move ax value i.e, ax=40 to [si] location ie.,si[6] = 40; fourth location value is 40. ie., si[6] = 40;

8. hlt                         ; //halts the program//

9. main ENDP

10. proc_1    PROC       //start of subroutine//

11. call proc_2               // go to proc_2 (line 17)//

12. add    si, 2                //si= si+2 =2+2=4 , NEW LOCATION ie si[4] //

13. add     ax, 10           //ax=ax+10 = 20+10 = 30 //

14. mov   array[si], ax    // move ax value i.e, ax=30 to [si] location ie.,si[4] = 30; third location value is 30. ie., si[6] = 30;

15. ret                              //return//

16. proc_1 ENDP        //end of subroutine; go back to where it left ie., line 05//

17. proc_2    PROC      //start of subroutine//

18. call proc_3   //go to proc_3 (line 24)//

19. add    si, 2               //si= si+2 =0+2=2 , NEW LOCATION ie si[2] //

20. add     ax, 10          // ax=ax+10 = 10+10 = 20 ;//

21. mov   array[si], ax    // move ax value i.e, ax=20 to [si] location ie.,si[2] = 20; second location value is 20. ie., si[2] = 0;

22. ret        //return//

23. proc_2 ENDP         / /end of subroutine; go back to where it left ie., line 12//

24. proc_3    PROC      //start of subroutine//

25. mov   array[si], ax     //move ax=10 value to array represented by source index, [si]=0// first location value is 10. ie., si[0] = 10;

26.      ret    //return//

27. proc_3 ENDP           //end of subroutine; go back to where it left ie., line 19//

array = [10,20,30,40]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote