组装将任何基础转换为任何基础 [英] Assembly Conversion any base to any base

查看:82
本文介绍了组装将任何基础转换为任何基础的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个程序,输入数字和基数,并将此数字转换为任何基数.在这个最初的例子中,我从用户那里得到数字和基数,问题是..我如何验证数字是否来自该基数?

i'm doing a program to input a number and base, and convert this number to any base. In this initial fase, i get from the user the number and base, the question is.. How i can verify if the number is from that base?

NUMBER_INPUT PROC
   jmp @again   
   @ERROR:                        

   LEA DX, ILLEGAL               
   MOV AH, 9
   INT 21H

   @AGAIN:                  
   print num
   MOV CX, 8                   
   XOR BX, BX               
   MOV AH, 1                 

   @INPUT:                      
     INT 21H                    

     CMP AL, 0DH               
     JE @END                    

     CMP AL, 30H               
     JL @ERROR               

     ; CMP AL, 31H              
     ; JG @ERROR                  

     AND AL, 0FH           
     SHL BX, 1                 
     OR  BL, AL                 
     LOOP @INPUT             
   @END:              
   RET                          
NUMBER_INPUT ENDP


BASE_INPUT PROC
   JMP @AGAIN                   

   @ERROR:               

   LEA DX, ILLEGAL               
   MOV AH, 9
   INT 21H

   @AGAIN:                  
   print base
   MOV CX, 2                     
   XOR DX, DX               
   MOV AH, 1              

   @INPUT:                   
     INT 21H                 

     CMP AL, 0DH              
     JE @END               

     CMP AL, 30H              
     JL @ERROR                          

     AND AL, 0FH                 
     SHL DX, 1             
     OR  DL, AL               
     LOOP @INPUT               

   @END:                   
   RET                        
BASE_INPUT ENDP

推荐答案

唯一的方法-如果没有约定将底数表示为数字表示形式的一部分,则使底数明确无误,就是检测数字值任何数字的大于或等于预期的数字基数.但是,即使指定了数字基数,您仍然想检查所有数字的合法性,只是为了避免产生垃圾输出.说,代表值"10"的数字"A"在基数10的数字中可能不会出现."8"在数字基数8和更低的数字中没有位置.而且对于十六进制而言,可能没有非法的"G"(我们将其归因于数值16).您可能希望将转换器限制为基数36,因为用尽了一些有意义的符号来表示数字,因为基数36可能采用0-9,A-Z.

only way - in case there are no conventions to express the number base as part of the number representation, making the number base unambiguous, is to detect whether numeric value of any digit is greater or same as the intended number base. But even with specifying the number base, you still want to check for legality of all digits, simply to avoid to produce garbage output. Say, digit "A" representing value "10" may not occur in numbers of radix 10. "8" has no place in number bases 8 and lower. And there may be no "G" (to which we'd attribute numeric value 16) is illegal for hex. You may want to limit your converter to radix 36, as you'd be running out of meaningful symbols for representing digits, as radix 36 could employ 0-9,A-Z.

这篇关于组装将任何基础转换为任何基础的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