如何字符串转换为数字在8086汇编? [英] How to convert String to Number in 8086 assembly?

查看:368
本文介绍了如何字符串转换为数字在8086汇编?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在8086汇编建基地转换器。

I have to build a Base Converter in 8086 assembly .

用户必须选择他基于然后把一个号码,
在此之后,程序会显示他他的3个碱基数目[他带来一个十进制数,并在此之后,他将看到他在十六进制,华侨城,和bin数量。

The user has to choose his based and then put a number, after then , the program will show him his number in 3 more bases[he bring a decimal number, and after this he will see his number in hex, oct, and bin.

这第一个问题是,我怎么能转换他给我的号码,从字符串到多少?

This first question is, how can I convert the number he gave me, from string, to a number?

美国证券交易委员会的问题是,我如何转换?由RCR,然后ADC一些变量?

the sec question is, how can i convert? by RCR, and then adc some variable?

下面是我的code:

data segment

  N=8

       ERROR_STRING_BASE DB ,10,13, "               THIS IS NOT A BASE!",10,13, "               TRY AGINE" ,10,13," $"     
        OPENSTRING DB "                      Welcome, to the Base    Convertor",10,13,"                     Please enter your base to convert     from:",10,13,"                   <'H'= Hex, 'D'=Dec, 'O'=oct, 'B'=bin>: $"

  Hex_string DB "(H)" ,10,13, "$"
  Octalic_string DB "(O) ",10,13, "$" 
  Binar_string DB "(B)",10,13, "$"
  Dece_string DB "(D)",10,13, "$"

  ENTER_STRING DB ,10,13, "      Now, Enter Your Number (Up to 4 digits) ",10,13, "$"
     Illegal_Number DB ,10,13, "      !!!  This number is illegal, lets Start     again" ,10,13,"$"


  BASED_BUFFER  DB N,?,N+1  DUP(0)  
  Number_buffer  db N, ? ,N+1 DUP(0)


  TheBase DB N DUP(0)                           
  The_numer DB N DUP(0)
  The_binNumber DB 16 DUP(0)
  data ends

   sseg segment stack
   dw   128  dup(0)
   sseg ends

    code segment
    assume ss:sseg,cs:code,ds:data

    start:  mov ax,data
    mov ds,ax


      MOV DX,OFFSET OPENSTRING ;PUTS THE OPENING SRTING 
      MOV AH,9
      INT 21H

    call EnterBase 

     CALL  CheckBase




     HEXBASE: CALL PRINTtheNUMBER 
     MOV DX,OFFSET Hex_string
     MOV AH,9
     INT 21h 
     JMP I_have_the_numberH 

     oCTALICbASE: CALL PRINTtheNUMBER 
     MOV DX,OFFSET Octalic_string 
     MOV AH,9
     INT 21h  
     JMP I_have_the_numberO          

     BINBASE:CALL PRINTtheNUMBER 
     MOV DX,OFFSET Binar_string
     MOV AH,9
     INT 21h  
     JMP I_have_the_numberB

     DECBASE: CALL PRINTtheNUMBER   
     MOV DX,OFFSET Dece_string
     MOV AH,9
     INT 21h 
     JMP I_have_the_numberD





    I_have_the_numberH: CALL BINcalculation
                CALL OCTcalculation
                CALL DECcalculation 




    I_have_the_numberO: CALL BINcalculation
                CALL DECcalculation
                CALL HEXcalculation


    I_have_the_numberB: CALL OCTcalculation
                CALL DECcalculation
                CALL HEXcalculation


    I_have_the_numberD: CALL BINcalculation
                CALL OCTcalculation
                CALL HEXcalculation


     exit:  mov ax, 4c00h
      int 21h  



     EnterBase PROC

     MOV DX,OFFSET BASED_BUFFER  ; GETS THE BASE 
     MOV AH,10
     INT 21H 


     LEA DX,BASED_BUFFER[2]
     MOV BL,BASED_BUFFER[1]
     MOV BH,0
     MOV BASED_BUFFER[BX+2],0

     LEA SI, BASED_BUFFER[2]
     XOR CX, CX
     MOV CL, BASED_BUFFER[1]

     LEA DI, TheBase

     LOL_OF_BASE:   MOV DL, [SI]
           MOV [DI], DL
           INC SI
           INC DI
           INC AL


        RET


       EnterBase  ENDP   



       CheckBase proc



       CMP  TheBase,'H' 
       JE HEXBASE

       CMP  TheBase,'h'
         JE HEXBASE


       CMP TheBase,'O'
        JE oCTALICbASE

       CMP TheBase,'o'
       JE oCTALICbASE

        CMP TheBase,'B'
         JE BINBASE 

         CMP TheBase,'b'
       JE BINBASE

        CMP TheBase,'D'
       JE DECBASE

        CMP TheBase,'d'
        JE DECBASE
        CMP TheBase, ' ' 
        je ERRORoFBASE 

      ERRORoFBASE: MOV DX,OFFSET  ERROR_STRING_BASE ;PUTS WORNG BASE Illegal_Number 
      MOV AH,9
      INT 21H 
      JMP START      



    CheckBase  ENDP




   PRINTtheNUMBER  PROC 


    MOV DX,OFFSET ENTER_STRING
     MOV AH,9
     INT 21h 


    MOV DX,OFFSET Number_buffer  ; GETS THE number
    MOV AH,10
    INT 21H 


     LEA DX,Number_buffer[2]
     MOV BL,Number_buffer[1]
     MOV BH,0
     MOV Number_buffer[BX+2],0

     LEA SI, Number_buffer[2]
     XOR CX, CX
     MOV CL, Number_buffer[1]

     LEA DI, The_numer 
     xor AL,AL

     LOL_OF_NUMBER_CHECK:   MOV DL, [SI]
                   MOV [DI], DL
                   INC SI
                   INC DI
                   INC AL 
                   CMP AL,5 
                   JE ERRORofNUMBER 
                   LOOP LOL_OF_NUMBER_CHECK 


    RET 

      ERRORofNUMBER: MOV DX,OFFSET  Illegal_Number ;PUTS WORNG BASE         Illegal_Number 
      MOV AH,9
      INT 21H 
      JMP START        

     PRINTtheNUMBER ENDP








      PROC BINcalculation  
          XOR CX,CX
          XOR AX,AX
          MOV CX,4
          MOV AX,16
          LEA SI, The_binNumber[0]
       TheBinarLoop: RCL  The_numer,1
          ADC [SI],0
          INC SI
          LOOP TheBinarLoop

      ENDP

      PROC OCTcalculation



      ENDP

      PROC DECcalculation

      ENDP

      PROC  HEXcalculation

      ENDP

     code  ends

     end start

应该是这样的:

谢谢!

שלולוי

推荐答案

从任何基地整数解code ASCII字符串的algorighm是相同的:

the algorighm to decode ascii strings from ANY base to integer is the same:

result = 0
for each digit in ascii-string
   result *= base
   result += value(digit)

有关{仓,华侨城,DEC}值(数字)是ASCII码(数字)-ascii('0')结果
十六进制是一个比较复杂一点,你必须检查值是'A' - 'F',并且将其转换为10-15

for { bin, oct, dec } value(digit) is ascii(digit)-ascii('0')
hex is a bit more complicated, you have to check if the value is 'a'-'f', and convert this to 10-15

转换整数为ascii(碱x)是相似的,你必须通过碱来划分的值,直到它的0,并在左侧添加其余的ASCII重新presentation

converting integer to ascii(base x) is similar, you have to divide the value by base until it's 0, and add ascii representation of the remainder at the left

e.g. 87/8= 10, remainder 7 --> "7"
     10/8=  1, remainder 2 --> "27"
      1/8=  0, remainder 1 --> "127"

这篇关于如何字符串转换为数字在8086汇编?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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