0% found this document useful (0 votes)
78 views

Programming and Problem Solving: ELEC 330 Digital Systems Engineering Dr. Ron Hayne

The document discusses programming and problem solving using assembly language. It covers dividing problems into modular tasks, using flowcharts to represent processes and sequence, and examples of writing assembly language instructions to load and add bytes. The key steps of programming in assembly language are analyzed - drawing a flowchart, converting it to mnemonics, looking up hex codes, entering the code into memory, executing the program, and debugging. The document also discusses using an assembler, assembler directives, and debugging techniques like breakpoints.

Uploaded by

Radot Chandra
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Programming and Problem Solving: ELEC 330 Digital Systems Engineering Dr. Ron Hayne

The document discusses programming and problem solving using assembly language. It covers dividing problems into modular tasks, using flowcharts to represent processes and sequence, and examples of writing assembly language instructions to load and add bytes. The key steps of programming in assembly language are analyzed - drawing a flowchart, converting it to mnemonics, looking up hex codes, entering the code into memory, executing the program, and debugging. The document also discusses using an assembler, assembler directives, and debugging techniques like breakpoints.

Uploaded by

Radot Chandra
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 24

Programming and Problem Solving

ELEC 330 Digital Systems Engineering Dr. Ron Hayne


Images Courtesy of Ramesh Gaonkar and Delmar Learning

Problem Solving
Modular Design

Divide problem into various tasks


Independent units that can be combined Graphical representation of processes (tasks) Sequence to be followed

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

Assembly Language Programming


Analyze the problem Draw a flowchart Convert the flowchart into mnemonics Look up Hex code and assign memory addresses Enter the Hex code into memory Execute the program Debug the program if necessary

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

;Load first byte in W


;Save first byte in REG0 ;Load second byte in W ;Save second byte in REG1 ;Add bytes and save sum in W ;Branch if no carry ;Clear W

SAVE:

MOVWF
SLEEP

REG2

;Save sum in REG2


;Power Down

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

Execute the Program


Hardware

MPLAB IDE PICDEM 2 Plus Demo Board Microchip PIC18F4520 MPU MPLAB ICD2
PIC18 Simulator IDE Microchip PIC18F452 MPU

Simulation

330_04

11

PIC18 Simulator IDE


Integrated Development Environment

Editing Assembling Linking Downloading Executing Simulation Debugging

330_04

12

Using an Assembler
Assembly Language Programs

Program in Mnemonics Assembler Directives Comments


Label Opcode Operand (data, register, or memory address) Comment
330_04 13

Assembly Language Statements (4 fields)


Assembly Language Format


Label
START:

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

Decimal Binary ASCII

330_04

16

PIC18 Simulator IDE


Editor

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

Understanding the List File


List file generated primarily for documentation Includes seven columns

Line numbers Memory addresses where binary code is stored Hex code Contents of source file

Labels Opcode Operands Comments

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

You might also like