Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced Assembly Language Programming

Similar presentations


Presentation on theme: "Advanced Assembly Language Programming"— Presentation transcript:

1 Advanced Assembly Language Programming
ELEC 330 Digital Systems Engineering Dr. Ron Hayne ELEC 330

2 Outline More Indexing Bit and Byte Manipulation Arithmetic Operations
Shift Operations Logical Operations Arithmetic Operations Multiplication Division BCD Operations The Stack 330_05

3 More Indexing Prebytes
When Y index register is included, the required number of instruction op codes exceeds an 8-bit number Double-byte op code prebyte + op code byte Op Code Maps Pages 515, 516 Prebytes 18, 1A, CD 330_05

4 Additional Instructions
Index Register Exchange Instructions XGDX, XGDY Exchange the D accumulator with the X or Y index register Compare Accumulator D CPD Compare accumulator D to Memory 330_05

5 Shift Operations Rotate Instructions Shift Instructions
ROL, ROLA, ROLB Rotate left memory byte or accumulator ROR, RORA, RORB Rotate right memory byte or accumulator Shift Instructions ASL, ASLA, ASLB, ASLD, LSL, LSLA, LSLB, LSLD Arithmetic or logical shift left memory byte or accumulator LSR, LSRA, LSRB, LSRD Logical shift right memory byte or accumulator ASR, ASRA, ASRB Arithmetic shift right memory byte or accumulator 330_05

6 Logical Operations Bit Picking ANDA, ANDB BITA, BITB
And memory byte to accumulator BITA, BITB And memory byte to accumulator and discard result Contents of memory called a mask Example 330_05

7 Testing Hardware Signals
Memory Register IN1 PB1 (bit 6) PB2 (bit 3) Example program to test push buttons Execute one program if both are pushed Execute another program if both not pushed MASK1 FCB % MASK2 FCB % LDAA IN1 ANDA MASK1 BEQ NOT ANDA MASK2 BOTH  NOT  330_05

8 Logical Operations Bit Packing Bit Reversing ORAA, ORAB
Or memory byte to accumulator Use ORA to pack 1s Use ANDA to pack 0s Bit Reversing EORA, EORB Exclusive or memory byte to accumulator Use EOR with 1 to reverse a bit 330_05

9 Hardware Signals Continued
Memory Register OUT LT1 (bit 2) Program continued Turn on LT1 if both buttons are pushed Turn off LT1 otherwise MASK3 FCB % MASK4 FCB % BOTH LDAA OUT ORAA MASK3 STAA OUT BRA NEXT NOT LDAA OUT ANDA MASK4 NEXT  330_05

10 Logical Operations Bit Set and Clear Bit Testing and Branching BSET
Set all bits in a memory byte that correspond to 1s in the mask BCLR Clear all bits in a memory byte that correspond to the 1s in the mask Assembly Language BSET LIGHTS,$10 Bit Testing and Branching BRSET Branch if all the bits in a memory byte that correspond to 1s in the mask are set BRCLR Branch if all the bits in a memory byte that correspond to 1s in the mask are clear Assembly Language BRCLR 0,X,MASK1,NEXT 330_05

11 Arithmetic Operations
Multiplication MUL (unsigned) Multiply accumulator A by accumulator B and put the product into accumulator D Division IDIV, FDIV Divide two 16-bit numbers giving a 16-bit quotient and a 16-bit remainder BCD Operations DAA Decimal adjust accumulator A Use after ADDA, ADDB, ADCA, ADCB, ABA 330_05

12 The Stack Stack Stack Pointer (SP) Stack Operations Last-in-first-out
Memory address of next available stack location Stack Operations Push Put data on stack Decrement SP (after) Pull Remove data from stack Increment SP (before) 330_05

13 Stack Instructions LDS PSHA, PSHB PULA, PULB PSHX, PSHY PULX, PULY
Load SP Creates a stack PSHA, PSHB Push accumulator on stack Decrement SP (after) PULA, PULB Pull from stack to accumulator Increment SP (before) PSHX, PSHY Push index register on stack (2 bytes) PULX, PULY Pull from stack to index register (2 bytes) TSX, TXS, TSY, TYS Transfer the SP to index register Transfer index register to SP 330_05

14 Stack Example ORG $E100 * INITIALIZE STACK START LDS #$B7FF
* CREATE SAMPLE DATA LDAA #$22 LDAB #$33 * STORE DATA IN STACK PSHA PSHB * GET DATA FROM STACK PULA PULB SWI SP B7FC B7FD A B7FE B7FF B 330_05

