Help for Assignment 2. Topics Tackled Handling some “C++” keywords when programming assembly code –Programming “subroutines called by subroutines” –Programming.

Slides:



Advertisements
Similar presentations
Subroutines – parameter passing passing data to/from a subroutine can be done through the parameters and through the return value of a function subroutine.
Advertisements

1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Lecture 20: 11/12/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Lecture 9: MIPS Instruction Set
Slides revised 3/25/2014 by Patrick Kelley. 2 Procedures Unlike other branching structures (loops, etc.) a Procedure has to return to where it was called.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
Computer Architecture CSCE 350
Procedures II (1) Fall 2005 Lecture 07: Procedure Calls (Part 2)
The University of Adelaide, School of Computer Science
Functions Functions and Parameters. History A function call needs to save the registers in use The called function will use the registers The registers.
Over-view of Lab. 1 For more details – see the Lab. 1 web-site There will be a 20 min prelab quiz (based on Assignment 1 and 2) at the start of the lab.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V.
Lab. 1 – Task 1 to 4 details For more details – see the Lab. 1 web-site There will be a 20 min prelab-quiz (based on Assignment 1 and 2) at the start of.
Display Interrupt Service Routine for cargo monitoring system Overview of concepts demonstrated during Labs 3 and 4.
Understanding the Blackfin ADSP-BF5XX Assembly Code Format
Help for Lab. 1 Subroutines calling Subroutines. Lab 1 – Application stream File “interruptservice.cpp” extern volatile boolean mute_on; extern volatile.
1. 2 FUNCTION INLINE FUNCTION DIFFERENCE BETWEEN FUNCTION AND INLINE FUNCTION CONCLUSION 3.
Overview scope - determines when an identifier can be referenced in a program storage class - determines the period of time during which that identifier.
Later tasks of Lab. 1 For more details – see the Lab. 1 web-site There will be a 20 min prelab quiz (based on Assignment 1 and 2) at the start of the lab.
CS2422 Assembly Language & System Programming November 7, 2006.
Tutorial Essentially all the Blackfin instruction you need for all of ENCM511. The instructions are easy. Its knowing when to use them that is the difficult.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2013 CMPE-013/L Modules and Scope Gabriel Hugh Elkaim Spring 2013.
Input Laboratory: GPIO Pin control needed to have the Blackfin accept your commands Re-uses information from ENEL353 and ENCM369 courses and text books.
Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 9/19/2015 Review of 50% OF ENCM369 in 50 minutes1.
Blackfin Array Handling Part 2 Moving an array between locations int * MoveASM( int foo[ ], int fee[ ], int N);
MIPS function continued. Recursive functions So far, we have seen how to write – A simple function – A simple function that have to use the stack to save.
Help for Lab. 1 Subroutines calling Subroutines. Topics tackled today Handling some “C++” keywords when programming assembly code  Programming “subroutines.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM511.
Generating “Rectify( )” Test driven development approach to TigerSHARC assembly code production Assembly code examples Part 1 of 3.
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Subroutines, parameters and the stack Bryan Duggan.
Blackfin Array Handling Part 1 Making an array of Zeros void MakeZeroASM(int foo[ ], int N);
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Works for other quizzes and exams too A FEW SLIDES ARE UPDATED OVER THE SLIDES IN THE NOTES 1 Hints for Post-Lab Quiz 1.
CE-2810 Dr. Mark L. Hornick 1 Mixing C and assembly Safety goggles on!
Building a simple loop using Blackfin assembly code If you can handle the while-loop correctly in assembly code on any processor, then most of the other.
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 2/26/2016 Review of 50% OF ENCM369 in 50 minutes1.
Assembly Language Review Being able to repeat on the Blackfin the things we were able to do on the MIPS 3/3/2016 Review of 50% OF ENCM369 in 50 minutes1.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM415.
Handling multiple input signals. Midterm question Light sensor is in front of the door  Light signs on light sensor  If person blocking light – light.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Function Calling. Mips Assembly Call and Return Steps for procedure calling –Save the return address –Jump to the procedure (function) –Execute the procedure.
“Lab. 5” – Updating Lab. 3 to use DMA Test we understand DMA by using some simple memory to memory DMA Make life more interesting, since hardware is involved,
Storage Allocation Mechanisms
Lecture 5: Procedure Calls
Help for Lab. 1 Subroutines calling Subroutines
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Generating the “Rectify” code (C++ and assembly code)
Generating “Rectify( )”
A Play Core Timer Interrupts
The planned and expected
Generating a software loop with memory accesses
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Using Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
A Play Lab. 2 Task 8 Core Timer Interrupts
Assembly Language Review
Hints for Post-Lab Quiz 1
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
Tutorial Essentially all the Blackfin instruction you need for all of ENCM511. The instructions are easy. Its knowing when to use them that is the difficult.
Explaining issues with DCremoval( )
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
Input Laboratory: GPIO Pin control needed to have the Blackfin accept your commands Re-uses information from ENEL353 and ENCM369 courses and text books.
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
Handling multiple input signals
Display Interrupt Service Routine for cargo monitoring system
Blackfin Syntax Stores, Jumps, Calls and Conditional Jumps
Presentation transcript:

