Question

In: Computer Science

Make a detailed trace of the execution of the following program fragment, giving the contents of...

Make a detailed trace of the execution of the following program fragment, giving the contents of all the registers, and memory locations involved. Assume that before execution begins the SS register contains 0410h, and the SP register 0100h, and that the contents of AX, BX, CX, and DX are 789Ah, 0020h, 2000h, and 1234h respectively.

SS

SP

TOS

AX

BX

CX

DX

Initial contents

0990

0100

/

789A

0020

2000

1234

after

PUSH AX

after

PUSH BX

after

PUSH CX

after

POP DX

after

POP CX

after

PUSH DX

after

POP AX

after

POP BX

Solutions

Expert Solution

Stack Pointer operation:

· 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.

· POP - gets 16 bit value from the stack.

Syntax for POP instruction:

POP REG

  • Store original value of the register in stack (using PUSH).
  • Use the register for any purpose.
  • Restore the original value of the register from stack (using POP).

· 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.

· In 8086, the main stack register is called stack pointer - SP. The stack segment register (SS) is usually used to store information about the memory segment that stores the call stack of currently executed program. SP points to current stack top.

General purpose registers in 8086 microprocessor

1)AX – This is the accumulator. It is of 16 bits and is divided into two 8-bit registers AH and AL to also perform 8-bit instructions.

It is generally used for arithmetical and logical instructions but in 8086 microprocessor it is not mandatory to have accumulator as the destination operand.

2)BX – This is the base register. It is of 16 bits and is divided into two 8-bit registers BH and BL to also perform 8-bit instructions.

It is used to store the value of the offset.

3)CX – This is the counter register. It is of 16 bits and is divided into two 8-bit registers CH and CL to also perform 8-bit instructions.
It is used in looping and rotation.

4)DX – This is the data register. It is of 16 bits and is divided into two 8-bit registers DH and DL to also perform 8-bit instructions.
It is used in multiplication an input/output port addressing.

5)SP – This is the stack pointer. It is of 16 bits.
It points to the topmost item of the stack. If the stack is empty the stack pointer will be (FFFE)H. It’s offset address relative to stack segment.

Make a detailed trace of the execution of the following program fragment, giving the contents of all the registers, and memory locations involved. Assume that before execution begins the SS register contains 0410h, and the SP register 0100h, and that the contents of AX, BX, CX, and DX are 789Ah, 0020h, 2000h, and 1234h respectively.

Assume that before execution begins the SS register contains 0410h, and the SP register 0100h, and that the contents of

AX=789Ah

BX=0020h

CX=2000h

and DX=1234h

Initial contents:

SS=0410h

SP=0100h

TOS=0990h

Answer:

Make a detailed trace of the execution of the following program fragment, giving the contents of all the registers, and memory locations involved.

1) after

PUSH AX

– SP decreases as data is PUSHed

               PUSH     AX   ==> SUB SP, 2 ;   MOV [SS:SP], AX

AX =789Ah goes to memory location 0991=78 0990=9A

2) after

PUSH BX

SP decreases as data is PUSHed

               PUSH     BX   ==> SUB SP, 2 ;   MOV [SS:SP], BX

BX =0020h goes to memory location 0993=00, 0992=20

3) after

PUSH CX

SP decreases as data is PUSHed

               PUSH    CX   ==> SUB SP, 2 ;   MOV [SS:SP], CX

CX =2000h goes to memory location 0995=20 ,0994=00

4) POP DX

SP increases as data is POPed

               POP        DX   ==> MOV DX, [SS:SP] ; ADD SP, 2

DX=1234h after execution of this instruction mov the content from memory to register DX

5) POP CX

SP increases as data is POPed

               POP        CX   ==> MOV CX, [SS:SP] ; ADD SP, 2

After execution of POP CX

CX =2000h

CH                       CL

20                         00

0995h                            0994h

The register CX contain 2000h after execution.

6) after

PUSH DX

– SP decreases as data is PUSHed

               PUSH    DX   ==> SUB SP, 2 ;   MOV [SS:SP], DX

DX =1234h goes to memory location 0997=12 ,0996=34

7) after

POP AX

SP increases as data is POPed

               POP        AX   ==> MOV AX, [SS:SP] ; ADD SP, 2

