Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 ECE 372 – Microcontroller Design Basic Assembly Programming for(j=0; j<10; j++) { PORTT = j; } For Loop Example: Assembly Code: ldaa #0 ; Initialize.

Similar presentations


Presentation on theme: "1 ECE 372 – Microcontroller Design Basic Assembly Programming for(j=0; j<10; j++) { PORTT = j; } For Loop Example: Assembly Code: ldaa #0 ; Initialize."— Presentation transcript:

1 1 ECE 372 – Microcontroller Design Basic Assembly Programming for(j=0; j<10; j++) { PORTT = j; } For Loop Example: Assembly Code: ldaa #0 ; Initialize j Loop: cmpa #10 ; Compare j to 10 bge EndLoop ; Else !(j<10) staa PTT ; Write J to PORT T adda #1 ; Increment j bra Loop ; Repeat Loop EndLoop: ; do something else

2 2 ECE 372 – Microcontroller Design Basic Assembly Programming $4000$86LDAA immediate addressing $4001$00Value to be stored in A $4002$81CMPA immediate addressing $4003$0ACompare Value 10 $4004$2CBGE (Branch if greater then or equal to zero) $4005$04PC=PC+2+Rel $4006$8BADDA immediate addressing $4007$01Value to add to A $4008$20Branch Always $4009$F8PC=PC+2+Rel … Assembly Code: ldaa #0 ; Initialize j Loop: cmpa #10 ; Compare j to 10 bge EndLoop ; Else !(j<10) staa PTT ; Write J to PORT T adda #1 ; Increment j bra Loop ; Repeat Loop EndLoop: ; do something else Insert staa instruction

3 3 ECE 372 – Microcontroller Design Basic Assembly Programming $4000$86LDAA immediate addressing $4001$00Value to be stored in A $4002$81CMPA immediate addressing $4003$0ACompare Value 10 $4004$2CBGE (Branch if greater then or equal to zero) $4005$04PC=PC+2+Rel $4006$7ASTAA extended addressing $4007$Memory Location $4008$ $4009$8BADDA immediate addressing $400A$01Value to add to A $400B$20Branch Always $400C$F8PC=PC+2+Rel … Assembly Code: ldaa #0 ; Initialize j Loop: cmpa #10 ; Compare j to 10 bge EndLoop ; Else !(j<10) staa PTT ; Write J to PORT T adda #1 ; Increment j bra Loop ; Repeat Loop EndLoop: ; do something else How do we determine this value?

4 4 ECE 372 – Microcontroller Design Basic Assembly Programming $4000$86LDAA immediate addressing $4001$00Value to be stored in A $4002$81CMPA immediate addressing $4003$0ACompare Value 10 $4004$2CBGE (Branch if greater then or equal to zero) $4005$04PC=PC+2+Rel $4006$7ASTAA extended addressing $4007$02Memory Location or PORTT ($240) $4008$40 $4009$8BADDA immediate addressing $400A$01Value to add to A $400B$20Branch Always $400C$F8PC=PC+2+Rel … Assembly Code: ldaa #0 ; Initialize j Loop: cmpa #10 ; Compare j to 10 bge EndLoop ; Else !(j<10) staa PTT ; Write J to PORT T adda #1 ; Increment j bra Loop ; Repeat Loop EndLoop: ; do something else Do the relative addresses for the BGE and BRA instructions change? Why or why not?

5 5 ECE 372 – Microcontroller Design Basic Assembly Programming $4000$86LDAA immediate addressing $4001$00Value to be stored in A $4002$81CMPA immediate addressing $4003$0ACompare Value 10 $4004$2CBGE (Branch if greater then or equal to zero) $4005$07PC=PC+2+Rel $4006$7ASTAA extended addressing $4007$02Memory Location or PORTT ($240) $4008$40 $4009$8BADDA immediate addressing $400A$01Value to add to A $400B$20Branch Always $400C$F5PC=PC+2+Rel (-11) … Assembly Code: ldaa #0 ; Initialize j Loop: cmpa #10 ; Compare j to 10 bge EndLoop ; Else !(j<10) staa PTT ; Write J to PORT T adda #1 ; Increment j bra Loop ; Repeat Loop EndLoop: ; do something else

6 6 ECE 372 – Microcontroller Design STAA Instruction Execution Timing ECLK ADDR 15:0 R/W DATA 15:0 $4000 $8600 $4002 $810A $4000$86LDAA immediate addressing $4001$00Value to be stored in A $4002$81CMPA immediate addressing $4003$0ACompare Value 10 $4004$2CBGE (Branch if greater then or equal to zero) $4005$07PC=PC+2+Rel $4006$7ASTAA extended addressing $4007$02Memory Location or PORTT ($240) $4008$40 $4009$8BADDA immediate addressing $400A$01Value to add to A $400B$20Branch Always $400C$F5PC=PC+2+Rel (-11) $2C06 $4004$4006 $7A02 $0240 $0000 $4009 $8B01 A = 0A = 1 Store A to PORT T Requires 1 Write Cycle $4007 $0242