Help for Assignment 2

Topics Tackled Handling some “C++” keywords when programming assembly code –Programming “subroutines called by subroutines” –Programming “extern” variables –Programming “volatile” variables Understanding what I did when –Programming “subroutines called by subroutines” –Programming “extern” variables –Programming “volatile” variables

Subroutine calling subroutine All void functions File “bloodEnglishmanASM.asm”.extern _Fee__Fv;.extern _Fi__Fv;.extern _Fo__Fv;.section program;.global _Fum__Fv; _Fum__Fv: LINK 16; CALL _Fee __Fv; LINK 16; CALL _Fee __Fv; CALL _Fi __Fv; CALL _Fi __Fv; CALL _Fo__Fv; CALL _Fo__Fv; P0 = [FP +4]; UNLINK; UNLINK;_Fum__Fv.END: JUMP (P0); JUMP (P0); File “bloodEnglishmanCPP.cpp” void Fee(void); void Fi(void); void Fo(void); void Fum(void); void Fum(void) { Fee( ); Fee( ); Fi( ); Fi( ); Fo( ); Fo( );}

What nursery rhyme? Fe,Fi,Fo,Fum, I smell the blood of an Englishman?

Subroutine calling subroutine All integer functions File “bloodEnglishmanASM.asm”.extern _Fee__Fi;.extern _Fi__Fi;.extern _Fo__Fi;.section program;.global _Fum__Fi; _Fum__Fi: // value passed in R0 LINK 16; LINK 16; R0 += 6; // pass parameter in R0 R0 += 6; // pass parameter in R0 CALL _Fee __Fi; CALL _Fee __Fi; R0 = 7; // pass parameter in R0 CALL _Fi __Fi; CALL _Fi __Fi; R0 = 8; // pass parameter in R0 CALL _Fo__Fi; CALL _Fo__Fi; P0 = [FP +4]; UNLINK; UNLINK;_Fum__Fi.END: JUMP (P0); JUMP (P0); File “bloodEnglishmanCPP.cpp” void Fee(int); void Fi(int); void Fo(int); void Fum(int); void Fum(int value) { Fee(6 + value); Fee(6 + value); Fi(7); Fi(7); Fo(8); Fo(8);}