After execution of POP AX

AX =789Ah

AH                       AL

78                         9A

0991h                            0990h

The register AX contain 789Ah after execution.

8) after

POP BX

SP increases as data is POPed

               POP        BX   ==> MOV BX, [SS:SP] ; ADD SP, 2

After execution of POP AX

BX =0020h

BH                       BL

00                         20

0993h                            0992h

Content of BH is stored in 0993h location and Content of BL is stored in 0992h location

The register BX contain 0020h after execution.


Related Solutions

Trace the execution of quicksort on the following array, assuming that the first item in each...
Trace the execution of quicksort on the following array, assuming that the first item in each subarray is the pivot value. Show the values of first and last for each recursive call and the array elements after returning from each call. Also, show the value of pivot during each call and the value returned through pivIndex. How many times is sort called, and how many times is partition called? 55 50 10 40 80 90 60 100 70 80 20...
Write a program fragment (not a complete program) which will perform the following task: The int...
Write a program fragment (not a complete program) which will perform the following task: The int variable m currently contains the number of minutes a basketball player played in their last game. Use an IF statement(s) to print out an appropriate message based on the following: If m is from 35 to 48, print the message "very tired" If m is from 10 to 34, print the message "little tired" If m is from 1 to 9, print the message...
Trace the execution of my_recursive_function(100) and my_recursive_function(32) for the following code snippet. [0.5 M] void my_recursive_function(int...
Trace the execution of my_recursive_function(100) and my_recursive_function(32) for the following code snippet. [0.5 M] void my_recursive_function(int n) { if(n == 0) { printf("False"); return; } if(n == 1) { printf("True"); return; } if(n%2==0) my_recursive_function(n/2); else { printf("False"); return; } } int main() { my_recursive_function(n); return 0; }
Trace the parts of the digestive system in the pig (same as man) giving the sites...
Trace the parts of the digestive system in the pig (same as man) giving the sites of activity, secretions released, enzymes involved and substrates acted on.Be complete. 2. Describe the blood flow of the heart starting with the inferior and superior vena cava. Include blood vessels and valves involved.
True or False Generally, the trace mineral contents of foods depend on soil and water composition...
True or False Generally, the trace mineral contents of foods depend on soil and water composition and on how foods are processed.                       (      ) Most of the trace minerals are safe at intakes three times above current recommendations . (      ) All people need the same nutrients, but the amounts they need vary depending on their height and weight.                                        (      ) A strong immune system depends on adequate nutrition. Poor nutrition weakens the immune system, which increases susceptibility to infections....
True or False Generally, the trace mineral contents of foods depend on soil and water composition...
True or False Generally, the trace mineral contents of foods depend on soil and water composition and on how foods are processed.                       (      ) Most of the trace minerals are safe at intakes three times above current recommendations . (      ) All people need the same nutrients, but the amounts they need vary depending on their height and weight.                                        (      ) A strong immune system depends on adequate nutrition. Poor nutrition weakens the immune system, which increases susceptibility to infections....
If adenines make up 19% of the bases in the sequence of a fragment of singlestranded...
If adenines make up 19% of the bases in the sequence of a fragment of singlestranded RNA, what can you tell me about the rest of that RNA fragment’s base composition?
Write a AL program that will interchange the contents of the two variables.
Assume we have two string variables:  Shakespeare byte 'Brevity is the soul of wit' and Poet byte 'The problem is not in the stars but within ourselves'  Write a AL program that will interchange the contents of the two variables.
Trace through the program and what the outputs will be. If there is an error explain...
Trace through the program and what the outputs will be. If there is an error explain what must be fixed and continue to trace through. #include <iostream> using namespace std; void beans(int y, int& n, int size); void spam(int& n, int& y); int main(){ int m = 7; int n = 4; cout<<"m is "<<m<<" n is "<<n<<endl; beans(n, m, 3); cout<<"m is "<<m<<" n is "<<n<<endl; spam(m, n); cout<<"m is "<<m<<" n is "<<n<<endl; beans(m, 2, n); cout<<"m is...
“Who are the consumers of health information?” Do so by giving two detailed examples (and the...
“Who are the consumers of health information?” Do so by giving two detailed examples (and the reasoning behind your examples – include user needs) of consumers of health information other than patients and patient families.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT