Chapter 3 - v3.1 - Chapter 3 Programming Examples Example...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
22 Chapter 3 Programming Examples Example 1: (simple addition) Write a program which adds the contents of memory locations $0040 and $0041 and stores the sum to memory location $0042. Start the program from location $0020. machine location code ($) mnemonic comments 0020 96 LDAA $40 Get operand 1 0021 40 0022 9B ADDA $41 Add operand 2 0023 41 0024 97 STAA $42 Store result 0025 42 0026 7E JMP $0026 Loop forever 0027 00 0028 26 Example 2: (nibble seperation) Write a program which takes the contents of location $40 and stores the four least significant bits (LSBs) in location $41, i.e., separate the low order nibble. Start the program from location $0010. machine location code ($) mnemonic comment $0010 96 LDAA $40 get the operand $0011 40 $0012 84 ANDA #$0F mask off the most significant nibble $0013 0F $0014 97 STAA $41 store the result $0015 41 $0016 7E JMP $0016 loop forever $0017 00 $0018 16 Accumulator B can also be used alternatively. machine location code ($) mnemonic $0010 D6 40 LDAB $40 $0012 C4 0F ANDB #%00001111 $0014 D7 41 STAB $41 $0016 7E 00 16 JMP $0016 Example 3: (disassembly of a word) Write a program which places the four LSBs of location $0040 in location $0041 and four MSBs of location $0040 in location $0042 as the four LSBs of the corresponding destination locations. Start the program from $0060. machine location m. code ($) mnemonic comment cycle 0060 96 LDAA $40 Get data 3 0061 40 0062 84 ANDA #$0F Mask off 4 MSBs 2 0063 0F # : immediate addressing $ : hexadecimal %: binary
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
0064 97 STAA $41 Store LSBs 3 0065 41 0066 96 LDAA $40 Get data 3 0067 40 0068 44 LSRA Convert MSBs 2 0069 44 LSRA to LSBs 2 006A 44 LSRA 2 006B 44 LSRA 2 006C 97 STAA $42 Store MSBs 3 006D 42 006E 7E JMP $006E Loop forever 006F 00 0070 6E Total number of cycles: 22. With 2 MHz clock the execution time of the program: 11 μ sec. Example 4: (addition of an array of n numbers) Memory location $41 contains the length ( 0) of a set of numbers. The set starts at memory location $42. Write a program that stores the sum (less than 256) of numbers in $40. Start the program at $0060. location label mnemonic comment $0060 CLRA SUM=0 $0061 LDAB $41 COUNT=Length of array acc. B will be used as counter $0063 LDX #$0042 IX will be used as pointer $0066 SUMD ADDA $00,X SUM=SUM+element from the array $0068 INX update the pointer $0069 DECB update the counter COUNT=($41) SUM=0 POINTER=$42 SUM=SUM+(POINTER) POINTER=POINTER+1 COUNT=COUNT-1 IS COUNT 0? ($40)=SUM
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/30/2011 for the course EE 447 taught by Professor Skst during the Fall '10 term at Middle East Technical University.

Page1 / 7

Chapter 3 - v3.1 - Chapter 3 Programming Examples Example...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online