Subroutine calling subroutine All integer functions.extern _Fee__Fi;.extern _Fi__Fi;.extern _Fo__Fi;.section program;.global _Fum__Fi; _Fum__Fi: // value passed in R0 LINK 16; LINK 16; [--SP] = R0; // Save passed value [--SP] = R0; // Save passed value R0 = 6; // pass parameter in R0 R0 = 6; // pass parameter in R0 CALL _Fee __Fi; CALL _Fee __Fi; R0 = 7; // pass parameter in R0 CALL _Fi __Fi; CALL _Fi __Fi; R0 = [SP++]; // Recover passed value R0 += 8; // pass parameter in R0 R0 += 8; // pass parameter in R0 CALL _Fo__Fi; CALL _Fo__Fi; P0 = [FP +4]; UNLINK; UNLINK;_Fum__Fi.END: JUMP (P0); JUMP (P0); File “bloodEnglishmanCPP.cpp” void Fee(int); void Fi(int); void Fo(int); void Fum(int); void Fum(int value) { Fee(6); Fee(6); Fi(7); Fi(7); Fo(8 + value); Fo(8 + value);}

Subroutine calling subroutine All integer functions -- Better.extern _Fee__Fi;.extern _Fi__Fi;.extern _Fo__Fi;.section program;.global _Fum__Fi; _Fum__Fi: // value passed in R0 LINK 16; LINK 16; [FP + 8] = R0; // Save passed value [FP + 8] = R0; // Save passed value R0 = 6; // pass parameter in R0 R0 = 6; // pass parameter in R0 CALL _Fee __Fi; CALL _Fee __Fi; R0 = 7; // pass parameter in R0 CALL _Fi __Fi; CALL _Fi __Fi; R0 = [FP + 8]; // Recover passed value R0 += 8; // pass parameter in R0 R0 += 8; // pass parameter in R0 CALL _Fo__Fi; CALL _Fo__Fi; P0 = [FP +4]; UNLINK; UNLINK;_Fum__Fi.END: JUMP (P0); JUMP (P0); File “bloodEnglishmanCPP.cpp” void Fee(int); void Fi(int); void Fo(int); void Fum(int); void Fum(int value) { Fee(6); Fee(6); Fi(7); Fi(7); Fo(8 + value); Fo(8 + value);}

extern long int.extern _thumb;.section L1_cache;.global _plumb[5] = {1, 2, 3, 4, 5};.section program;.global _Jack__FPl; // Pointer long _Jack__FPl: // pointer passed in R0 LINK 16; LINK 16; P0 = R0; // Use passed value as a pointer P0 = R0; // Use passed value as a pointer P1.L = _thumb; P1.L = _thumb; P1.H = _thumb; P1.H = _thumb; R0 = [P1 + (2 * 4)]; // LOAD R0 = [P1 + (2 * 4)]; // LOAD P1.L = _plumb; P1.L = _plumb; P1.H = _plumb; P1.H = _plumb; R1= [P1 + (1 * 4)]; // LOAD R1= [P1 + (1 * 4)]; // LOAD R0 = R0 + R1; R0 = R0 + R1; [P0 + (1 * 4)] = R0; // STORE [P0 + (1 * 4)] = R0; // STORE P0 = [FP +4]; UNLINK; UNLINK; _ Jack__FPl.END:: JUMP (P0); JUMP (P0); File “PutInHisThumb.cpp” extern long int thumb[10]; long int plumb[5] = {1, 2, 3, 4, 5} long int Jack(long int *goodboy) long int Jack(long int *goodboy{ long int sum; long int sum; goodboy[3] = thumb[2] + plumb[1] goodboy[3] = thumb[2] + plumb[1]}

extern volatile long int.extern _thumb;.section L1_cache;.global _plumb[5] = {1, 2, 3, 4, 5};.section program;.global _Jack__FPl; // Pointer long _Jack__FPl: // pointer passed in R0 LINK 16; LINK 16; P0 = R0; // Use passed value as a pointer P0 = R0; // Use passed value as a pointer P1.L = _thumb; P1.L = _thumb; P1.H = _thumb; P1.H = _thumb; R0 = [P1 + (2 * 4)]; // LOAD R0 = [P1 + (2 * 4)]; // LOAD P1.L = _plumb; P1.L = _plumb; P1.H = _plumb; P1.H = _plumb; R1= [P1 + (1 * 4)]; // LOAD R1= [P1 + (1 * 4)]; // LOAD R0 = R0 + R1; R0 = R0 + R1; [P0 + (1 * 4)] = R0; // STORE [P0 + (1 * 4)] = R0; // STORE P0 = [FP +4]; UNLINK; UNLINK;_Jack__FPl.END: JUMP (P0); JUMP (P0); File “PutInHisThumb.cpp” extern volatile long int thumb[10]; long int plumb[5] = {1, 2, 3, 4, 5} long int Jack(long int *goodboy) long int Jack(long int *goodboy{ long int sum; long int sum; goodboy[3] = thumb[2] + plumb[1] goodboy[3] = thumb[2] + plumb[1]}

