1 / 18

Physics 413 Chapter 4 : Advanced Assembly Programming

Physics 413 Chapter 4 : Advanced Assembly Programming. 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. Assembler Directives and more …. org end equ

trella
Download Presentation

Physics 413 Chapter 4 : Advanced Assembly Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Physics 413Chapter 4: Advanced Assembly Programming

  2. 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

  3. 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

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

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

  6. 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

  7. Push and Pull PSHA A MSP SP - 1 SP PULA SP + 1 SP MSP A

  8. Predict the Outcome! PSHA PSHB PULA PULB

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

  10. 00D3 00D4 00D5 00D6 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.

  11. Research Project Ideas Follow . . .

  12. D-Bug12 Built-in Subroutines Table 4.2 (Huang)

  13. I/O Ports Table 4.5 (Huang)

  14. LED Circuit in the Dragon12-Plus Board (Huang)

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

More Related