Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Electrical & Electronics Expert

Interpret the Assembly Output of the LC - 3 Compilers

Goals to understand the stack convention of the LC3 compiler:

  • How the stack pointer and frame pointer are managed
  • Where parameters, return values, return addresses, and local variables are stored
  • What the stack looks like before, during, and after a function call.

Instructions

This assignment makes you interpret the assembly output of the LC3 compiler (lcc) in order to figure out the stack convention. We supply the original C file (stack.c) and the assembly code (stack.asm) generated from the compiler. The C program and a fragment of the assembly file with the function code are shown below, these should be sufficient. Note that we have modified lines zero and one to do separate decrements of the stack pointer, instead of combining them as the compiler does. Examine the C code and the assembly code and answer the questions, which are worth 5 points each. For the last question you must draw a picture of the stack at a certain point in the program, this problem is worth 30 points. This assignment does not require you to compile or run code using the LC3 compiler.

The Assignment

Here is the C code for the assignment, comments have been removed to save space:

int add(int param0, int param1)

{

    int result;

    result = param0 + param1;

    return (result);

}

int main(int argc, char *argv[])

{

    int local0 = 1234;

    int local1 = 2345;

    printf("Result: %d\n", add(local0, local1));

    return (0);

}

Here is the assembly code generated by lcc for the add function in stack.c

;;;;;;;;;;;;;;;;;;;;;;;;;;;;add;;;;;;;;;;;;;;;;;;;;;;;;;;;;

lc3_add

;; stack entry

 0:           ADD R6, R6, #­1

 1:           ADD R6, R6, #­1

 2:           STR R7, R6, #0

 3:           ADD R6, R6, #­1 

 4:           STR R5, R6, #0

 5:           ADD R5, R6, #­1

;; function body

 6:           ADD R6, R6, #­1

 7:           ldr R7, R5, #4

 8:           ldr R3, R5, #5

 9:           add R7, R7, R3

10:           str R7, R5, #0

11:           ldr R7, R5, #0

;; stack exit

12:                  STR R7, R5, #3

13:                  ADD R6, R5, #1

14:                  LDR R5, R6, #0

15:                  ADD R6, R6, #1

16:                  LDR R7, R6, #0

17:                  ADD R6, R6, #1

18:                  RET

Answer the following questions, using the variable names from the original program, or one of the following: stack pointer, frame pointer, and return address. When the answer is the frame pointer, identify whether it is the frame pointer from main() or add(). Do not tell me that R7 is getting pushed or R5 getting popped, we already know that from reading the code. Be specific with names from the original C program: local0, local1, param0, param1, etc. Assume that the main program has pushed param0 and param1 before calling the add () function.

Question 1: The code at line 0 is making room on the stack for which value?

Question 2: What is getting pushed at lines 1 and 2?

Question 3: What is getting pushed at lines 3 and 4?

Question 4: What value is being setup at line 5 for which function?

Question 5: The code at line 6 is making room on the stack for which value?

Question 6: Which parameter is loaded, and from what frame pointer offset at line 7?

Question 7: Which parameter is loaded, and from what frame pointer offset at line 8?

Question 8: What is the code at line 9 doing?

Question 9: What is being stored at line 10, and to which frame pointer offset is written?

Question 10: What is being load at line 11, and from which frame pointer offset is read?

Question 11: Is the instruction at line 11 redundant? If so why might the compiler generate it?

Question 12: What is being stored at line 12, and to which frame pointer offset is written?

Question 12: What is being done at line 13?

Question 13: What is getting popped at line 14 and 16?

Electrical & Electronics, Engineering

  • Category:- Electrical & Electronics
  • Reference No.:- M9525725

Have any Question?


Related Questions in Electrical & Electronics

Problem 1 a two-phase servomotor has rated voltage applied

Problem 1: A two-phase servomotor has rated voltage applied to its excitation winding. The torque speed characteristic of the motor with Vc = 220 V, 60 Hz applied to its control phase winding is shown in Fig.1. The momen ...

Discuss the role of load factor on the cost of electrical

Discuss the role of load factor on the cost of electrical energy.

Questions -problem 1 - solve for i0 in fig using mesh

Questions - Problem 1 - Solve for i 0 in Fig. using mesh analysis. Problem 2 - Use mesh analysis to find current i 0 in the circuit. Problem 3 - Use mesh analysis to find v 0 in the circuit. Let v s1 = 120 cos(100t+ 90 o ...

1 a name the three major groups of contamination and

1. (a) Name the three major groups of contamination and briefly describe their physical characteristics. (b) Where do the above contamination types come from? Give one example of each. 2. Name two processes metrics which ...

Research report1 read 3 to 4 journal articles about digital

Research report 1. Read 3 to 4 journal articles about digital control or industrial control, eg. one particular application, implementation aspect such as selection of sampling time, hardware etc. No text book example is ...

Problems -problem 1 - find v0 in the op amp circuit of fig

Problems - Problem 1 - Find v 0 in the op amp circuit of Fig. 1. Problem 2 - Compute i 0 (t) in the op amp circuit in Fig. 2 if v s = 4 cos(10 4 t). Problem 3 - If the input impedance is defined as Z in = v s /I s , find ...

Question 1 - for the transistor in the circuit shown in

Question 1 - For the transistor in the circuit shown in Figure, assume β = 120. Design the circuit such that I CQ = 0.15 mA and R TH = 200kΩ. What is the value of V CEQ ? Question 2 - (a) For the circuit shown in figure, ...

Question 1for the ce amplifier in figure 1 given the

Question 1 For the CE amplifier in Figure (1), given the following component parameters: Parameter Value β DC , β AC 150 V BE 0 . 7 V V CC 12 V R C 820 ? R E 1 100 ? R E 2 220 ? R 1 20 k? R 2 5 . 2 k? R L 100 k? C 1 , C ...

Assignment -consider a common emitter amplifiernow lets say

Assignment - Consider a common emitter amplifier: Now let's say that R B and R C do a fine job at DC biasing the BJT but they are large so they can be neglected for small signal (AC) analysis. In that case, the equivalen ...

1 a name the three major groups of contamination and

1. (a) Name the three major groups of contamination and briefly describe their physical characteristics. (b) Where do the above contamination types come from? Give one example of each. 2. Name two processes metrics which ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As