extern long int – optimized code.extern _star;.extern _BlinkLight__Fv;.section program;.global _Wonderwhat__Fv; _Wonderwhat__Fv: LINK 16; P0 = R0; // Use passed value as a pointer P0 = R0; // Use passed value as a pointer P1.L = _thumb; P1.L = _thumb; P1.H = _thumb; P1.H = _thumb; R0 = [P1 + (2 * 4)]; // LOAD R0 = [P1 + (2 * 4)]; // LOAD CC = R0 == 2; CC = R0 == 2; IF !CC JUMP DONE; IF !CC JUMP DONE; LOOP: CALL _BlinkLight__Fv; JUMP LOOP; DONE: P0 = [FP +4]; UNLINK; UNLINK; _Wonderwhat__Fv.END: JUMP (P0); JUMP (P0); File “TwinkleTwinkle.cpp” extern long int star[10]; void WonderWhat(void); void BlinkLight(void); void WonderWhat(void) { while (star[2] == 2) { while (star[2] == 2) { BlinkLight( ); BlinkLight( ); }} Either star[2] == 2, or it does not If star[2] == 2 then get an infinite loop

extern volatile long int optimized code.extern _star;.extern _BlinkLight__Fv;.section program;.global _Wonderwhat__Fv; _Wonderwhat__Fv: LINK 16; P0 = R0; // Use passed value as a pointer P0 = R0; // Use passed value as a pointer P1.L = _thumb; P1.L = _thumb; P1.H = _thumb; P1.H = _thumb;LOOP: R0 = [P1 + (2 * 4)]; // KEEP LOADING R0 = [P1 + (2 * 4)]; // KEEP LOADING CC = R0 == 2; // LOOP NEEDED CC = R0 == 2; // LOOP NEEDED IF !CC JUMP DONE; IF !CC JUMP DONE; CALL _BlinkLight__Fv; JUMP LOOP; CALL _BlinkLight__Fv; JUMP LOOP;DONE: P0 = [FP +4]; UNLINK; UNLINK; _Wonderwhat__Fv.END: JUMP (P0); JUMP (P0); File “TwinkleTwinkle.cpp” extern volatile long int star[10]; void WonderWhat(void); void BlinkLight(void); void WonderWhat(void) { while (star[2] == 2) { while (star[2] == 2) { BlinkLight( ); BlinkLight( ); }} star[2] == 2 MAY START OFF BEING 2 But since star is “volatile” then some external action may change it. Loop needed in optimized code if “volatile” memory value

Understanding what I did Will look at things in more detail later in class But here are some ideas of why we did what we did

Subroutine calling subroutine All void functions File “bloodEnglishmanASM.asm”.extern _Fee__Fv;.extern _Fi__Fv;.extern _Fo__Fv;.section program;.global _Fum__Fv; _Fum__Fv: Since the other functions are coded “outside” or “external” to this file then we indicate that with the keyword.extern File “bloodEnglishmanCPP.cpp” void Fee(void); void Fi(void); void Fo(void); void Fum(void); void Fum(void) { }

