ECE 265 – Lecture 9

26
ECE 265 – LECTURE 9 PROGRAM DESIGN 06/23/22 1 ECE265

description

ECE 265 – Lecture 9. PROGRAM DESIGN. Lecture Overview. Program Design General Overview Program Design Methodology Assembler Language Assembler Directives REF: Chapter 4. Program Design. General Overview - PowerPoint PPT Presentation

Transcript of ECE 265 – Lecture 9

Page 1: ECE 265 – Lecture 9

ECE 265 – LECTURE 9

PROGRAM DESIGN

04/20/23

1ECE265

Page 2: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

Lecture Overview

Program Design General Overview Program Design Methodology Assembler Language Assembler Directives

REF: Chapter 4

04/20/23

2

ECE265

Page 3: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

Program Design

General Overview From the text page 89: “The design of an embedded

microcontroller system requires an integrated use of hardware and software.”

Hardware and software provide a natural division of the view of the system. Embedded systems require well designed interaction between these two divisions.

The software design needs to follow established methodologies.

04/20/23ECE265

3

Page 4: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

Software Design Methodology

The software of the system is typically called a Software Program.

A software program is software compiled and assembled into executable code for the target machine.

Window7 is a program designed as the operating system for general purpose PCs and will run on hardware structured to support that OS.

04/20/23ECE265

4

Page 5: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

Top-down design methodology

A popular design methodology for software is Top-Down design and Bottom-up coding.

It starts with a specification of the system at the top level.

This top-level is then broken down into major tasks and subtasks.

Each major task (and subtask) is broken down into smaller subtasks as appropriate.

04/20/23ECE265

5

Page 6: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

Top-Down Design

Graphical illustration of the Top-down design methodology.

The number of levels continues until the subtask is one that can be directly coded.

04/20/23ECE265

6

Page 7: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

Benefits of the top-down method

Each subtask is independent of other subtasks, allowing the programmer to design, write and test each module independently.

Errors can be detected and corrected in a logical manner. Mentally, the programmer only has to grasp one subtask at a

time. A team of programmer can be used to accomplish the

project faster. Program modules can be used in future applications. For

example, your program needs to use a linked list data structure. Most likely the routines to manage and manipulate a linked list are available.

04/20/23ECE265

7

Page 8: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

Statement of the problem

Where it all starts. The highest level of abstraction

The statement of the problem to be solved

Requires full analysis of the problem to be addressed and the system being designed to address it.

04/20/23ECE265

8

Page 9: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

An example of the methodology

Example 4.2 from the Text.

04/20/23ECE265

9

Page 10: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

Assembler language programming

A good practice is never to program in assembler language directly.

Start with the specification of the module to be coded.

Code it in a Pseudo Design Language or PDL PDL is much like any high level programming

language.

04/20/23ECE265

10

Page 11: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

Assembler Language

Assembler Language is specific to the machine (processor architecture).

Each processor version may have instructions that other versions do not have.

Assembler language has a 1-to-1 relationship with the machine language, i.e., executable code of the processor. One assembler language statement = one executable instruction.

04/20/23ECE265

11

Page 12: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

Assembler language

Usually written line by line where each line is 80 character long.

Within the 80 character line there are fields. Field position can be fixed. For example: The first 10 characters are a label The next field is for the operand or assembler directive This is followed by the operand field The last filed is for comments

04/20/23ECE265

12

Page 13: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

The 68HC11 format

Each assembler language statement is on one line Starts in column 1 and has 4 fields

The label field The op code field The operand filed The comment field

THE LABEL FIELD Starts in column 1 Can be blank Label can be up to 15 characters in length Upper case is distinct from lower case and must start with a character

TDREG1 is valid 1TDREG is not valid Delimited (ended) by a ‘:’ or a ‘ ’

04/20/23ECE265

13

Page 14: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

The 68HC11 format (cont)

The operation field Must start in column 2 or after Best to start in the same column for the complete program Contains the instruction mnemonic such a LDAA, OR an assembler directive OR a macro call

Operand Field The field contains the instruction operand or argument for assembler directives Numbers in this field are identified by some symbols that can precede the

number None A decimal number $ The number is a hexidecimal number @ The number is an octal number % The number is a binary number

04/20/23ECE265

14

Page 15: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

68HC11 formal continued

The comment field The last field is a comment field and is separated from

the previous filed by at least one space An optional field Can have any printable ASCII character as this field is

used for documentation Can be continued (or you can use any line as a

comment) by starting the line with a *. These lines are considered as comments and anything on the line is considered a comment, i.e., no assembly takes place.

LABEL: OPCODE OPERAND COMMENT

04/20/23ECE265

15

Page 16: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

Assembler directives

These are direction to the assembler to perform a particular task or set up a specific condition.

The assembler directives are

04/20/23ECE265

16

Page 17: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

NAM directive

Give the program a name. Documentation only. There is no impact on the

machine code generated.

NAM Pressure Monitoring

04/20/23ECE265

17

Page 18: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

ORG directive

Used extensively and common to all assemblers. Sets the location (physical location) counter to a set value. Example

ORG $C000 CNTMAX RMB 2

This would place the 16-bits for CNTMAX at address $C000 and 2 bytes of memory are set aside.

ORG $D000 START LDAA #$46 x x

Here the ORG place the executable code to start at address $D000 and the label START would have a value of $D000

Memory address $D000 contains $86, the op code for LDAA immediate mode

04/20/23ECE265

18

Page 19: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

END directive / EQU directive

END simply indicates that this is the last source code line.

EQU allows a value to be given to label for more readable and understandable code. <label> EQU <expression> [<comment>] EX ADCTL EQU $1030 Location of the A/D control register.

04/20/23ECE265

19

Page 20: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

FCB directive

Form Constant Byte This directive can have more than one value in the

operand field. EX

DIGITS FCB 0, 1, 2, 3 Fills a 4-byte memory buffer labeled with DIGITS with values 0,1,2, and 3 MYHEX FCB $32 Fills the location MYHEX with a value of $32.

04/20/23ECE265

20

Page 21: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

FCC directive

FCC is much like FCB except that now the memory locations are filled with the ASCII code for the characters in the string. [<label>] FCC ‘<ASCII string>’

Note the use of single ’s Example

MYLAB FCC ‘my ASCII string’

04/20/23ECE265

21

Page 22: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

RMB

RMB with reserve space in memory and attach a label to that location that can be used in the assembler code to refer to the location. Does not affect the value in the location.

EX MRCNT RMB 1 Reserve 1 byte TREG1 RMB 2 Reserve 2 bytes TEBUFF RMB 12 Reserve 12 bytes

04/20/23ECE265

22

Page 23: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

SET directive

The SET directive established the value for a label being used in the assembler code. <label> SET <expression>

EX COUNT SET #40 sets the value for the label COUNT to 40. Any time COUNT is used it is the same as using 40 If you later reassign a value to the label, that value will

be the new value for the label.

04/20/23ECE265

23

Page 24: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

BTEXT and ETEXT Directives

These directives allows the programmer to insert blocks of text easier than with the other directives.

No need for starting and ending quotes on each line EXAMPLE

BTEXT These lines will be ignored by the assembler but will appear in the LST file. ETEXT

A BTEXT must be ended by a ETEXT

04/20/23ECE265

24

Page 25: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

Lecture summary

04/20/23ECE265

25

Program Design General Overview of software Program Design Methodology Assembler Language in general Assembler Directives for the 68HC11

Page 26: ECE 265 – Lecture 9

Joanne E. DeGroat, OSU

Assignment

04/20/23ECE265

26

Problems : Chapter 4 page 127 – Prob 7