Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Lecture Slides on Assembly Language and C | CPE 323, Study notes of Engineering

Material Type: Notes; Professor: Milenkovic; Class: INTRO TO EMBEDDED COMPUTER SYS; Subject: Computer Engineering; University: University of Alabama - Huntsville; Term: Fall 2008;

Typology: Study notes

Pre 2010

Uploaded on 07/23/2009

koofers-user-7tj-3
koofers-user-7tj-3 🇺🇸

5

(1)

10 documents

1 / 57

Toggle sidebar

Related documents


Partial preview of the text

Download Lecture Slides on Assembly Language and C | CPE 323 and more Study notes Engineering in PDF only on Docsity! CPE 323 Introduction to Embedded Computer Systems: MSP430: Assembly Language and C Instructor: Dr Aleksandar Milenkovic Lecture Notes CPE 323 Intro2EmbeddedSystems 2 Outline Assembly Language Programming Adding two 32-bit numbers (decimal, integers) Counting characters ‘E’ Subroutines CALL&RETURN Subroutine Nesting Passing parameters Stack and Local Variables C and the MSP430 CPE 323 Intro2EmbeddedSystems 5 Decimal/Integer Addition of 32-bit Numbers (cont’d) main: NOP ; main program MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer MOV #lint1, R4 ; pointer to first 4-byte decimal number MOV #lsumd, R8 MOV #2, R5 CLRC ldeca: MOV 4(R4), R7 DADD @R4+, R7 ; decimal addition MOV R7, 0(R8) ADD #2, R8 DEC R5 JNZ ldeca MOV #lint1, R4 ; pointer to first 4-byte decimal number MOV #lsumd, R8 MOV #2, R5 CLRC lia: MOV 4(R4), R7 ADDC @R4+, R7 ; decimal addition MOV R7, 4(R8) ADD #2, R8 DEC R5 JNZ lia JMP $ ; jump to current location '$' ; (endless loop) END CPE 323 Intro2EmbeddedSystems 6 Assembly Language Directives ORG 0xF000 b1: DB 5 ; allocates a byte in memory and initialize ; it with constant 5; ; equivalent to DC8 5 b2: DB -122 ; allocates a byte with constant -122 b3: DB 10110111b ; binary value of a constant b4: DB 0xA0 ; hexadecimal value of a constant b5: DB 123q ; octal value of a constant EVEN ; move a location pointer to the first even address tf EQU 25 w1: DW 32330 ; allocates a a word size constant in memory; ; equivalent to DC16 32330 w2: DW -32000 dw1: DL 100000 ; allocates a long word size constant in memory; ; equivalent to DC32 100000 dw2: DL -10000 dw3: DL 0xFFFFFFFF dw4: DL tf s1: DB 'ABCD' ; allocates 4 bytes in memory with string ABCD s2: DB "ABCD" ; allocates 5 bytes in memory with string ABCD ; and \0 character at the end CPE 323 Intro2EmbeddedSystems 7 Assembly Language Directives (cont’d) ORG 0x0200 v1b DS 1 ; allocates a byte in memory; equivalent to DS8 v2b DS 1 ; allocates a byte in memory; v3w DS 2 ; allocates a word of 2 bytes in memory; ; equivalent to DS8 2 or DS16 v4b DS32 4 ; allocates a buffer of 4 long words; ; 4x4=16 bytes in memory CPE 323 Intro2EmbeddedSystems 10 Count Characters ‘E’ *------------------------------------------------------------------- * Program : Counts the number of characters E in a string * Input : The input string is the myStr * Output : The port one displays the number of E's in the string * Written by : A. Milenkovic * Date : August 14, 2008 * Description: MSP430 IAR EW; Demonstration of the MSP430 assembler *---------------------------------------------------------------------*/ #include "msp430.h" ; #define controlled include file NAME main ; module name PUBLIC main ; make the main label visible ; outside this module ORG 0FFFEh DC16 init ; set reset vector to 'init' label RSEG CSTACK ; pre-declaration of segment CSTACK RSEG CODE ; place program in 'CODE' segment CPE 323 Intro2EmbeddedSystems 11 Count Characters ‘E’ (cont’d) init: MOV #SFE(CSTACK), SP ; set up stack main: NOP ; main program MOV.W #WDTPW+WDTHOLD,&WDTCTL ; stop watchdog timer BIS.B #0FFh,&P1DIR ; configure P1.x output MOV.W #myStr, R4 ; load the starting address of the string into the register R4 CLR.B R5 ; register R5 will serve as a counter gnext: MOV.B @R4+, R6 ; get a new character CMP #0,R6 JEQ lend ; go to the end CMP.B #'E',R6 JNE gnext INC R5 ; increment counter JMP gnext lend: MOV.B R5,&P1OUT ; set all P1 pins JMP $ ; jump to itself myStr DB "HELLO WORLD, I AM THE MSP430!" ; the string is placed on the stack ; the null character is automatically added after the '!' END CPE 323 Intro2EmbeddedSystems 12 Outline Assembly Language Programming Adding two 32-bit numbers (decimal, integers) Counting characters ‘E’ Subroutines CALL&RETURN Subroutine Nesting Passing parameters Stack and Local Variables C and the MSP430 CPE 323 Intro2EmbeddedSystems 15 Sum up two integer arrays (ver1) main: NOP ; main program MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer BIS.B #0xFF,&P1DIR ; configure P1.x as output BIS.B #0xFF,&P2DIR ; configure P2.x as output BIS.B #0xFF,&P3DIR ; configure P3.x as output BIS.B #0xFF,&P4DIR ; configure P4.x as output MOV #arr1, R4 ; load the starting address of the array1 into the register R4 ; Sum arr1 and display CLR R7 ; Holds the sum MOV #8, R10 ; number of elements in arr1 lnext1: ADD @R4+, R7 ; get next element DEC R10 JNZ lnext1 MOV.B R7, P1OUT ; display sum of arr1 SWPB R7 MOV.B R7, P2OUT ; Sum arr2 and display MOV #arr2, R4 CLR R7 ; Holds the sum MOV #7, R10 ; number of elements in arr2 lnext2: ADD @R4+, R7 ; get next element DEC R10 JNZ lnext2 MOV.B R7, P3OUT ; display sum of arr1 SWPB R7 MOV.B R7, P4OUT JMP $ arr1 DC16 1, 2, 3, 4, 1, 2, 3, 4 ; the first array arr2 DC16 1, 1, 1, 1, -1, -1, -1 ; the second array END CPE 323 Intro2EmbeddedSystems 16 Subroutines A particular sub-task is performed many times on different data values Frequently used subtasks are known as subroutines Subroutines: How do they work? Only one copy of the instructions that constitute the subroutine is placed in memory Any program that requires the use of the subroutine simply branches to its starting location in memory Upon completion of the task in the subroutine, the execution continues at the next instruction in the calling program CPE 323 Intro2EmbeddedSystems 17 Subroutines (cont’d) CALL instructions: perform the branch to subroutines RETURN instruction: the last instruction in the subroutine CPE 323 Intro2EmbeddedSystems 20 Subroutine: SUMA_RP Subroutine for summing up elements of an integer array Passing parameters through registers R12 - starting address of the array R13 - array length R14 - display id (0 for P2&P1, 1 for P4&P3) CPE 323 Intro2EmbeddedSystems 21 Subroutine: SUMA_RP /*------------------------------------------------------------------------------ * Program : Subroutine for that sums up elements of an integer array * Input : The input parameters are passed through registers: R12 - starting address of the array R13 - array length R14 - display id (0 for P2&P1, 1 for P4&P3) * Output : No output parameters *------------------------------------------------------------------------------*/ #include "msp430.h" ; #define controlled include file PUBLIC suma_rp RSEG CODE suma_rp: ; save the registers on the stack PUSH R7 ; temporal sum CLR R7 lnext: ADD @R12+, R7 DEC R13 JNZ lnext BIT #1, R14 ; display on P1&P2 JNZ lp34 ; it's P3&P4 MOV.B R7, P1OUT SWPB R7 MOV.B R7, P2OUT JMP lend lp34: MOV.B R7, P3OUT SWPB R7 MOV.B R7, P4OUT lend: POP R7 ; restore R7 RET END CPE 323 Intro2EmbeddedSystems 22 Sum Up Two Integer Arrays (ver2) /*------------------------------------------------------------------------------ * Program : Find a sum of two integer arrays using a subroutine (suma_rp.s43) * Input : The input arrays are signed 16-bit integers in arr1 and arr2 * Output : Display sum of arr1 on P1OUT&P2OUT and sum of arr2 on P3OUT&P4OUT * Modified by: A. Milenkovic, milenkovic@computer.org * Date : September 14, 2008 * Description: MSP430 IAR EW; Demonstration of the MSP430 assembler *------------------------------------------------------------------------------*/ #include "msp430.h" ; #define controlled include file NAME main ; module name PUBLIC main ; make the main label visible ; outside this module EXTERN suma_rp ORG 0FFFEh DC16 init ; set reset vector to 'init' label RSEG CSTACK ; pre-declaration of segment RSEG CODE ; place program in 'CODE' segment init: MOV #SFE(CSTACK), SP ; set up stack CPE 323 Intro2EmbeddedSystems 25 Subroutine: SUMA_SP /*------------------------------------------------------------------------------ * Program : Subroutine for that sums up elements of an integer array * Input : The input parameters are passed through the stack: starting address of the array array length display id * Output : No output parameters *------------------------------------------------------------------------------*/ #include "msp430.h" ; #define controlled include file PUBLIC suma_sp RSEG CODE suma_sp: ; save the registers on the stack PUSH R7 ; temporal sum PUSH R6 ; array length PUSH R4 ; pointer to array CLR R7 MOV 10(SP), R6 ; retrieve array length MOV 12(SP), R4 lnext: ADD @R4+, R7 DEC R6 JNZ lnext MOV 8(SP), R4 ; get id from the stack BIT #1, R4 ; display on P1&P2 JNZ lp34 ; it's P3&P4 MOV.B R7, P1OUT SWPB R7 MOV.B R7, P2OUT JMP lend lp34: MOV.B R7, P3OUT SWPB R7 MOV.B R7, P4OUT lend: POP R4 ; restore R4 POP R6 POP R7 RET END CPE 323 Intro2EmbeddedSystems 26 Sum Up Two Integer Arrays (ver3) *------------------------------------------------------------------------------ * Program : Find a sum of two integer arrays * Input : The input arrays are signed 16-bit integers in arr1 and arr2 * Output : Display sum of arr1 on P1OUT&P2OUT and sum of arr2 on P3OUT&P4OUT * Modified by: A. Milenkovic, milenkovic@computer.org * Date : September 14, 2008 * Description: MSP430 IAR EW; Demonstration of the MSP430 assembler *------------------------------------------------------------------------------*/ #include "msp430.h" ; #define controlled include file NAME main ; module name PUBLIC main ; make the main label visible ; outside this module EXTERN suma_sp ORG 0FFFEh DC16 init ; set reset vector to 'init' label RSEG CSTACK ; pre-declaration of segment RSEG CODE ; place program in 'CODE' segment init: MOV #SFE(CSTACK), SP ; set up stack CPE 323 Intro2EmbeddedSystems 27 Sum Up Two Integer Arrays (ver3) main: NOP ; main program MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer BIS.B #0xFF,&P1DIR ; configure P1.x as output BIS.B #0xFF,&P2DIR ; configure P2.x as output BIS.B #0xFF,&P3DIR ; configure P3.x as output BIS.B #0xFF,&P4DIR ; configure P4.x as output PUSH #arr1 ; push the address of arr1 PUSH #8 ; push the number of elements PUSH #0 ; push display id CALL #suma_sp ADD #6,SP ; collapse the stack PUSH #arr2 ; push the address of arr1 PUSH #7 ; push the number of elements PUSH #1 ; push display id CALL #suma_sp ADD #6,SP ; collapse the stack JMP $ arr1 DC16 1, 2, 3, 4, 1, 2, 3, 4 ; the first array arr2 DC16 1, 1, 1, 1, -1, -1, -1 ; the second array END CPE 323 Intro2EmbeddedSystems 30 Sum Up Two Integer Arrays (ver3) /*------------------------------------------------------------------------------ * Program : Find a sum of two integer arrays * Input : The input arrays are signed 16-bit integers in arr1 and arr2 * Output : Display sum of arr1 on P1OUT&P2OUT and sum of arr2 on P3OUT&P4OUT * Modified by: A. Milenkovic, milenkovic@computer.org * Date : September 14, 2008 * Description: MSP430 IAR EW; Demonstration of the MSP430 assembler *------------------------------------------------------------------------------*/ #include "msp430.h" ; #define controlled include file NAME main ; module name PUBLIC main ; make the main label visible ; outside this module EXTERN suma_sp ORG 0FFFEh DC16 init ; set reset vector to 'init' label RSEG CSTACK ; pre-declaration of segment RSEG CODE ; place program in 'CODE' segment init: MOV #SFE(CSTACK), SP ; set up stack CPE 323 Intro2EmbeddedSystems 31 Sum Up Two Integer Arrays (ver3) main: NOP ; main program MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer BIS.B #0xFF,&P1DIR ; configure P1.x as output BIS.B #0xFF,&P2DIR ; configure P2.x as output BIS.B #0xFF,&P3DIR ; configure P3.x as output BIS.B #0xFF,&P4DIR ; configure P4.x as output PUSH #arr1 ; push the address of arr1 PUSH #8 ; push the number of elements PUSH #0 ; push display id CALL #suma_sp ADD #6,SP ; collapse the stack PUSH #arr2 ; push the address of arr1 PUSH #7 ; push the number of elements PUSH #1 ; push display id CALL #suma_sp ADD #6,SP ; collapse the stack JMP $ arr1 DC16 1, 2, 3, 4, 1, 2, 3, 4 ; the first array arr2 DC16 1, 1, 1, 1, -1, -1, -1 ; the second array END CPE 323 Intro2EmbeddedSystems 32 Outline Assembly Language Programming Adding two 32-bit numbers (decimal, integers) Counting characters ‘E’ Subroutines CALL&RETURN Subroutine Nesting Passing parameters Stack and Local Variables C and the MSP430 CPE 323 Intro2EmbeddedSystems 35 Compiling a C Program: Example #1 #include "io430.h" int main( void ) { int i1, i2; unsigned int ui1; short int sint1; long int lint2; int a[4]; // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; i1 = 2; i2 = -2; ui1=65535; sint1=127; lint2=128243; a[0]=20; a[1]=9; return 0; } CPE 323 Intro2EmbeddedSystems 36 Example #1 Compiler Generated List File (no optimization) ############################################################################### # # # IAR MSP430 C/C++ Compiler V4.11C/W32 [Kickstart] 21/Sep/2008 20:24:33 # # Copyright 1996-2008 IAR Systems. All rights reserved. # # # # __rt_version = 3 # # __double_size = 32 # # __reg_r4 = free # # __reg_r5 = free # # __pic = no # # __core = 430 # # Source file = C:\Documents and Settings\Aleksandar\My # # Documents\Work\teaching\cpe323-08F\tutorial\test_dtypes # # .c # # Command line = "C:\Documents and Settings\Aleksandar\My # # Documents\Work\teaching\cpe323-08F\tutorial\test_dtypes # # .c" -lC "C:\Documents and Settings\Aleksandar\My # # Documents\Work\teaching\cpe323-08F\tutorial\Debug\List\ # # " -o "C:\Documents and Settings\Aleksandar\My # # Documents\Work\teaching\cpe323-08F\tutorial\Debug\Obj\" # # --no_cse --no_unroll --no_inline --no_code_motion # # --no_tbaa --debug -D__MSP430F149__ -e --double=32 -I # # "C:\Program Files\IAR Systems\Embedded Workbench # # 5.0\430\INC\" -Ol --multiplier=16 # # List file = C:\Documents and Settings\Aleksandar\My # # Documents\Work\teaching\cpe323-08F\tutorial\Debug\List\ # # test_dtypes.lst # # Object file = C:\Documents and Settings\Aleksandar\My # # Documents\Work\teaching\cpe323-08F\tutorial\Debug\Obj\t # # est_dtypes.r43 # # # # # ############################################################################### CPE 323 Intro2EmbeddedSystems 37 Example #1 Compiler Generated List File (no optimization) 1 #include "io430.h" \ In segment DATA16_AN, at 0x120 \ union <unnamed> volatile __data16 _A_WDTCTL \ _A_WDTCTL: \ 000000 DS8 2 \ In segment CODE, align 2 2 int main( void ) { \ main: \ 000000 0A12 PUSH.W R10 \ 000002 0812 PUSH.W R8 \ 000004 0912 PUSH.W R9 \ 000006 3182 SUB.W #0x8, SP 3 int i1, i2; ^ Warning[Pe550]: variable "i1" was set but never used int i1, i2; ^ "C:\Documents and Settings\Aleksandar\My Documents\Work\teaching\cpe323- 08F\tutorial\test_dtypes.c",3 Warning[Pe550]: variable "i2" was set but never used 4 unsigned int ui1; ^ Warning[Pe550]: variable "ui1" was set but never used 5 short int sint1; ^ Warning[Pe550]: variable "sint1" was set but never used 6 long int lint2; ^ Warning[Pe550]: variable "lint2" was set but never used 7 int a[4]; ^ Warning[Pe550]: variable "a" was set but never used CPE 323 Intro2EmbeddedSystems 40 C Data Types, cont’d Local variables Defined inside a function Cannot be accessed from outside the function Normally lost when a return from the function is made Global variables Defined outside a function Can be accessed both from inside and outside the function Variables defined in a block exist only within that block int i; /*global variable, visible to everything from this point*/ void function_1(void) /*A function with no parameters*/ { int k; /*Integer k is local to function_1*/ { int q; /*Integer q exists only in this block*/ int j; /*Integer j is local and not the same as j in main*/ } } void main(void) { int j; /*Integer j is local to this block within function main*/ } /*This is the point at which integer j ceases to exist*/ CPE 323 Intro2EmbeddedSystems 41 Storage Class Specifiers auto Variable is no longer required once a block has been left; Default register Ask compiler to allocate the variable to a register Also is automatic Cannot be accessed by means of pointers static Allows local variable to retain its value when a block is reentered Initialized only once, by the compiler! extern Indicates that the variable is defined outside the block The same global variable can be defined in more than one module CPE 323 Intro2EmbeddedSystems 42 Storage Class Modifiers volatile To define variables that can be changed externally Compiler will not put them in registers Think about Status Registers ! const Variable may not be changed during the execution of a program Cannot be changed unintentionally, but CAN be changed externally (as a result of an I/O, or OS operations external to the C program) Type conversion In C, done either automatically or explicitly (casting) CPE 323 Intro2EmbeddedSystems 45 Example #2 Compiler Generated List File (no optimization) 14 a[0]=20; a[1]=9; \ 000028 B14014000C00 MOV.W #0x14, 0xc(SP) \ 00002E B14009000E00 MOV.W #0x9, 0xe(SP) 15 return 0; \ 000034 0C43 MOV.W #0x0, R12 \ 000036 31501400 ADD.W #0x14, SP \ 00003A 3041 RET \ 00003C REQUIRE _A_WDTCTL 16 } Maximum stack usage in bytes: Function CSTACK -------- ------ main 22 Segment part sizes: Function/Label Bytes -------------- ----- _A_WDTCTL 2 main 60 60 bytes in segment CODE 2 bytes in segment DATA16_AN 60 bytes of CODE memory 0 bytes of DATA memory (+ 2 bytes shared) Errors: none Warnings: none CPE 323 Intro2EmbeddedSystems 46 Factorial #include "stdio.h" #include "io430.h" int fact(int n); int main(void) { int n = 5; int nf; nf = fact(n); printf("n=%d, nf=%d\n", n, nf); return 0; } int fact(int n) { if(n>1) return n*fact(n-1); else return 1; } CPE 323 Intro2EmbeddedSystems 47 Factorial: List File 1 # include "stdio.h" 2 #include "io430.h" 4 int fact(int n); \ In segment CODE, align 2 6 int main(void) { \ main: \ 000000 0A12 PUSH.W R10 \ 000002 0B12 PUSH.W R11 7 8 int n = 5; \ 000004 3A400500 MOV.W #0x5, R10 9 10 int nf; 11 12 nf = fact(n); \ 000008 0C4A MOV.W R10, R12 \ 00000A B012.... CALL #fact \ 00000E 0B4C MOV.W R12, R11 13 14 printf("n=%d, nf=%d\n", n, nf); \ 000010 0B12 PUSH.W R11 \ 000012 0A12 PUSH.W R10 \ 000014 3C40.... MOV.W #`?<Constant "n=%d, nf=%d\\n">`, R12 \ 000018 B012.... CALL #printf 15 16 return 0; \ 00001C 0C43 MOV.W #0x0, R12 \ 00001E 2152 ADD.W #0x4, SP \ 000020 3B41 POP.W R11 \ 000022 3A41 POP.W R10 \ 000024 3041 RET 17 } CPE 323 Intro2EmbeddedSystems 50 Functions and Parameters 8 int main( void ) \ main: 9 { \ 000000 2182 SUB.W #0x4, SP 10 // Stop watchdog timer to prevent time out reset 11 WDTCTL = WDTPW + WDTHOLD; \ 000002 B240805A2001 MOV.W #0x5a80, &0x120 12 13 int x = 5; \ 000008 B14005000200 MOV.W #0x5, 0x2(SP) 14 int y = 6; \ 00000E B14006000000 MOV.W #0x6, 0(SP) 19 swapbyv(x, y); \ 000014 2D41 MOV.W @SP, R13 \ 000016 1C410200 MOV.W 0x2(SP), R12 \ 00001A B012.... CALL #swapbyv 24 swapbyr(&x, &y); \ 00001E 0D41 MOV.W SP, R13 \ 000020 0C41 MOV.W SP, R12 \ 000022 2C53 ADD.W #0x2, R12 \ 000024 B012.... CALL #swapbyr 29 return 0; \ 000028 0C43 MOV.W #0x0, R12 \ 00002A 2152 ADD.W #0x4, SP \ 00002C 3041 RET \ 00002E REQUIRE _A_WDTCTL 30 } CPE 323 Intro2EmbeddedSystems 51 Functions and Parameters \ In segment CODE, align 2 32 void swapbyv(int a, int b) { \ swapbyv: 33 int temp; 34 35 temp = a; \ 000000 0F4C MOV.W R12, R15 36 a = b; \ 000002 0C4D MOV.W R13, R12 37 b = temp; \ 000004 0D4F MOV.W R15, R13 38 } \ 000006 3041 RET 39 \ In segment CODE, align 2 40 void swapbyr(int *a, int *b) { \ swapbyr: 41 int temp; 42 43 temp = *a; \ 000000 2F4C MOV.W @R12, R15 44 *a = *b; \ 000002 AC4D0000 MOV.W @R13, 0(R12) 45 *b = temp; \ 000006 8D4F0000 MOV.W R15, 0(R13) 46 } \ 00000A 3041 RET Maximum stack usage in bytes: Function CSTACK -------- ------ main 6 -> swapbyv 6 -> swapbyr 6 swapbyr 2 swapbyv 2 Segment part sizes: Function/Label Bytes -------------- ----- _A_WDTCTL 2 main 46 swapbyv 8 swapbyr 12 66 bytes in segment CODE 2 bytes in segment DATA16_AN 66 bytes of CODE memory 0 bytes of DATA memory (+ 2 bytes shared) CPE 323 Intro2EmbeddedSystems 52 Pointers and C #include "io430.h" #include "stdio.h" int main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; int x = 5; // an integer x int *p_x; // a pointer to int int y1; // an integer y1 (uninitialized) long int y2, y3; // long integers y2, y3 long int *p_y2; // a pointer to long integer char mya[20] = "hello world, cpe323!"; // character array char *p_mya; // pointer to character p_x = &x; // p_x points to x y1 = 10 + x; // new value to y1 y2 = -1; p_y2 = &y2; // pointer p_y2 points to y2 y3 = 10 + *p_y2; p_mya = mya; // p_mya points to array mya p_mya = p_mya + 3; // display addresses and variables in terminal i/o printf("a.x=%x, x=%x\n", &x, x); printf("a.p_x=%x, p_x=%x\n", &p_x, p_x); printf("a.y1=%x, y1=%x\n", &y1, y1); printf("a.y2=%x, y2=%lx\n", &y2, y2); printf("a.y3=%x, y3=%lx\n", &y3, y3); printf("a.p_y2=%x, p_y2=%x\n", &p_y2, p_y2); printf("a.mya=%x, mya=%s\n", &mya, mya); printf("a.p_mya=%x, p_mya=%x\n", &p_mya, p_mya); return 0; } CPE 323 Intro2EmbeddedSystems 55 Speed and Performance of Microprocessors Why is difficult to compare the speed of two microprocessors? Performance Execution time MIPS: Million of Instructions Per Second Carefully interpret benchmarks! Clock Cycles/Bus Cycles CPE 323 Intro2EmbeddedSystems 56 Speed and Performance of Microprocessors, cont’d #include "msp430.h" ; #define controlled include file NAME main ; module name PUBLIC main ; make the main label vissible ; outside this module ORG 0FFFEh DC16 init ; set reset vector to 'init' label RSEG CSTACK ; pre-declaration of segment RSEG CODE ; place program in 'CODE' segment init: MOV #SFE(CSTACK), SP ; set up stack main: NOP ; main program MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer PUSH R14 ; R14 will serve as a frame pointer MOV SP, R14 ; R14 points to the top of the stack MOV #aend, R6 MOV R6, R5 SUB #arr1, R5 ; how many bytes is in the array SUB R5, SP ; allocate storage for array on the stack lnext: DEC R6 ; decrement pointer to arr1 DEC R14 ; decrement pointer on the stack MOV.B @R6, 0(R14) DEC R5 JNZ lnext JMP $ NOP arr1 DC8 1, 2, 3, 4, 5, 6, 7, 8, 9 aend END CPE 323 Intro2EmbeddedSystems 57 Speed and Performance of Microprocessors, cont’d #include "msp430.h" ; #define controlled include file NAME main ; module name PUBLIC main ; make the main label vissible ; outside this module ORG 0FFFEh DC16 init ; set reset vector to 'init' label RSEG CSTACK ; pre-declaration of segment RSEG CODE ; place program in 'CODE' segment init: MOV #SFE(CSTACK), SP ; 4 cc main: NOP ; 1 cc MOV.W #WDTPW+WDTHOLD,&WDTCTL ; 5 cc PUSH R14 ; 3 cc (table 3.15) MOV SP, R14 ; 1 cc MOV #aend, R6 ; 2 cc MOV R6, R5 ; 1 cc SUB #arr1, R5 ; 2 cc SUB R5, SP ; 1 cc lnext: DEC R6 ; 1 cc x 9 DEC R14 ; 1 cc x 9 MOV.B @R6, 0(R14) ; 4 cc x 9 DEC R5 ; 1 cc x 9 JNZ lnext ; 2 cc x 9 JMP $ arr1 DC8 1, 2, 3, 4, 5, 6, 7, 8, 9 aend END TOTAL NUMBER OF CLOCK CYLES: 4+1+5+3+1+2+1+2+1+9x(1+1+4+1+2) = 20+9x9 = 101 cc TOTAL NUMBER OF INSTRUCITONS 9+9x5 = 54 instructions CPI 101/54 = 1.87 cc/instruction
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved