Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2010 Kettering University, All rights reserved..

Similar presentations


Presentation on theme: "© 2010 Kettering University, All rights reserved.."— Presentation transcript:

1 © 2010 Kettering University, All rights reserved.

2

3 Microcomputers I – CE 320 Electrical and Computer Engineering Kettering University Jaerock Kwon, Ph.D.

4 Announcements Quiz 2 today!  Starts at 10:50AM

5 Lecture 9: Assembly Language Example

6 Today’s Topics Flowcharts Practice assembly programming

7 Flowcharts There are other more sophisticate methods of representing programs. Flowcharts work well for software written in assembly code level. We will see logical building blocks in flowchart formats along with assembly code templates.

8 Flowcharts There are many more symbols other than these. Shapes may be different. In this course, those four symbols are pretty much all we need. Meaning of symbols Decision Start or End Process flow

9 Flowcharts Set CCR bits for decision Bxx Process A Process B code If(PillColor == RED) RealWorld Else Matrix Example: ldaaPillColor cmpa#RED bnelmatrix RealWorld bralskip lmatrix:Matrix lskip:... If-Then-Else Color of Pill is RED? Matrix RealWorld TRUE FALSE

10 Flowcharts Set CCR bits for decision Bxx past BRA Process code Set CCR bits for decision BRA to Bxx Example: ldaaKnowThis lloop:cmpa#YES beqlnext StudyMore ldaaKnowThis bralloop lnext:NextStep While-Do KnowThis? StudyMore TRUE FALSE

11 Flowcharts Process code Set CCR bits Bxx to Process code Example: loop:DoSomething ldaaResult beqldone braloop ldone: Repeat-Until Is the Job done? FALSE TRUE DoSomething

12 Flowcharts Set CCR bits Bxx to Process 1 Set CCR bits Bxx to Process 2 … Set CCR bits Bxx to Process N Default Process code BRA past Process N code Process 1 code BRA past process N code Process 2 code BRA past Process N code … Process N code Example: ldaanTemp cmpa#20 bhsl1 TurnOnHeater bralres l1:cmpa#70 bhil2 FlashIndicator bralres l2: cmpa#100 bhil3 TurnOnCooler bralres l3:Alarm lres: Case nTemp < 20 nTemp < 20 TurnOnHeater FALSE TRUE nTemp < 70 nTemp < 70 FlashIndicator FALSE TRUE nTemp < 100 nTemp < 100 TurnOnCooler FALSE TRUE Alarm

13 Flowchart Guidelines Do not refer to registers in the flowchart Arrows should never cross  They will not need to if the flowchart represents a structured program The purpose is to remove any questions about how to program and understand the algorithm, and this usually determines when the flowchart contains enough detail.

14 Assembly Example Convert an array of 4-byte Big-Endian values to an array of Little-Endian values. Let  $1000 hold the address of the array of Big-Endian values,  $1002 hold the address of the array for the Little-Endian values,  $1004 hold the two-byte length of numbers to convert. Write an assembly program to implement these requirements.

15 4. There are no more elements TRUE FALSE Start End 1: Point to the first BE item 2: Point to the first LE item 3: Make a copy of the length 5: Copy 1st BE byte to 4th LE byte 6: Copy 2 nd BE byte to 3 rd LE byte 7: Copy 3 rd BE byte to 2 nd LE byte 8: Copy 4 th BE byte to 1 st LE byte 9: Point to next elements & dec length

16 org $1000 Bendds.w 1 LEnd ds.w 1 Lengthds.w 1 TmpLends.w1 org $2000 ldx BEnd ldy Lend ldd Length Loopstd TmpLen; 3 beq Done ldaa 0,x; 3 staa 3,y; 2 ldaa 1,x; 3 staa 2,y; 2 ldaa 2,x; 3 staa 1,y; 2 ldaa 3,x; 3 staa 0,y; 2 inx; 1 inx iny; 1 iny ldd TmpLen; 3 subd#$0001 bra Loop Doneswi 4. There are no more elements TRUE FALSE Start End 1: Point to the first BE item 2: Point to the first LE item 3: Make a copy of the length 5: Copy 1st BE byte to 4th LE byte 6: Copy 2 nd BE byte to 3 rd LE byte 7: Copy 3 rd BE byte to 2 nd LE byte 8: Copy 4 th BE byte to 1 st LE byte 9: Point to next elements & dec length

17 org $1000 Bendds.w 1 LEnd ds.w 1 Lengthds.w 1 org $2000 ldx BEnd ldy Lend ldd Length Loopbeq Done movb 0,x,3,y; 5 movb 1,x,2,y movb 2,x,1,y movb 3,x,0,y leax 4,x; 2 leay 4,y subd #1; 2 bra Loop Doneswi 4. There are no more elements TRUE FALSE Start End 1: Point to the first BE item 2: Point to the first LE item 3: Make a copy of the length 5: Copy 1st BE byte to 4th LE byte 6: Copy 2 nd BE byte to 3 rd LE byte 7: Copy 3 rd BE byte to 2 nd LE byte 8: Copy 4 th BE byte to 1 st LE byte 9: Point to next elements & dec length Note: You can save 10 (= 3 + 2x2 + 3) cycles.

18 Questions?

19 Wrap-up Flowcharts  Templates will be greatly helpful. Assembly program example What we’ve learned

20 What to Come Arithmetic instructions Logic instructions


Download ppt "© 2010 Kettering University, All rights reserved.."

Similar presentations


Ads by Google