【问题标题】:Decision Structures in 68k assembly language68k 汇编语言中的决策结构
【发布时间】:2017-02-01 20:04:00
【问题描述】:

我想编写一个程序,提示用户从键盘输入一个字符。对于输入的字符,将字符分类为数字、字母 如果用户输入“*”,则再次循环获取新值 问题总是显示结果是数字,当我输入字母时它不正确。感谢您的帮助。

             ORG    $1000
*read user input
START:      
            MOVEQ   #18,D0
            LEA     PR1,A1
            TRAP    #15

*COMPARING           
           MOVE.B  D1,D2 
            CMP.B   #$30,D2                 ;if ch less than ASCII '0'
            BGE     number                  
            CMP.B   #$39,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   #$2a,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

【问题讨论】:

    标签: assembly 68000 easy68k


    【解决方案1】:

    你的逻辑不正确:

    CMP.B   #$30,D2                 ;if ch less than ASCII '0'
    BGE     number                  
    CMP.B   #$39,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   #$30,D2 
    BLT     not_number
    ; We've established that ch>=0x30, now also make sure that it's also <=0x39                  
    CMP.B   #$39,D2                 
    BLE     number
    not_number:
    

    您的信件支票可能需要进行类似的更改;我没有检查那部分代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 2010-12-24
      • 1970-01-01
      • 2012-05-23
      • 1970-01-01
      • 2014-10-07
      相关资源
      最近更新 更多