Presentation is loading. Please wait.

Presentation is loading. Please wait.

Physics 413 Chapter 4: Advanced Assembly Programming.

Similar presentations


Presentation on theme: "Physics 413 Chapter 4: Advanced Assembly Programming."— Presentation transcript:

1

2 Physics 413 Chapter 4: Advanced Assembly Programming

3 My First Assembly Program Program adds two 16-bit numbers stored at $1000 - $1001 and $1002 - $1003 and stores the sum at $1010 - $1011 org $2000 ldd $1000 addd $1002 std $1010 end

4 Assembler Directives and more … org end equ db fcc Examples alpha equ 1.7 string fcc “hello!” array db $3, $8, $23, $11, $57, $12, $47

5 Delay Loop DELAY: LDX # $ FFFF AGAIN : DEX BNE AGAIN SWI

6 Delay Loop Subroutine here:JSR DELAY LDAA # $ E3 CMPA $ 50 BNE here SWI. DELAY: LDX # $ FFFF AGAIN : DEX BNE AGAIN RTS

7 Stack  Stack is the area of RAM pointed to by the 16-bit Stack Pointer (SP)  LDS functions like LDX  LDS #$ 5C42 The number 5C42 is loaded into SP  LDS $ 5C42 Numbers from 5C43 and 5C42 loaded  LDS $ 5C Numbers from 005D and 005C loaded

8 Push and Pull PSHA A M SP SP - 1 SP PULA SP + 1 SPM SP A

9 Predict the Outcome! PSHA PSHB PULA PULB

10 Solution Congratulations, if you said the contents of A and B will be swapped and, perhaps more importantly, the value of the stack pointer will be restored to its original value before this program segment was run. 00D6 00D5 00D4 00D3

11 Detailed Explanation Suppose that SP was pointing at 00D6 (stack). PUSHA stores A into 00D6. Then PUSHB stores B into 00D5. At this point SP = 00D4. Then PULA pulls 00D5 (which contains B) and stores it into A. Finally, PULB pulls 00D6 (which contains A) and stores it into B. We end up swapping A and B. At this point SP = 00D6, its original value. 00D6 00D5 00D4 00D3

12 Research Project Ideas Follow...

13 D-Bug12 Built-in Subroutines Table 4.2 (Huang)

14 I/O Ports Table 4.5 (Huang)

15 LED Circuit in the Dragon12-Plus Board (Huang)

16

17

18

19 Look for more research project ideas in the book and on the internet...


Download ppt "Physics 413 Chapter 4: Advanced Assembly Programming."

Similar presentations


Ads by Google