68k 汇编语言中的决策结构
Decision Structures in 68k assembly language
我想编写提示用户从键盘输入一个字符的程序。对于输入的字符,将字符分类为数字、字母
如果用户输入“*”,则再次循环获取新值
问题是总是显示结果是数字,当我输入字母时不正确。感谢您的帮助。
ORG 00
*read user input
START:
MOVEQ #18,D0
LEA PR1,A1
TRAP #15
*COMPARING
MOVE.B D1,D2
CMP.B #,D2 ;if ch less than ASCII '0'
BGE number
CMP.B #,D2 ;check if ch greater than ASCII '9'
BLE number
ANDI #$DF,D2 ;CONVERT TO UPPERCASE
CMP.B #65,D2
BGE letter
CMP.B #90,D2
BLE letter
CMP.B #a,D1 ;if user enter *
BEQ START ;then loop again to enter new value
number LEA n,A1
JSR P_STR
MOVE.B #5,D0
TRAP #15
letter LEA l,A1
JSR P_STR
MOVE.B #5,D0
TRAP #15
PR1 DC.B 'Enter value: ',0
n DC.B 'Number',0
l DC.B 'Letter',0
INCLUDE 'sample.x68' ; it is the file Prints a string withCR/LF
END START
你的逻辑不正确:
CMP.B #,D2 ;if ch less than ASCII '0'
BGE number
CMP.B #,D2 ;check if ch greater than ASCII '9'
BLE number
这转化为:
if (ch >= 0x30 || ch <= 0x39) goto number;
你想要的是:
if (ch >= 0x30 && ch <= 0x39) goto number;
看起来像这样:
CMP.B #,D2
BLT not_number
; We've established that ch>=0x30, now also make sure that it's also <=0x39
CMP.B #,D2
BLE number
not_number:
您的信件支票可能需要类似的更改;我没有检查那部分代码。
我想编写提示用户从键盘输入一个字符的程序。对于输入的字符,将字符分类为数字、字母 如果用户输入“*”,则再次循环获取新值 问题是总是显示结果是数字,当我输入字母时不正确。感谢您的帮助。
ORG 00
*read user input
START:
MOVEQ #18,D0
LEA PR1,A1
TRAP #15
*COMPARING
MOVE.B D1,D2
CMP.B #,D2 ;if ch less than ASCII '0'
BGE number
CMP.B #,D2 ;check if ch greater than ASCII '9'
BLE number
ANDI #$DF,D2 ;CONVERT TO UPPERCASE
CMP.B #65,D2
BGE letter
CMP.B #90,D2
BLE letter
CMP.B #a,D1 ;if user enter *
BEQ START ;then loop again to enter new value
number LEA n,A1
JSR P_STR
MOVE.B #5,D0
TRAP #15
letter LEA l,A1
JSR P_STR
MOVE.B #5,D0
TRAP #15
PR1 DC.B 'Enter value: ',0
n DC.B 'Number',0
l DC.B 'Letter',0
INCLUDE 'sample.x68' ; it is the file Prints a string withCR/LF
END START
你的逻辑不正确:
CMP.B #,D2 ;if ch less than ASCII '0'
BGE number
CMP.B #,D2 ;check if ch greater than ASCII '9'
BLE number
这转化为:
if (ch >= 0x30 || ch <= 0x39) goto number;
你想要的是:
if (ch >= 0x30 && ch <= 0x39) goto number;
看起来像这样:
CMP.B #,D2
BLT not_number
; We've established that ch>=0x30, now also make sure that it's also <=0x39
CMP.B #,D2
BLE number
not_number:
您的信件支票可能需要类似的更改;我没有检查那部分代码。