15 Stack Example ORG $E100 * INITIALIZE STACK START LDS #$B7FF
* CREATE SAMPLE DATA LDAA #$22 LDAB #$33 * STORE DATA IN STACK PSHA PSHB * GET DATA FROM STACK PULA PULB SWI SP B7FC B7 FF B7FD A B7FE B7FF B 330_05

16 Stack Example ORG $E100 * INITIALIZE STACK START LDS #$B7FF
* CREATE SAMPLE DATA LDAA #$22 LDAB #$33 * STORE DATA IN STACK PSHA PSHB * GET DATA FROM STACK PULA PULB SWI SP B7FC B7 FF B7FD A B7FE 22 B7FF B 33 330_05

17 Stack Example ORG $E100 * INITIALIZE STACK START LDS #$B7FF
* CREATE SAMPLE DATA LDAA #$22 LDAB #$33 * STORE DATA IN STACK PSHA PSHB * GET DATA FROM STACK PULA PULB SWI SP B7FC B7 FE B7FD A B7FE 22 B7FF B 33 330_05

18 Stack Example ORG $E100 * INITIALIZE STACK START LDS #$B7FF
* CREATE SAMPLE DATA LDAA #$22 LDAB #$33 * STORE DATA IN STACK PSHA PSHB * GET DATA FROM STACK PULA PULB SWI SP B7FC B7 FD B7FD A B7FE 33 22 B7FF B 330_05

19 Stack Example ORG $E100 * INITIALIZE STACK START LDS #$B7FF
* CREATE SAMPLE DATA LDAA #$22 LDAB #$33 * STORE DATA IN STACK PSHA PSHB * GET DATA FROM STACK PULA PULB SWI SP B7FC B7 FE B7FD A B7FE 33 B7FF 22 B 330_05

20 Stack Example ORG $E100 * INITIALIZE STACK START LDS #$B7FF
* CREATE SAMPLE DATA LDAA #$22 LDAB #$33 * STORE DATA IN STACK PSHA PSHB * GET DATA FROM STACK PULA PULB SWI SP B7FC B7 FF B7FD A B7FE 33 B7FF 22 B 330_05

21 Proper Rules of Stacking
The stack is a temporary storage place ALWAYS PULL and PUSH the same numbers of bytes Ensure that enough memory was allocated for your stack 330_05

22 Summary More Indexing Bit and Byte Manipulation Arithmetic Operations
Shift Operations Logical Operations Arithmetic Operations Multiplication Division BCD Operations The Stack 330_05

23 Subroutines A program module used multiple times during the execution of a program It can be imbedded repeatedly in the main program listing BUT is more efficiently CALLED by the main program. Subroutines increase our programming productivity 330_05

24 Writing Subroutines You can get to your subroutine two ways, by jumping (JSR) or branching (BSR) Both methods save the PC in the stack This provides a “return address” to the main program upon completion of the subroutine The final command of a subroutine is RTS, which retrieves the return address from the stack HINT: “Calling” subroutines requires a stack 330_05

25 Stack Care and Feeding Subroutines must leave the stack unchanged from its state prior to the subroutine call Otherwise, RTS will not yield a proper return Subroutine use of the stack must observe the PUSH = PULL rule Stacks are used to: Save temporary data Save addresses Know what your use is at all times 330_05

26 Good Subroutines Are independent of the main program
If you move the data, does it break the subroutine? Are correctly structured Single entry point and a single exit points First instruction is always the first instruction executed Ends with RTS Take extra care when using microprocessor resources within the subroutine Very easy for the main program and subroutine to conflict when both use a particular accumulator or register 330_05

27 Passing Data Call by Value Call by Reference
Copies of data are passed to the subroutine Simple method - the main puts the data to be passed to the subroutine in the microprocessor registers. Can only pass 6 bytes and must take care to not to incorrectly overwrite data Subroutine cannot change the main programs data value Call by Reference Memory addresses containing the data are passed to the subroutine 330_05

28 Subroutine Example * Data Section ORG $0010 VALUE FCB $46 Demo Data
* Program Section ORG $E100 * Create a Stack START LDS #$B7FF * Load A With Demo Data LDAA VALUE * Call subroutine JSR SWAP DONE BRA DONE "STOP" 330_05

29 Swap Subroutine * Swap Subroutine ORG $E150 SWAP LSLA ADCA #0 LSLA
RTS Return from Subroutine END 330_05

30 Summary Subroutines Passing Data JSR, BSR RTS Call by Value
Call by Reference 330_05


Download ppt "Advanced Assembly Language Programming"

Similar presentations


Ads by Google