Programming and Problem Solving: ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Programming and Problem Solving: ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Problem Solving
Modular Design
Subroutines
Flowchart
330_04
Flowcharting
330_04
Example 4.1
Write instructions to load two bytes (37H and 92H) in data registers REG0 and REG1. Add the bytes and store the sum in REG2. Steps
Load two bytes in data registers REG0 and REG1 Add the bytes Save the sum in data register REG2
330_04
Example 4.1
330_04
330_04
Illustrative Program
Addition With Carry Check
Write instructions to load two bytes (F2H and 32H) in data registers REG0 and REG1 and add the bytes. If the sum generates a carry, clear the data register REG2; otherwise, save the sum in REG2.
330_04
Illustrative Program
330_04
Assembly Language
Label Opcode Operand Comments
START:
MOVLW
MOVWF MOVLW MOVWF ADDWF BNC MOVLW
0xF2
REG0 0x32 REG1 REG0,W SAVE 0
SAVE:
MOVWF
SLEEP
REG2
330_04
Code Look-up?
Address Hex Label Opcode Operand
000020
000022 000024 000026 000028 00002A 00002C
0EF2
6E00 0E32 6E01 2400 E301 0E00
START:
MOVLW
MOVWF MOVLW MOVWF ADDWF BNC MOVLW
0xF2
REG0 0x32 REG1 REG0,W SAVE 0
00002E
000030
6E02
0003
SAVE:
MOVWF
SLEEP
REG2
330_04
10
MPLAB IDE PICDEM 2 Plus Demo Board Microchip PIC18F4520 MPU MPLAB ICD2
PIC18 Simulator IDE Microchip PIC18F452 MPU
Simulation
330_04
11
330_04
12
Using an Assembler
Assembly Language Programs
Opcode
MOVLW
Operand
0xF2
Comment
;Load F2H in W Semicolon
Tab
Tab
Tab
330_04
14
Assembler Directives
#INCLUDE ORG EQU DB END Include resources from library Origin Equate Data byte End of assembly
330_04
15
Radix Formats
Type Hexadecimal Format 0x4F H4F 4F 4FH D100 B10011000 Susan ASusan
330_04
16
Assembler
Breakpoint Manager Watch Variables Run and Step LED Board 7-Segment Display Keypad Matrix
330_04 17
Debugger
Simulator
I/O Modules
Assembler (Editor)
330_04
18
Line numbers Memory addresses where binary code is stored Hex code Contents of source file
330_04
19
Assembler Listing
330_04
20
Executing a Program
330_04
21
Debugging a Program
Single-step technique
Execute one instruction at a time Observe registers for expected results Execute a group of instructions Observe registers for expected results
Breakpoint technique
330_04
22
Breakpoint Manager
Simulation automatically switches to step-by-step mode when reaching a breakpoint
330_04
23
Special Breakpoints
Switch to step-bystep when the value of a register has changed or equals a predefined value
330_04
24