• No results found

3.8 Status Flag Manipulation

Sometimes the state of a status flag needs to be set or cleared prior to some other operation to assure proper operation of another instruction. The HC11 provides four instructions that can directly manipulate status flags in the CCR. These instructions are summarized in Figure 3.33. CLC and SEC clear or set the carry flag (C) in the CCR, respectively. CLV and SEV clear or set the twos complement overflow flag (V) in the CCR, respectively. These four instructions operate in the inherent addressing mode and have no other effect on the CCR.

For example, all of the shift and rotate instructions use the C flag of the CCR. Thus, the C flag needs to be initialized to the desired state (1 or 0) before performing these operations. Many instructions, like the load instructions, do not affect the C flag. If the load instruction is used prior to a rotate and it is desirable to have the C flag cleared, simply execute the CLC instruction.

1. What is the largest number that can be directly multiplied on the HC11? 2. Where is the result of the MUL instruction stored?

3. Which register contains the remainder of a division? 4. What happens if an attempt is made to divide by zero?

5. Which division instruction would be used to find the binary-weighted equivalent fraction of any number less than zero?

Mnemonic Description Function IMM DIR EXT INDX INDY INH REL S X H I N Z V C

CLC Clear carry flag 0 ⇒ C - - - X - - - 0

SEC Clear carry flag 1 ⇒ C - - - X - - - 1

CLV Clear overflow flag 0 ⇒ V - - - X - - - 0 -

SEV Clear overflow flag 1 ⇒ V - - - X - - - 1 -

Figure 3.33 Status Flag Manipulation Instructions 87

Self-Test Questions 3.8

Summary

Instructions tell the processor which functions should be performed. The order in which the instructions are presented to the processor determines the order in which the functions are performed. Some instructions are responsible for the movement of data. The HC11 instruction set allows data to be moved using three different methods: from memory to the processor registers (load instructions), from the processor registers to memory (store instructions) and from one processor register to another processor register (transfer and exchange instructions).

Other instructions are responsible for mathematical calculations. The basic arithmetic operations of addition, subtraction, multiplication and division are supported. In addition, instructions to increment, decrement or change the sign of a value are supported. The logical operations AND, OR, XOR and NOT are also provided. The operation of single instructions and the combination of a few instructions in short program segments are the focus of this chapter. The application and examples are limited to the inherent, immediate, direct and extended addressing modes to reinforce their use.

Chapter Questions

Section 3.1

1. What is the H flag used for? 2. What is the N flag used for?

Section 3.2

3. List the three ways that the movement of data can be accomplished.

4. What type of instructions are used to accomplish the data movement methods listed for question #3?

5. What is the address of the data that gets loaded by the following instruction: LDAA $4B?

6. How many bytes of data are loaded by the following instruction: LDX $00? 7. What is the mnemonic used for the instruction that stores the contents of AccA? 8. What is the source of the data that gets stored by the following instruction:

STAB $019F?

9. Why is the CLRA instruction similar to the LDAA instruction? 10. What happens to AccA when a TAB instruction is executed?

11. How many instructions would be necessary to duplicate the function of a single exchange instruction?

1. Can status flags in the CCR be directly modified by instructions? How? 2. What instruction is used to set the V flag?

88

Section 3.3

12. What condition causes the C flag to be set during an add instruction? 13. What condition causes the H flag to be set during an add instruction?

14. What actually takes place when the following instruction is executed: ADDA $0100?

15. Can the DAA instruction perform a decimal adjust after a subtract instruction? 16. How can the function of the INCA instruction be duplicated using an ADDA

instruction?

Section 3.4

17. What condition causes the C flag to be set during a subtract instruction? 18. What condition causes the H flag to be set during a subtract instruction? 19. What addressing modes support the negate instructions?

20. What is the advantage of a decrement instruction over the equivalent subtract instruction?

Section 3.5

21. What four logical operations are supported by the HC11?

22. What series of instructions could be used to create a logical NAND function?