7 7 ECE 372 – Microcontroller Design Basic Assembly Programming – Accumulator D for(j=0; j<1000; j++) { PORTT = j%256; } For Loop Example: Assembly Code: ldd #0 ; Initialize j Loop: cpd #1000 ; Compare j to 1000 bge EndLoop ; Else !(j<1000) stab PTT ; Write J%256 to PORT T addd #1 ; Increment j bra Loop ; Repeat Loop EndLoop: ; do something else Do we need to use division here?

8 8 ECE 372 – Microcontroller Design Basic Assembly Programming – Accumulator D $4000$CCLDD immediate addressing $4001$00MSB of value to be stored in D $4002$00LSB of value to be stored in D $4003$8CCPD immediate addressing $4004$03Compare to Value 1000 $4005$E8 … Assembly Code: ldd #0 ; Initialize j Loop: cpd #1000 ; Compare j to 1000 bge EndLoop ; Else !(j<1000) stab PTT ; Write J to PORT T addd #1 ; Increment j bra Loop ; Repeat Loop EndLoop: ; do something else

9 9 ECE 372 – Microcontroller Design Instruction Execution Timing – Accumulator D ECLK ADDR 15:0 R/W DATA 15:0 $4000 $CC00 $4001 $0000 $4000$CCLDD immediate addressing $4001$00MSB of value to be stored in D $4002$00LSB of value to be stored in D $4003$8CCPD immediate addressing $4004$03Compare to Value 1000 $4005$E8 $8C03 $4003$4004 $03E8 $4006 D = 0 Detect LDD instruction Read immediate value Detect CPD instruction Read immediate value

10 10 ECE 372 – Microcontroller Design Time for Fun (or maybe not?) 10 Gallon7 Gallon3 Gallon

11 11 ECE 372 – Microcontroller Design STAA Instruction Execution Timing ECLK ADDR 15:0 R/W DATA 15:0 $4000 $CC00 $4001 $0000 $4000$CCLDD immediate addressing $4001$00MSB of value to be stored in D $4002$00LSB of value to be stored in D $4003$8CCPD immediate addressing $4004$03Compare to Value 1000 $4005$E8 How does the CPU execute this internally?

12 12 ALU A B D MAR MDR PC IR 16 ADDR 15:0 DATA 15:0 T ECE 372 – Microcontroller Design CPU Internals Program Counter Instruction Register Memory Data Register Memory Address Register Arithmetic Logic Unit Temporary Register

13 13 ECE 372 – Microcontroller Design CPU Internal Execution Timing $4000$86LDAA immediate addressing $4001$00Value to be stored in A $4002$81CMPA immediate addressing $4003$0ACompare Value 10 $4004$2CBGE (Branch if greater then or equal to zero) $4005$04PC=PC+2+Rel $4006$8BADDA immediate addressing $4007$01Value to add to A $4008$20Branch Always $4009$F8PC=PC+2+Rel ldaa #0 ; Initialize j Loop: cmpa #10 ; Compare j to 10 bge EndLoop ; Else !(j<10) ; do something adda #1 ; Increment j bra Loop ; Repeat Loop EndLoop: ; do something else ALU A B D MAR MDR PC IR 16 ADDR 15:0 DATA 15:0 T

14 14 ECE 372 – Microcontroller Design CPU Internal Execution Timing $4000$86LDAA immediate addressing $4001$00Value to be stored in A $4002$81CMPA immediate addressing $4003$0ACompare Value 10 $4004$2CBGE (Branch if greater then or equal to zero) $4005$04PC=PC+2+Rel $4006$8BADDA immediate addressing $4007$01Value to add to A $4008$20Branch Always $4009$F8PC=PC+2+Rel ECLK ADDR 15:0 R/W DATA 15:0 $FFFE $4000 $8600$810A $4002 ALU A: B: D MAR: MDR: PC: IR: 16 ADDR 15:0 DATA 15:0 T: $FFFE $4000

15 15 ECE 372 – Microcontroller Design CPU Internal Execution Timing $4000$86LDAA immediate addressing $4001$00Value to be stored in A $4002$81CMPA immediate addressing $4003$0ACompare Value 10 $4004$2CBGE (Branch if greater then or equal to zero) $4005$04PC=PC+2+Rel $4006$8BADDA immediate addressing $4007$01Value to add to A $4008$20Branch Always $4009$F8PC=PC+2+Rel ECLK ADDR 15:0 R/W DATA 15:0 $FFFE $4000 $8600$810A $4002 ALU A: B: D MAR: MDR: PC: IR: 16 ADDR 15:0 DATA 15:0 T: $FFFE $4000 $8600 $86 $00 $4002

