Interpret the assembly output of the lc - 3 compilers, Electrical Engineering

Assignment Help:

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?


Related Discussions:- Interpret the assembly output of the lc - 3 compilers

Three phase power measurement, what is the relationship between the inducta...

what is the relationship between the inductance, capacitance and resistance in the 2-wattmeter experiment?

Push instruction - stack operations , PUSH Instruction This  instructi...

PUSH Instruction This  instruction copies  the contents  of the specified  register  pair into the  stack. The  contents  of stack  pointer register  are decremented by two. Th

BASIC ELECTRICLE, kindly tell me which text book is usefull forlearn the ba...

kindly tell me which text book is usefull forlearn the basic electricle.

Determine resistance in ideal inverting summing amplifier, Q. In the ideal ...

Q. In the ideal inverting summing amplifier circuit with two inputs, for R f = 10 k, find R 1 and R 2 so that v o = -10v i1 -5 vi2 .

What are hard magnetic materials, What are hard magnetic materials? Har...

What are hard magnetic materials? Hard Magnetic materials- They have a slowly rising magnetization curve along with large hysteresis loop area and therefore large energy losses

Flag registers , Flag Registers Flag  register  is also an  8 bit  reg...

Flag Registers Flag  register  is also an  8 bit  register. Out of 8 bit  five are  defined as flags to indicate status  of the accumulator  hence it is also called status reg

Find the real and reactive powers per phase, Q. A 345-kV, 60-Hz, three-phas...

Q. A 345-kV, 60-Hz, three-phase transmission line delivers 600 MVA at 0.866 power factor lagging to a three-phase load connected to its receiving- end terminals. Assuming that the

Sid input - serial input output ports , SID  Input Serial input data  ...

SID  Input Serial input data  single  bit can be  accepted through this  pin using RIM  command  discussed in details in chapter8.

Give the significance of sim and rim instruction, Give the significance of ...

Give the significance of SIM and RIM instruction available in 8085. Instruction SIM: Set Interrupt Mask. This is a 1 byte instruction and can be used three dissimilar functio

Draw the diagram of the system, You have a motor that is powered by 24 VDC....

You have a motor that is powered by 24 VDC.  It free-runs at 600 radians/second, and stalls with a load of 125 in-lbs.  The time constant (τ) of the motor itself is 1.5 seconds.  T

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd