制作简单的 input/output 作业程序
Making simple input/output program for assignment
Create a program that prints "You entered a one" if the user enters a
1,
"You entered a two" if the user enters a 2,
"You entered a three" if the user enters a 3.
The program should loop until the user enters a 4, then it should exit.
If a number other than 1, 2, 3, or 4 is entered the program should
print "You entered an invalid number".
org 0200h
Main:
ldx #InMess1<
ldy #InMess1>
jsr 0E00Ch
jsr 0E009h
jsr 0E015h
CheckOne:
cmp #1d
bne CheckTwo
ldx #OneMess<
ldy #OneMess>
jsr 0E00Ch
jmp Main
CheckTwo:
cmp #2d
bne CheckThree
ldx #TwoMess<
ldy #TwoMess>
jsr 0E00Ch
jmp Main
CheckThree:
cmp #3d
bne CheckFour
ldx #ThreeMess<
ldy #ThreeMess>
jsr 0E00Ch
jmp Main
CheckFour:
cmp #4d
bne Main
CheckError:
cmp #1d>
cmp #4d<
ldx #ErrorMess<
ldy #ErrorMess>
bne Main
brk
InMess1:
dbt 0ah,0dh
dbt "Enter 1-4: "
dbt 0d
OneMess:
dbt 0ah,0dh
dbt "You entered a one. "
dbt 0d
TwoMess:
dbt 0ah,0dh
dbt "You entered a two. "
dbt 0d
ThreeMess:
dbt 0ah,0dh
dbt "You entered a three. "
dbt 0d
ErrorMess:
dbt 0ah,0dh
dbt "You entered an invalid number. "
dbt 0d
end
这是我的完整代码供参考,但我的主要问题在于输入部分无效(错误)
CheckError:
cmp #1d>
cmp #4d<
ldx #ErrorMess<
ldy #ErrorMess>
bne Main
brk
ErrorMess:
dbt 0ah,0dh
dbt "You entered an invalid number. "
dbt 0d
end
从逻辑上讲,我知道如何做到这一点,但我不知道如何使用 6502 汇编语言做到这一点,我的总体问题是我如何准确地包含除 4 select 个数字之外的所有错误数字检查。
你根本不需要 CheckError
。如果您达到 CheckFour
,则输入不是 1、2 或 3。因此您需要做的就是:
- 如果输入为
4
,则无错退出;
- 如果输入不是
4
那么,鉴于您达到了 CheckFour
,您已经知道它也不是 1
、2
或 3
。因此您知道输入不是 1
、2
、3
或 4
。所以打印错误,然后退出。
即类似于:
CheckFour:
cmp #4d
beq ValidExit
# If here, then input wasn't 1, 2, 3 or 4.
ldx #ErrorMess<
ldy #ErrorMess>
jsr 0E00Ch
ValidExit:
end
就是说,假设您想出于任何其他原因进行范围检查,如果从 a
中减去操作数的结果为负,则 cmp
设置负标志。因此,如果 a
严格小于操作数,则设置负数。
例如:
lda #4d
cmp SomeValue
bmi SomeValueWasGreaterThanFour
或:
lda #1d
cmp SomeValue
bpl SomeValueWasLessThanOrEqualToOne
... 如果您需要探索更大的范围,请考虑使用进位而不是符号或 SBC
(参见下面的评论和 Peter Cordes 的输入)。
Create a program that prints "You entered a one" if the user enters a 1,
"You entered a two" if the user enters a 2,
"You entered a three" if the user enters a 3.
The program should loop until the user enters a 4, then it should exit.If a number other than 1, 2, 3, or 4 is entered the program should print "You entered an invalid number".
org 0200h
Main:
ldx #InMess1<
ldy #InMess1>
jsr 0E00Ch
jsr 0E009h
jsr 0E015h
CheckOne:
cmp #1d
bne CheckTwo
ldx #OneMess<
ldy #OneMess>
jsr 0E00Ch
jmp Main
CheckTwo:
cmp #2d
bne CheckThree
ldx #TwoMess<
ldy #TwoMess>
jsr 0E00Ch
jmp Main
CheckThree:
cmp #3d
bne CheckFour
ldx #ThreeMess<
ldy #ThreeMess>
jsr 0E00Ch
jmp Main
CheckFour:
cmp #4d
bne Main
CheckError:
cmp #1d>
cmp #4d<
ldx #ErrorMess<
ldy #ErrorMess>
bne Main
brk
InMess1:
dbt 0ah,0dh
dbt "Enter 1-4: "
dbt 0d
OneMess:
dbt 0ah,0dh
dbt "You entered a one. "
dbt 0d
TwoMess:
dbt 0ah,0dh
dbt "You entered a two. "
dbt 0d
ThreeMess:
dbt 0ah,0dh
dbt "You entered a three. "
dbt 0d
ErrorMess:
dbt 0ah,0dh
dbt "You entered an invalid number. "
dbt 0d
end
这是我的完整代码供参考,但我的主要问题在于输入部分无效(错误)
CheckError:
cmp #1d>
cmp #4d<
ldx #ErrorMess<
ldy #ErrorMess>
bne Main
brk
ErrorMess:
dbt 0ah,0dh
dbt "You entered an invalid number. "
dbt 0d
end
从逻辑上讲,我知道如何做到这一点,但我不知道如何使用 6502 汇编语言做到这一点,我的总体问题是我如何准确地包含除 4 select 个数字之外的所有错误数字检查。
你根本不需要 CheckError
。如果您达到 CheckFour
,则输入不是 1、2 或 3。因此您需要做的就是:
- 如果输入为
4
,则无错退出; - 如果输入不是
4
那么,鉴于您达到了CheckFour
,您已经知道它也不是1
、2
或3
。因此您知道输入不是1
、2
、3
或4
。所以打印错误,然后退出。
即类似于:
CheckFour:
cmp #4d
beq ValidExit
# If here, then input wasn't 1, 2, 3 or 4.
ldx #ErrorMess<
ldy #ErrorMess>
jsr 0E00Ch
ValidExit:
end
就是说,假设您想出于任何其他原因进行范围检查,如果从 a
中减去操作数的结果为负,则 cmp
设置负标志。因此,如果 a
严格小于操作数,则设置负数。
例如:
lda #4d
cmp SomeValue
bmi SomeValueWasGreaterThanFour
或:
lda #1d
cmp SomeValue
bpl SomeValueWasLessThanOrEqualToOne
... 如果您需要探索更大的范围,请考虑使用进位而不是符号或 SBC
(参见下面的评论和 Peter Cordes 的输入)。