Question
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
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.
Task #2
C code:
9: #include /* common defines and macros */
10: #include "derivative.h" /* derivative-specific definitions */
11:
12:
13:
14: int i;
15: void main(void)
16: {
*** EVALUATION ***
Function: main
17: /* put your own code here */
18:
19: i=-100;
0000 ccff9c [2] LDD #65436
0003 7c0000 [3] STD i
20:
21:
22: }
0006 0a [7] RTC
23:
24:
Assembly:
*** 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:
14: int i;
15: void main(void)
16: {
*** EVALUATION ***
17: /* put your own code here */
18:
19: i=-100;
0000 ccff9c [2] LDD #65436
0003 7c0000 [3] STD i
20:
21:
22: }
0006 0a [7] RTC
23:
24:
Task #3
C code:
#include /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
unsigned j;
void main(void)
{
j=25;
}
Assembly:
*** EVALUATION ***
ANSI-C/cC++ Compiler for HC12 V-5.0.41 Build 10203, Jul 23 2010
1:
2:
3: #include /* common defines and macros */
4: #include "derivative.h" /* derivative-specific definitions */
*** EVALUATION ***
Function: main
Source : C:\Users\ecelab\Desktop\Lab_02_Task_04\Sources\main.c
9: c='X';
0000 c658 [1] LDAB #88
0002 7b0000 [3] STAB c
10: }
0005 0a [7] RTC
11:
12:
Task #5
C code:
#include /* common defines and macros */
#include "derivati 5:
6:
7: unsigned j;
8: void main(void)
9: {
*** EVALUATION ***
Function: main
Source : C:\Users\ecelab\Desktop\Project_22\Sources\main.c
10: j=25;
0000 c619 [1] LDAB #25
0002 87 [1] CLRA
0003 7c0000 [3] STD j
11: }
0006 0a [7] RTC
12:
13:
Task #4
C code:
#include /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
char c;
void main(void)
{
c='X';
}
Assembly:
*** EVALUATION ***
ANSI-C/cC++ Compiler for HC12 V-5.0.41 Build 10203, Jul 23 2010
1:
2:
3: #include /* common defines and macros */
4: #include "derivative.h" /* derivative-specific definitions */
5:
6: char c;
7: void main(void)
8: {
ve.h" /* derivative-specific definitions */
void main(void)
{
int iarr[10]={0,1,2,3,4,5,6,7,8,9
};
char carr[10]="abcdefghi";
}
Assembly:
*** EVALUATION ***
ANSI-C/cC++ Compiler for HC12 V-5.0.41 Build 10203, Jul 23 2010
1:
2:
3: #include /* common defines and macros */
4: #include "derivative.h" /* derivative-specific definitions */
5:
6:
7:
8: void main(void)
9: {
*** EVALUATION ***
Function: main
Source : C:\Users\ecelab\Desktop\Lab02_Task_05\Sources\main.c
Options : -CPUHCS12 -D_HCS12_SERIALMON -D__NO_FLOAT__ -Env"GENPATH=C:\Users\ecelab\Desktop\Lab02_Task_05;C:\Users\ecelab\Desktop\Lab02_Task_05\bin;C:\Users\ecelab\Desktop\Lab02_Task_05\prm;C:\Users\ecelab\Desktop\Lab02_Task_05\cmd;C:\Users\ecelab\Desktop\Lab02_Task_05\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\Desktop\Lab02_Task_05\bin -EnvTEXTPATH=C:\Users\ecelab\Desktop\Lab02_Task_05\bin -Lasm=C:\Users\ecelab\Desktop\Lab02_Task_05\Lab02_Task_05_Data\Standard\ObjectCode\main.c.o.lst -Mb -ObjN=C:\Users\ecelab\Desktop\Lab02_Task_05\Lab02_Task_05_Data\Standard\ObjectCode\main.c.o -WmsgSd1106
0000 1bf1e2 [2] LEAS -30,SP
10: int iarr[10]={0,1,2,3,4,5,6,7,8,9
0003 c7 [1] CLRB
0004 87 [1] CLRA
0005 6c8a [2] STD 10,SP
0007 52 [1] INCB
0008 6c8c [2] STD 12,SP
000a 58 [1] LSLB
000b 6c8e [2] STD 14,SP
000d 52 [1] INCB
000e 6cf010 [3] STD 16,SP
0011 52 [1] INCB
0012 6cf012 [3] STD 18,SP
0015 52 [1] INCB
0016 6cf014 [3] STD 20,SP
0019 52 [1] INCB
001a 6cf016 [3] STD 22,SP
001d 52 [1] INCB
001e 6cf018 [3] STD 24,SP
0021 52 [1] INCB
0022 6cf01a [3] STD 26,SP
0025 52 [1] INCB
0026 6cf01c [3] STD 28,SP
11: };
12: char carr[10]="abcdefghi";
0029 c661 [1] LDAB #97
002b 6b80 [2] STAB 0,SP
002d 52 [1] INCB
002e 6b81 [2] STAB 1,SP
0030 52 [1] INCB
0031 6b82 [2] STAB 2,SP
0033 52 [1] INCB
0034 6b83 [2] STAB 3,SP
0036 52 [1] INCB
0037 6b84 [2] STAB 4,SP
0039 52 [1] INCB
003a 6b85 [2] STAB 5,SP
003c 52 [1] INCB
003d 6b86 [2] STAB 6,SP
003f 52 [1] INCB
0040 6b87 [2] STAB 7,SP
0042 52 [1] INCB
0043 6b88 [2] STAB 8,SP
0045 6a89 [2] STAA 9,SP
13:
14: }
0047 1bf01e [2] LEAS 30,SP
004a 0a [7] RTC
15:
16:
Task #6
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 = 0x00;
MSDelay(500); //1/2 sec delay
PORTB = 0x01;
MSDelay(500);
PORTB = 0x03;
MSDelay(500);
PORTB = 0x07;
MSDelay(500);
PORTB = 0x0F;
MSDelay(500);
PORTB = 0x1F;
MSDelay(500);
PORTB = 0x3F;
MSDelay(500);
PORTB = 0x7F;
MSDelay(500);
PORTB = 0xFF;
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
}
Assembly:
*** 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\Desktop\Project_23\Sources\main.c
Options : -CPUHCS12 -D_HCS12_SERIALMON -D__NO_FLOAT__ -Env"GENPATH=C:\Users\ecelab\Desktop\Project_23;C:\Users\ecelab\Desktop\Project_23\bin;C:\Users\ecelab\Desktop\Project_23\prm;C:\Users\ecelab\Desktop\Project_23\cmd;C:\Users\ecelab\Desktop\Project_23\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\Desktop\Project_23\bin -EnvTEXTPATH=C:\Users\ecelab\Desktop\Project_23\bin -Lasm=C:\Users\ecelab\Desktop\Project_23\Project_23_Data\Standard\ObjectCode\main.c.o.lst -Mb -ObjN=C:\Users\ecelab\Desktop\Project_23\Project_23_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 = 0x00;
000a 790000 [3] CLR _PORTAB:1
26: MSDelay(500); //1/2 sec delay
000d cc01f4 [2] LDD #500
0010 4a000000 [7] CALL MSDelay,PAGE(MSDelay)
27: PORTB = 0x01;
0014 c601 [1] LDAB #1
0016 071e [4] BSR *+32 ;abs = 0036
28: MSDelay(500);
29: PORTB = 0x03;
0018 c603 [1] LDAB #3
001a 071a [4] BSR *+28 ;abs = 0036
30: MSDelay(500);
31: PORTB = 0x07;
001c c607 [1] LDAB #7
001e 0716 [4] BSR *+24 ;abs = 0036
32: MSDelay(500);
33: PORTB = 0x0F;
0020 c60f [1] LDAB #15
0022 0712 [4] BSR *+20 ;abs = 0036
34: MSDelay(500);
35: PORTB = 0x1F;
0024 c61f [1] LDAB #31
0026 070e [4] BSR *+16 ;abs = 0036
36: MSDelay(500);
37: PORTB = 0x3F;
0028 c63f [1] LDAB #63
002a 070a [4] BSR *+12 ;abs = 0036
38: MSDelay(500);
39: PORTB = 0x7F;
002c c67f [1] LDAB #127
002e 0706 [4] BSR *+8 ;abs = 0036
40: MSDelay(500);
41: PORTB = 0xFF;
0030 c6ff [1] LDAB #255
0032 0702 [4] BSR *+4 ;abs = 0036
0034 20d4 [3] BRA *-42 ;abs = 000a
0036 5b00 [2] STAB _PORTAB:1
0038 cc01f4 [2] LDD #500
003b 4a000000 [7] CALL MSDelay,PAGE(MSDelay)
003f 3d [5] RTS
42: MSDelay(500);
43: }
44:
45: }
46:
47: //millisecond delay for XTAL=8MHz, PLL=48MHz
48: //The HCS12 Serial Monitor is used to download and the program.
49: //Serial Monitor uses PLL=48MHz
50:
51: void MSDelay(unsigned int itime)
52: {
*** EVALUATION ***
Function: MSDelay
Source : C:\Users\ecelab\Desktop\Project_23\Sources\main.c
Options : -CPUHCS12 -D_HCS12_SERIALMON -D__NO_FLOAT__ -Env"GENPATH=C:\Users\ecelab\Desktop\Project_23;C:\Users\ecelab\Desktop\Project_23\bin;C:\Users\ecelab\Desktop\Project_23\prm;C:\Users\ecelab\Desktop\Project_23\cmd;C:\Users\ecelab\Desktop\Project_23\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\Desktop\Project_23\bin -EnvTEXTPATH=C:\Users\ecelab\Desktop\Project_23\bin -Lasm=C:\Users\ecelab\Desktop\Project_23\Project_23_Data\Standard\ObjectCode\main.c.o.lst -Mb -ObjN=C:\Users\ecelab\Desktop\Project_23\Project_23_Data\Standard\ObjectCode\main.c.o -WmsgSd1106
0000 6cac [2] STD 4,-SP
53: unsigned int i; unsigned int j;
54: 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
55: 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
56: }
001c 1b84 [2] LEAS 4,SP
001e 0a [7] RTC
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started