Question

Discuss the relationship between the C code and the Assembly code generated by the compiler??? Especially...

Discuss the relationship between the C code and the Assembly code generated by the compiler???

Especially focus on the difference between declaration of different types of variables in assembly for example difference between the declaration of an integer variable and a character variable.

URGENT PLEASE

BELOW IS THE C CODE:

//Toggling PORTB in C Language for Dragon12 Plus Trainer Board

//with HCS12 Serial Monitor Program installed. This code is for CodeWarrior IDE

//On Dragon12+ Trainer board 8 LEDs are connected to PORTB and

//PTJ1 is used to allow LEDs of PORTB to show the data (See Page 24 of Dragon12+ Doc)

//Modified from Example 7-7 of Mazidi & Causey HCS12 book

//Use F7 to Make, F5 (Debug) to download, and F5 (Start) to run the program

//Make sure you are in HCS12 Serial Monitor mode when downloading and running.

#include /* common defines and macros */

#include "derivative.h" /* derivative-specific definitions */

void MSDelay(unsigned int);

void main(void)

{

/* put your own code here */

DDRB = 0xFF; //PORTB as output since LEDs are connected to it

DDRJ = 0xFF; //PTJ as output to control Dragon12+ LEDs

PTJ=0x0; //Allow the LEDs to display data on PORTB pins

for(;;)

{

PORTB = 0xFF;

MSDelay(500); //1/2 sec delay

PORTB = 0x0;

MSDelay(500);

}

}

//millisecond delay for XTAL=8MHz, PLL=48MHz

//The HCS12 Serial Monitor is used to download and the program.

//Serial Monitor uses PLL=48MHz

void MSDelay(unsigned int itime)

