6502 Assembly Language Programming by Unknown

6502 Assembly Language Programming by Unknown

Author:Unknown
Language: eng
Format: epub


no

ADD ONE

FIGURE 13. Sample Routine

The overall function of the routine is to read characters from the terminal until a non-blank character is obtained. We add one to that character, and what happens after that is not shown.

146 6502 ASSEMBLY LANGUAGE PROGRAMMING

(a) Is JMP a conditional or unconditional instruction?

(b) Is BEQ a conditional or unconditional instruction?

(c) In the routine diagrammed in Figure 13, what happens if the user types a space?

(d) What happens if the user types a B? .

(e) Is the MIXER loop closed or open?

(a) unconditional; (b) conditional; (c) control returns to the beginning of the loop (branch to MIXER); (d) control falls through (one is added to the character); (e) open

8. These are the conditional jump instructions:

BEQ — Branch if EQusl: jump if the zero flag is on BNE — Branch if Not JEqual: jump if the zero flag is off BCS — Branch if Carry Set: jump if the carry flag is on BCC — Branch if Carry Clear: jump if the carry flag is off BMI — Branch if AfJnus: jump if the sign flag is on BPL — Branch if PLus: jump if the sign flag is off BVS — Branch if overflow Set: jump if the overflow flag is on BVC — Branch if overflow Clear: jump if the overflow flag is off

Write the appropriate jump instructions for the following situations:

(a) Jump to ENDER if the decrement below results in a zero.

DEX

(b) Jump to LOOP if the subtraction below results in a nonzero value.

SBC #10

(c) Jump to NEGVAL if the input value is negative,

JSR INPUT

■V

CONDITIONAL INSTRUCTIONS 147

(d) Jump to OK if the subtraction below results in a positive value.

SBC HIND

(e) Jump to TOOBIG if the addition below results in a carry.

ADC $10

(ft Jump to CYCLE if the addition below does not overflow.

ADC HALF

(a) BEQ ENDER; (b) BNE LOOP; (c) BMI NEGVAL; (d) BPL OK; (e) BCS TOOBIG; (f) BVC CYCLE

9. Suppose we want to branch to NOT50 if the value in the accumulator is under $50. We start with a subtraction:

SEC

SBC #$50

Now which flag do we test—carry or sign?

Let's examine the effect on the flags if A is greater than $50. The subtraction results in no borrow, so the carry flag will be set. We don't know the effect on the sign flag because we don't know the original value in A. If it's greater than $D0, the MSB will be on and the sign flag will be set. Otherwise, it will be cleared.

If A equals $50, there will be no borrow, and the carry flag will be set. The sign flag will be cleared. (The zero flag will also be set.)

If A is less than $50, there will be a borrow, so the carry flag will be cleared. The sign flag will be set because the high order bit of the remainder will always be a one.

(a) What branch instructions should be used? , —

(b) Code a routine to branch to ERROR if the value in the accumulator is less than $10.

148 6502



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.