How to convert string to number in Tasm?

前端 未结 1 1725
心在旅途
心在旅途 2020-12-11 12:06

I made a program that reads a string and converts it into a number. A string representation of the number entered in the decimal system. The result of of converting is in re

相关标签:
1条回答
  • 2020-12-11 12:57

    You could, for example, extend your multiplication by 10 from 16 to 32 bits like this:

    ; file: mul32ten.asm
    ; compile: nasm.exe mul32ten.asm -f bin -o mul32ten.com
    
    bits 16
    org 0x100
    
        xor     dx, dx
        xor     ax, ax
    
        mov     si, MyStr
    
    NextDigit:
        mov     bl, [si]
        or      bl, bl
        je      Done
        call    MulDxAxBy10
        sub     bl, '0'
        add     al, bl
        adc     ah, 0
        adc     dx, 0
        inc     si
        jmp     NextDigit
    
    Done:
        ; dx:ax should be equal to 7FFFFFFF now
        ret
    
    MulDxAxBy10:
        push    si
        push    di
        shld    dx, ax, 1
        shl     ax, 1       ; dx:ax = n * 2
        mov     si, ax
        mov     di, dx      ; di:si = n * 2
        shld    dx, ax, 2
        shl     ax, 2       ; dx:ax = n * 8
        add     ax, si
        adc     dx, di      ; dx:ax = n * 8 + n * 2 = n * (8 + 2) = n * 10
        pop     di
        pop     si
        ret
    
    MyStr db "2147483647", 0
    
    0 讨论(0)
提交回复
热议问题