16 16 ECE 372 – Microcontroller Design CPU Internal Execution Timing $4000$86LDAA immediate addressing $4001$00Value to be stored in A $4002$81CMPA immediate addressing $4003$0ACompare Value 10 $4004$2CBGE (Branch if greater then or equal to zero) $4005$04PC=PC+2+Rel $4006$8BADDA immediate addressing $4007$01Value to add to A $4008$20Branch Always $4009$F8PC=PC+2+Rel ECLK ADDR 15:0 R/W DATA 15:0 $FFFE $4000 $8600$810A $4002 ALU A: B: D MAR: MDR: PC: IR: 16 ADDR 15:0 DATA 15:0 T: $4000 $8600 $4002 $86 $00 $4002 $810A $81 $0A Update CCR $4004

17 17 ECE 372 – Microcontroller Design CPU Internal Execution Timing $4000$86LDAA immediate addressing $4001$00Value to be stored in A $4002$81CMPA immediate addressing $4003$0ACompare Value 10 $4004$2CBGE (Branch if greater then or equal to zero) $4005$04PC=PC+2+Rel $4006$8BADDA immediate addressing $4007$01Value to add to A $4008$20Branch Always $4009$F8PC=PC+2+Rel ALU A: B: D MAR: MDR: PC: IR: 16 ADDR 15:0 DATA 15:0 T: $4002 $810A $86 $00 $4004 ECLK ADDR 15:0 R/W DATA 15:0 $FFFE $4000 $8600$810A $4002$4004 $2C04 $4006 $8B01 $4004 $2C04 $2C $04 $4006 BGE Not Taken

18 18 ECE 372 – Microcontroller Design CPU Internal Execution Timing $4000$86LDAA immediate addressing $4001$00Value to be stored in A $4002$81CMPA immediate addressing $4003$0ACompare Value 10 $4004$2CBGE (Branch if greater then or equal to zero) $4005$04PC=PC+2+Rel $4006$8BADDA immediate addressing $4007$01Value to add to A $4008$20Branch Always $4009$F8PC=PC+2+Rel ALU A: B: D MAR: MDR: PC: IR: 16 ADDR 15:0 DATA 15:0 T: $4002 $810A $86 $00 $4004 ECLK ADDR 15:0 R/W DATA 15:0 $FFFE $4000 $8600$810A $4002$4004 $2C04 $4006 $8B01 $4006 $2C04 $2C $04 $4006 $8B01 $8B $01

19 19 ECE 372 – Microcontroller Design CPU Internal Execution Timing $4000$86LDAA immediate addressing $4001$00Value to be stored in A $4002$81CMPA immediate addressing $4003$0ACompare Value 10 $4004$2CBGE (Branch if greater then or equal to zero) $4005$04PC=PC+2+Rel $4006$8BADDA immediate addressing $4007$01Value to add to A $4008$20Branch Always $4009$F8PC=PC+2+Rel ALU A: B: D MAR: MDR: PC: IR: 16 ADDR 15:0 DATA 15:0 T: $4006 $810A $86 $00 $0A $4008 $8B01 $8B $01 ECLK ADDR 15:0 R/W DATA 15:0 $4006$4008 $8B01$20F8 $4002 $810A $4004 $2C04 $4008 $20F8 $20 $F8 $400A $4002

20 20 ECE 372 – Microcontroller Design CPU Internal Execution Timing $4000$86LDAA immediate addressing $4001$00Value to be stored in A $4002$81CMPA immediate addressing $4003$0ACompare Value 10 $4004$2CBGE (Branch if greater then or equal to zero) $4005$04PC=PC+2+Rel $4006$8BADDA immediate addressing $4007$01Value to add to A $4008$20Branch Always $4009$F8PC=PC+2+Rel ALU A: B: D MAR: MDR: PC: IR: 16 ADDR 15:0 DATA 15:0 T: $4006 $810A $86 $00 $0A $4002 $20F8 $20 $F8 ECLK ADDR 15:0 R/W DATA 15:0 $4006$4008 $8B01$20F8 $4002 $810A $4004 $2C04 $4002

21 21 ECE 372 – Microcontroller Design Assembly Programming – Arrays unsigned short a[10]; for(j=0; j<10; j++) { if(a[j]==1) PORTT=0x04; else PORTT=0x00; } Array For Loop Example: 1.Initialize J 2.Compare J to 10 3.If Not Less than 10, 1.End Loop 4.Else 1.Load a[j] 2.If a[j] == 1 1.PORT T = 4 3.Else 1.PORT T = 0 4.Increment J 5.Repeat Loop (Step 2) Programming Steps:


Download ppt "1 ECE 372 – Microcontroller Design Basic Assembly Programming for(j=0; j<10; j++) { PORTT = j; } For Loop Example: Assembly Code: ldaa #0 ; Initialize."

Similar presentations


Ads by Google