180 likes | 267 Views
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
E N D
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 db fcc Examples alpha equ 1.7 string fcc “hello!” array db $3, $8, $23, $11, $57, $12, $47
Delay Loop DELAY: LDX # $ FFFF AGAIN : DEX BNE AGAIN SWI
Delay Loop Subroutine here:JSRDELAY LDAA # $ E3 CMPA$ 50 BNE here SWI . . . DELAY: LDX # $ FFFF AGAIN : DEX BNE AGAIN RTS
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
Push and Pull PSHA A MSP SP - 1 SP PULA SP + 1 SP MSP A
Predict the Outcome! PSHA PSHB PULA PULB
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.
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.
D-Bug12 Built-in Subroutines Table 4.2 (Huang)
I/O Ports Table 4.5 (Huang)
Look for more research project ideas in the book and on the internet . . .