EE 319 K Introduction to Microcontrollers Lecture 4























- Slides: 23
EE 319 K Introduction to Microcontrollers Lecture 4: Debugging, Arithmetic Operations, Condition Code Bits 4 -
Debugging q Aka, Testing, Diagnostics, Verification q Debugging Actions v Functional debugging, input/output values v Performance debugging, input/output values with time v Tracing, measure sequence of operations v Profiling, o measure percentage for tasks, o time relationship between tasks Ramesh Yerraballi v Performance measurement, how fast it executes v Optimization, make tradeoffs for overall good o o o improve speed, improve accuracy, reduce memory, reduce power, reduce size, reduce cost 4 -2
Debugging Intrusiveness q Intrusive Debugging v degree of perturbation caused by the debugging itself v how much the debugging slows down execution q Non-intrusive Debugging v characteristic or quality of a debugger v allows system to operate as if debugger did not exist v e. g. , logic analyzer, ICE, BDM Ramesh Yerraballi q Minimally intrusive v negligible effect on the system being debugged v e. g. , dumps(Scan. Point) and monitors q Highly intrusive v print statements, breakpoints and single -stepping 4 -3
Debugging Aids in TExas Interface q uc – View. Box, Break. Points q stk – Stack. Field, Memory. Box q Modes v v Follow. PC Cycle. View Instruction. View Log. Record Run time errors q Read from unprogrammed ROM q Write to ROM q Read from uninitialized RAM q Read/write unimplemented I/O q Single Step, Few, Step. Over, Step. Out, Run q Breakpoint versus Scan. Point Ramesh Yerraballi 4 -4
… Debugging q Instrumentation: Code we add to the system that aids in debugging v E. g. , print statements v Good practice: Define instruments with specific pattern in their names v Use instruments that test a run time global flag o leaves a permanent copy of the debugging code o causing it to suffer a runtime overhead o simplifies “on-site” customer support. v Use conditional compilation (or conditional assembly) o TExa. S does not support conditional assembly o Easy to remove all instruments q Visualization: How the debugging information is displayed q We will look at the following examples* v Simple_DP 512 asm. zip v Square_DP 512 asm. zip *: Downloadable from Jon’s site: http: //users. ece. utexas. edu/~valvano/Starterfiles/ Ramesh Yerraballi 4 -5
TExas in Real Mode We will run Simple in both Simulation mode and Real Mode. Note: v Use the cutout sheet between the 9 S 12 board and the breadboard to help identify pins v If you do not know the COM port then enter 0 v Make all connections/disconnections with power supply off v Place 9 S 12 board in “LOAD” mode when loading and debugging code v To use embedded system mode(8 MHz) switch the board to RUN mode and you may disconnect the RS 232 cable interface. v Is your PP 7 light flashing three times slower in RUN mode Ramesh Yerraballi 4 -6
Arithmetic Operations q Question 1. How many bits does it take to store the result of two unsigned 8 -bit numbers added together? q Question 2. How many bits does it take to store the result of two unsigned 8 -bit numbers subtracted? q Question 3. How many bits does it take to store the result of two unsigned 8 -bit numbers multiplied together? Ramesh Yerraballi 4 -7
… Arithmetic Operations q Question 4. How many bits does it take to store the result of two unsigned 8 -bit numbers added together? v 0 + 0 = 0, 255+255 = 510 0 to 510 is 9 bits q Question 5. How many bits does it take to store the result of two unsigned 8 -bit numbers subtracted? v 0 - 255 = -255, 255 -0 = 255 -255 to +255 is 9 bits q Question 6. How many bits does it take to store the result of two unsigned 8 -bit numbers multiplied together? v 0 * 0 = 0, 255*255 = 65025 Ramesh Yerraballi 0 to 65025 is 16 bits 4 -8
Add and Subtract Operations INH Ramesh Yerraballi 4 -9
+, -: Condition Code Register q C set after an unsigned add if the answer is wrong q V set after a signed add if the answer is wrong Ramesh Yerraballi 4 -10
Unsigned number wheel 96+64 224+64 C bit Set C bit Cleared The carry bit, C, is set after an unsigned addition or subtraction when the result is incorrect. Ramesh Yerraballi 4 -11
Trick q Whenever you directly add 2 unsigned 8 -bit numbers and the answer is more than 255, C bit is SET. The final answer is obtained by subtracting 256 from the direct addition. For example: 255 + 5 = 260, C = 1 and the actual answer is 260 -256 = 4 Ramesh Yerraballi 4 -12
Unsigned Number Wheel 160 -64 C bit Cleared 32 -64 C bit Set The carry bit, C, is normally set when we cross over from 255 to 0 while adding, or cross over from 0 to 255 while subtracting. Ramesh Yerraballi 4 -13
Trick q Whenever you directly subtract 2 unsigned 8 -bit numbers and the answer is negative, C bit is SET. The final answer is obtained by adding 256 to the direct subtraction. For example: 5 - 255 = -250, C = 1 and the actual answer is -250+256 = 6 Ramesh Yerraballi 4 -14
Signed Number Wheel -32+64 V bit Cleared 96+64 V bit Set The overflow bit, V, is set after a signed addition or subtraction when the result is incorrect. Ramesh Yerraballi 4 -15
Signed Number Wheel 32 -64 V bit Cleared -96 -64 V bit Set The overflow bit, V, is normally set when we cross over from 127 to -128 while adding or cross over from -128 to 127 while subtracting. Ramesh Yerraballi 4 -16
Addition Summary Let the result R be the result of the addition A+B. q N bit is set v v v if unsigned result is above 127 or if signed result is negative. N = R 7 q Z bit is set if result is zero q V bit is set after a signed addition if result is incorrect v V= q C bit is set after an unsigned addition if result is incorrect v C= Ramesh Yerraballi 4 -17
Subtraction Summary Let the result R be the result of the addition A-B. q N bit is set v v v if unsigned result is above 127 or if signed result is negative. N = R 7 q Z bit is set if result is zero q V bit is set after a signed subtraction if result is incorrect v V= q C bit is set after an unsigned subtraction if result is incorrect v C= Ramesh Yerraballi 4 -18
Problem When you perform (32 – 129) in an 8 -bit system what is the status of the NZVC bits? Answer = 159 NZVC = 1011 Ramesh Yerraballi 4 -19
Unsigned Promotion q Promotion involves increasing the precision of the input numbers, and performing the operation at that higher precision decimal 224 + 64 288 Ramesh Yerraballi 8 -bit 1110, 0000 +0100, 0000 0010, 0000 16 -bit 0000, 1110, 0000 +0000, 0100, 0000, 0001, 0010, 0000 4 -20
Unsigned Ceiling and Floor Ramesh Yerraballi 4 -21
Signed Promotion q. To promote a signed number, we duplicate the sign bit decimal -96 - 64 -160 Ramesh Yerraballi 8 -bit 1010, 0000 -0100, 0000 0110, 0000 16 -bit 1111, 1010, 0000 -0000, 0100, 0000 1111, 0110, 0000 4 -22
Signed Ceiling and Floor Ramesh Yerraballi 4 -23