{

unsigned int i; unsigned int j;

for(i=0;i

for(j=0;j<4000;j++); //1 msec. tested using Scope

}

BELOW IS THE ASSEMBLY CODE:

*** EVALUATION ***

ANSI-C/cC++ Compiler for HC12 V-5.0.41 Build 10203, Jul 23 2010

1: //Toggling PORTB in C Language for Dragon12 Plus Trainer Board

2: //with HCS12 Serial Monitor Program installed. This code is for CodeWarrior IDE

3: //On Dragon12+ Trainer board 8 LEDs are connected to PORTB and

4: //PTJ1 is used to allow LEDs of PORTB to show the data (See Page 24 of Dragon12+ Doc)

5: //Modified from Example 7-7 of Mazidi & Causey HCS12 book

6: //Use F7 to Make, F5 (Debug) to download, and F5 (Start) to run the program

7: //Make sure you are in HCS12 Serial Monitor mode when downloading and running.

8:

9: #include /* common defines and macros */

10: #include "derivative.h" /* derivative-specific definitions */

11:

12:

13: void MSDelay(unsigned int);

14: void main(void)

15: {

*** EVALUATION ***

Function: main

Source : C:\Users\ecelab\Documents\Lab01-Task01HL\Sources\main.c

Options : -CPUHCS12 -D_HCS12_SERIALMON -D__NO_FLOAT__ -Env"GENPATH=C:\Users\ecelab\Documents\Lab01-Task01HL;C:\Users\ecelab\Documents\Lab01-Task01HL\bin;C:\Users\ecelab\Documents\Lab01-Task01HL\prm;C:\Users\ecelab\Documents\Lab01-Task01HL\cmd;C:\Users\ecelab\Documents\Lab01-Task01HL\Sources;C:\Program Files (x86)\Freescale\CWS12v5.1\lib\HC12c\lib;C:\Program Files (x86)\Freescale\CWS12v5.1\lib\HC12c\src;C:\Program Files (x86)\Freescale\CWS12v5.1\lib\HC12c\include" -Env"LIBPATH=C:\Program Files (x86)\Freescale\CWS12v5.1\lib\HC12c\include" -EnvOBJPATH=C:\Users\ecelab\Documents\Lab01-Task01HL\bin -EnvTEXTPATH=C:\Users\ecelab\Documents\Lab01-Task01HL\bin -Lasm=C:\Users\ecelab\Documents\Lab01-Task01HL\Lab01-Task01HL_Data\Standard\ObjectCode\main.c.o.lst -Mb -ObjN=C:\Users\ecelab\Documents\Lab01-Task01HL\Lab01-Task01HL_Data\Standard\ObjectCode\main.c.o -WmsgSd1106

16: /* put your own code here */

17:

18:

19:

20: DDRB = 0xFF; //PORTB as output since LEDs are connected to it

0000 c6ff [1] LDAB #255

0002 5b00 [2] STAB _DDRAB:1

21: DDRJ = 0xFF; //PTJ as output to control Dragon12+ LEDs

0004 7b0000 [3] STAB _DDRJ

22: PTJ=0x0; //Allow the LEDs to display data on PORTB pins

0007 790000 [3]   CLR _PTJ

23: for(;;)

24: {

25: PORTB = 0xFF;

000a c6ff [1] LDAB #255

000c 5b00 [2] STAB _PORTAB:1

26: MSDelay(500); //1/2 sec delay

000e cc01f4 [2] LDD #500

0011 4a000000 [7]   CALL MSDelay,PAGE(MSDelay)

27: PORTB = 0x0;

0015 790000 [3]   CLR _PORTAB:1

28: MSDelay(500);

0018 cc01f4 [2] LDD #500

001b 4a000000 [7]   CALL MSDelay,PAGE(MSDelay)

001f 20e9 [3] BRA *-21 ;abs = 000a

29: }

30:

31: }

32:

33: //millisecond delay for XTAL=8MHz, PLL=48MHz

34: //The HCS12 Serial Monitor is used to download and the program.

35: //Serial Monitor uses PLL=48MHz

36:

37: void MSDelay(unsigned int itime)

38: {

*** EVALUATION ***

Function: MSDelay

Source : C:\Users\ecelab\Documents\Lab01-Task01HL\Sources\main.c

Options : -CPUHCS12 -D_HCS12_SERIALMON -D__NO_FLOAT__ -Env"GENPATH=C:\Users\ecelab\Documents\Lab01-Task01HL;C:\Users\ecelab\Documents\Lab01-Task01HL\bin;C:\Users\ecelab\Documents\Lab01-Task01HL\prm;C:\Users\ecelab\Documents\Lab01-Task01HL\cmd;C:\Users\ecelab\Documents\Lab01-Task01HL\Sources;C:\Program Files (x86)\Freescale\CWS12v5.1\lib\HC12c\lib;C:\Program Files (x86)\Freescale\CWS12v5.1\lib\HC12c\src;C:\Program Files (x86)\Freescale\CWS12v5.1\lib\HC12c\include" -Env"LIBPATH=C:\Program Files (x86)\Freescale\CWS12v5.1\lib\HC12c\include" -EnvOBJPATH=C:\Users\ecelab\Documents\Lab01-Task01HL\bin -EnvTEXTPATH=C:\Users\ecelab\Documents\Lab01-Task01HL\bin -Lasm=C:\Users\ecelab\Documents\Lab01-Task01HL\Lab01-Task01HL_Data\Standard\ObjectCode\main.c.o.lst -Mb -ObjN=C:\Users\ecelab\Documents\Lab01-Task01HL\Lab01-Task01HL_Data\Standard\ObjectCode\main.c.o -WmsgSd1106

0000 6cac [2] STD 4,-SP

39: unsigned int i; unsigned int j;

40: for(i=0;i

0002 c7 [1]   CLRB

0003 87 [1]   CLRA

0004 6c82 [2] STD 2,SP

0006 200e [3] BRA *+16 ;abs = 0016

41: for(j=0;j<4000;j++); //1 msec. tested using Scope

0008 ce0000 [2] LDX #0

000b 08 [1] INX

000c 8e0fa0 [2]   CPX #4000

000f 25fa [3/1] BCS *-4 ;abs = 000b

0011 ee82 [3] LDX 2,SP

0013 08 [1] INX

0014 6e82 [2] STX 2,SP

0016 ec82 [3] LDD 2,SP

0018 ac80 [3]   CPD 0,SP

001a 25ec [3/1] BCS *-18 ;abs = 0008

42: }

001c 1b84 [2] LEAS 4,SP

001e 0a [7] RTC

Homework Answers

Answer #1

C Language is very close to the assembly language, C language was created to make the tedious work which was done while programming assembly language easy. Thus C language has always been a time saver for the programmers, which helped them to save time. And the efficiency of assembly language is almost maintained in the C language as it is very close to the assembly language

The declaration of different variables is done differently and the amount of memory which is taken by the variables is also different.
Like following is the memory taken by different variables.
int: 32bits
char: 8bits

As the memory is taken by different variables is different, thus the maximum number of values which are represented by them would also be different.

If you have any doubts regarding the solution, do let me know in the comment section.
Thanks

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
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • 4. List and describe the THREE (3) necessary conditions for complete similarity between a model and...
    asked 10 minutes ago
  • In C++ Complete the template Integer Average program. // Calculate the average of several integers. #include...
    asked 15 minutes ago
  • A uniform rod is set up so that it can rotate about a perpendicular axis at...
    asked 17 minutes ago
  • To the TwoDArray, add a method called transpose() that generates the transpose of a 2D array...
    asked 38 minutes ago
  • How could your result from GC (retention time, percent area, etc.) be affected by these following...
    asked 48 minutes ago
  • QUESTION 17 What are the tasks in Logical Network Design phase? (Select five. ) Design a...
    asked 50 minutes ago
  • What is the temperature of N2 gas if the average speed (actually the root-mean-square speed) of...
    asked 59 minutes ago
  • Question One: Basic security concepts and terminology                         (2 marks) Computer security is the protection of...
    asked 1 hour ago
  • In program P83.cpp, make the above changes, save the program as ex83.cpp, compile and run the...
    asked 1 hour ago
  • the determination of aspirin in commercial preparations experment explain why the FeCl3-KCl-HCl solution was ased as...
    asked 1 hour ago
  • Describe important events and influences in the life of Wolfgang Amadeus Mozart. What styles, genres, and...
    asked 1 hour ago
  • 3.12 Grade Statistics Write a python module "school.py" that prints school information (first 3 lines of...
    asked 1 hour ago