Subroutine calling subroutine All void functions File “bloodEnglishmanASM.asm”.extern _Fee__Fv;.extern _Fi__Fv;.extern _Fo__Fv;.section program;.global _Fum__Fv; _Fum__Fv: Since we want other functions (coded “outside” or “external” to this file) to be able to use Fum( ) coded in this file we must “globalize” (tell everybody) this functions name with the keyword.global File “bloodEnglishmanCPP.cpp” void Fee(void); void Fi(void); void Fo(void); void Fum(void); void Fum(void) { }

Subroutine calling subroutine All void functions File “bloodEnglishmanASM.asm”.extern _Fee__Fv;.extern _Fi__Fv;.extern _Fo__Fv;.section program;.global _Fum__Fv; _Fum__Fv: LINK 16; CALL _Fee __Fv; LINK 16; CALL _Fee __Fv; CALL _Fi __Fv; CALL _Fi __Fv; CALL _Fo__Fv; CALL _Fo__Fv; P0 = [FP +4]; UNLINK; UNLINK;_Fum__Fv.END: JUMP (P0); JUMP (P0); The LINK 16; operation saves this subroutine’s return address (stored in the “RETurn from Subroutine register” RETS) onto the stack. This allows the processor to use register RETS when it calls other subroutines – same was as the MIPS – different register name UNLINK restores (recovers, reads) RETS from the stack so we can exit this subroutine.

Subroutine calling subroutine All integer functions.extern _Fee__Fi;.extern _Fi__Fi;.extern _Fo__Fi;.section program;.global _Fum__Fi; _Fum__Fi: // value passed in R0 LINK 16; LINK 16; [--SP] = R0; // Save passed value [--SP] = R0; // Save passed value R0 = 6; // pass parameter in R0 R0 = 6; // pass parameter in R0 CALL _Fee __Fi; CALL _Fee __Fi; R0 = 7; // pass parameter in R0 CALL _Fi __Fi; CALL _Fi __Fi; R0 = [SP++]; // Recover passed value R0 += 8; // pass parameter in R0 R0 += 8; // pass parameter in R0 CALL _Fo__Fi; CALL _Fo__Fi; P0 = [FP +4]; UNLINK; UNLINK;_Fum__Fi.END: JUMP (P0); JUMP (P0); Name mangle changes (Do not need to remember details in quizzes and exams – critical to get correct in labs) void Foo(void)  _Foo__Fv int Foo(void)  _Foo__Fv int Foo(int)  _Foo__Fi int Foo(long int)  _Foo__Fl int Foo(int *)  _Foo__FPi Int Foo(long int *)  _Foo_FPl Can’t overload on the basis of return value

Subroutine calling subroutine All integer functions.extern _Fee__Fi;.extern _Fi__Fi;.extern _Fo__Fi;.section program;.global _Fum__Fi; _Fum__Fi: // value passed in R0 LINK 16; LINK 16; [--SP] = R0; // Save passed value [--SP] = R0; // Save passed value R0 = 6; // pass parameter in R0 R0 = 6; // pass parameter in R0 CALL _Fee __Fi; CALL _Fee __Fi; R0 = 7; // pass parameter in R0 CALL _Fi __Fi; CALL _Fi __Fi; R0 = [SP++]; // Recover passed value R0 += 8; // pass parameter in R0 R0 += 8; // pass parameter in R0 CALL _Fo__Fi; CALL _Fo__Fi; P0 = [FP +4]; UNLINK; UNLINK;_Fum__Fi.END: JUMP (P0); JUMP (P0); void Fum(int value) { Fee(6); Fee(6); Fi(7); Fi(7); Fo(8 + value); Fo(8 + value);} ALWAYS pass the parameter to the subroutine in R0 – very similar to MIPS