Section 3.6

23. What is the significant difference between a logical and an arithmetic shift right?

24. Which bit in the CCR is used by all of the shift and rotate instructions? 25. How many times would the LSRA instruction have to be executed to shift the

upper nibble to the lower nibble position?

26. Why are there different mnemonic forms for logical and arithmetic shift left if they share the same opcodes?

27. Which flags in the CCR are affected by the ROLA instruction?

Section 3.7

28. Where are the results of a multiply instruction located at the end of the instruction?

29. Where is the result of an integer divide instruction located at the end of the instruction?

30. What happens if the X register contains zero and the IDIV instruction is executed?

31. If the numerator is less than the denominator, which divide instruction should be used?

Section 3.8

32. What addressing mode is used by the CLC instruction?

Chapter Problems

1. Using the diagram in Figure 3.3, derive a logic function for the Z flag. Validate the function with the data from Figure 3.34.

2. Using the data in Figure 3.34, express the results of the following instructions. 89

Which addressing mode is used for each instruction? NOTE: Each instruction is independent of the others. The results are not cumulative.

a. LDAA #$F9 b. STX $0108 c. TBA d. CLRB e. XGDX f. LDD $F9 g. TSX h. STS $0193 i. CLR $0029 j. TAP k. LDAB $FB

3. Using the data in Figure 3.35 draw a flowchart and write a program that will transfer the contents of AccA to AccB and then exchange the contents of the X and D registers.

4. Using the data from Figure 3.35, express the results of the following instructions. Which addressing mode is used for each instruction? NOTE: Each instruction is independent of the others. The results are not cumulative.

a. ADDA #$49 b. ABX c. INCB d. DEC $0100 e. ADDD #$0100 f. SUBB $13 g. DES h. ADDB $010B i. SBA C = $C4 00F8 00 11 22 33 44 55 66 77 D = $B600 0100 F3 56 E3 DB A1 A0 09 00 X = $00A0 0108 22 44 52 88 63 77 74 33 Y = $0110 0110 FF 00 FF 11 FF 22 FF 83 S = $0107 0118 F1 3B BB B6 D4 AD CE 00 Registers Memory 90

Figure 3.34 Default Data Set #1

Figure 3.35 Default Data Set #2

C = $D5 0000 52 88 63 33 44 55 66 77 D = $0082 0008 F3 56 E3 DB A1 A0 09 00 X = $0100 0010 22 44 52 88 63 77 74 33 Y = $0000 0100 FF 00 88 63 77 74 FF 83 S = $0041 0108 44 52 88 63 52 88 63 00 0110 33 44 55 B6 A1 A0 09 00 Registers Memory

5. Draw a flowchart and write a program that will add $3C and $42 and store the sum at location $0020.

6. Draw a flowchart and write a program that will add the BCD values $26 and $39, perform the proper decimal adjust as needed and store the sum at location $0180. 7. Draw a flowchart and write a program that will subtract the contents of memory

locations $0000 and $0001 and store the result in location $0002.

8. Using the data from Figure 3.35, express the results of the following instructions. Which addressing mode is used for each instruction? NOTE: Each instruction is independent of the others. The results are not cumulative.

a. EORB $0E

b. COMA

c. COM $0103

d. ORAB $0012

e. ANDB $06

9. Draw a flowchart of a program that multiplies the two numbers located in memory locations $0134 and $0135 and then divides the result by $000A.

10. Write a program that will divide $04A3 by $001B. Show the result and remainder and where they are stored.

11. Write instructions that will do the following: a. Set the C flag in the CCR.

b. Clear the V flag in the CCR c. Set the Z flag in the CCR.

12. Using the data from Figure 3.35, comment each line of code using transfer notation and express the results of the programs. NOTE: The results of each instruction within each program are cumulative; however, each program is independent of the others.

a. LDAA $03 LDAB #$59 ABA DAA b. ADDA $0100 SUBA $0A,Y STAA $0102 c. DECB COMA MUL