Subroutine calling subroutine All integer functions.extern _Fee__Fi;.extern _Fi__Fi;.extern _Fo__Fi;.section program;.global _Fum__Fi; _Fum__Fi: // value passed in R0 LINK 16; LINK 16; [--SP] = R0; // Save passed value [--SP] = R0; // Save passed value R0 = 6; // pass parameter in R0 R0 = 6; // pass parameter in R0 CALL _Fee __Fi; CALL _Fee __Fi; R0 = 7; // pass parameter in R0 CALL _Fi __Fi; CALL _Fi __Fi; R0 = [SP++]; // Recover passed value R0 += 8; // pass parameter in R0 R0 += 8; // pass parameter in R0 CALL _Fo__Fi; CALL _Fo__Fi; P0 = [FP +4]; UNLINK; UNLINK;_Fum__Fi.END: JUMP (P0); JUMP (P0); void Fum(int value) { Fee(6); Fee(6); Fi(7); Fi(7); Fo(8 + value); Fo(8 + value);} Must save the passed value (in R0) onto the stack, otherwise it will be destroyed when we call the other subroutines while we use R0 to pass the parameter

Note – We can store on the stack using SP or FP (same as MIPS).extern _Fee__Fi;.extern _Fi__Fi;.extern _Fo__Fi;.section program;.global _Fum__Fi; _Fum__Fi: // value passed in R0 LINK 16; LINK 16; [FP + 8] = R0; // Save passed value [FP + 8] = R0; // Save passed value R0 = 6; // pass parameter in R0 R0 = 6; // pass parameter in R0 CALL _Fee __Fi; CALL _Fee __Fi; R0 = 7; // pass parameter in R0 CALL _Fi __Fi; CALL _Fi __Fi; R0 = [FP + 8]; // Recover passed value R0 += 8; // pass parameter in R0 R0 += 8; // pass parameter in R0 CALL _Fo__Fi; CALL _Fo__Fi; P0 = [FP +4]; UNLINK; UNLINK;_Fum__Fi.END: JUMP (P0); JUMP (P0);.extern _Fee__Fi;.extern _Fi__Fi;.extern _Fo__Fi;.section program;.global _Fum__Fi; _Fum__Fi: // value passed in R0 LINK 16; LINK 16; [SP ] = R0; // Save passed value [SP ] = R0; // Save passed value R0 = 6; // pass parameter in R0 R0 = 6; // pass parameter in R0 CALL _Fee __Fi; CALL _Fee __Fi; R0 = 7; // pass parameter in R0 CALL _Fi __Fi; CALL _Fi __Fi; R0 = [SP ] // Recover passed value R0 += 8; // pass parameter in R0 R0 += 8; // pass parameter in R0 CALL _Fo__Fi; CALL _Fo__Fi; P0 = [FP +4]; UNLINK; UNLINK;_Fum__Fi.END: JUMP (P0); JUMP (P0);

This does not link and run Why not? A project containing only the file “PutInHisThumb.cpp” will not link and run because All projects must have a main( ) in them File “PutInHisThumb.cpp” extern long int thumb[10]; long int plumb[5] = {1, 2, 3, 4, 5} long int Jack(long int *goodboy) long int Jack(long int *goodboy{ long int sum; long int sum; goodboy[3] = thumb[2] + plumb[1] goodboy[3] = thumb[2] + plumb[1]}

This does not link and run Why not? File “main.cpp” extern long int thumb[10]; extern long int plumb[5] ; long int goodboy[10]; long int Jack(long int *goodboy) int main(void) { for (int count = 0; count < 10; count++) goodboy[count] = 0; goodboy[count] = 0; Jack(goodboy); Jack(goodboy); printf(“%d\n”, goodboy[3]); printf(“%d\n”, goodboy[3]);} File “PutInHisThumb.cpp” extern long int thumb[10]; long int plumb[5] = {1, 2, 3, 4, 5} long int Jack(long int *goodboy) long int Jack(long int *goodboy{ long int sum; long int sum; goodboy[3] = thumb[2] + plumb[1] goodboy[3] = thumb[2] + plumb[1]}

This does not link and run Why not? DECLARED IN ANOTHER FILE DECLARED IN THIS FILE File “main.cpp” extern long int thumb[10]; extern long int plumb[5] ; long int goodboy[10]; File “PutInHisThumb.cpp” extern long int thumb[10]; long int plumb[5] = {1, 2, 3, 4, 5} DECLARED IN ANOTHER FILE DECLARED IN THIS FILE IN NO FILE HAS MEMORY SPACE BEEN SET ASIDE FOR THE “THUMB” ARRAY

This does link and run -- because all arrays have been given “space” File “main.cpp” long int thumb[10] = {2, 4, 6, 8, 10}; extern long int plumb[5] ; long int goodboy[10]; long int Jack(long int *goodboy) int main(void) { for (int count = 0; count < 10; count++) goodboy[count] = 0; goodboy[count] = 0; Jack(goodboy); Jack(goodboy); printf(“%d\n”, goodboy[3]); printf(“%d\n”, goodboy[3]);} File “PutInHisThumb.cpp” extern long int thumb[10]; long int plumb[5] = {1, 2, 3, 4, 5} long int Jack(long int *goodboy) long int Jack(long int *goodboy{ long int sum; long int sum; goodboy[3] = thumb[2] + plumb[1] goodboy[3] = thumb[2] + plumb[1]}

How can something in memory change like this.extern _star;.extern _BlinkLight__Fv;.section program;.global _Wonderwhat__Fv; _Wonderwhat__Fv: LINK 16; P0 = R0; // Use passed value as a pointer P0 = R0; // Use passed value as a pointer P1.L = _thumb; P1.L = _thumb; P1.H = _thumb; P1.H = _thumb;LOOP: R0 = [P1 + (2 * 4)]; // KEEP LOADING R0 = [P1 + (2 * 4)]; // KEEP LOADING CC = R0 == 2; // LOOP NEEDED CC = R0 == 2; // LOOP NEEDED IF !CC JUMP DONE; IF !CC JUMP DONE; CALL _BlinkLight__Fv; JUMP LOOP; CALL _BlinkLight__Fv; JUMP LOOP;DONE: P0 = [FP +4]; UNLINK; UNLINK; _Wonderwhat__Fv.END: JUMP (P0); JUMP (P0); File “TwinkleTwinkle.cpp” extern volatile long int star[10]; void WonderWhat(void); void BlinkLight(void); void WonderWhat(void) { while (star[2] == 2) { while (star[2] == 2) { BlinkLight( ); BlinkLight( ); }} star[2] == 2 MAY START OFF BEING 2 But since star is “volatile” then some external action may change it. Loop with repeated read needed in optimized code if “volatile” memory value

Example from Lab. 1 Task 4 Lab. 1 Task 4 There is a main routine There is an “interrupt audio” routine. Every 1 / s the interrupt routine “interrupts” (temporarily halts) main( ), then runs itself, and then returns control to main Interrupts run under “external control” when “something happens” –switch changes or voltage changes -- unexpected Subroutines run under “internal control” –ONLY WHEN CALLED – NEVER UNEXPECTED

Example from Lab. 1 Task 4 File “main.cpp” volatile boolean mute_on = FALSE; long int ReadSwitches(void); int main( ) InitializeSwitches( ); InitializeSwitches( ); InitializeAudio( ); StartInterrupts( ); InitializeAudio( ); StartInterrupts( ); while (1) { while (1) { int value = ReadSwitches( ); int value = ReadSwitches( ); // If switch pressed // – turn off sound; if (value == 0x100) mute_on = TRUE; else mute_on = FALSE; if (value == 0x100) mute_on = TRUE; else mute_on = FALSE; }} File “interruptservice.cpp” extern volatile boolean mute_on; void Process_DataASM(void); EX_INTERRUPT_HANDLER(Sport0_RX_ISR){ …….. /// Lots of good stuff Process_DataASM( ); Process_DataASM( ); // Make the sound occur // Make the sound occur …….. // Lots of more good stuff;} void Process_DataASM(void) { if (mute_on = = FALSE) MakeTheSound( ); if (mute_on = = FALSE) MakeTheSound( );} WORRY ABOUT WHAT EX_INTERRUPT_HANDLER( ) MEANS IN LAB. 2