Reading a number using INT 21h (DOS) & 8086 assmebly

前端 未结 2 1978
借酒劲吻你
借酒劲吻你 2020-12-06 21:06

I need to prompt to user a msg that tells him to write a number , then I store this number and do some operation on it After searching in INT 21h I found this :

         


        
2条回答
  •  天涯浪人
    2020-12-06 21:43

    When you managed to get the user input, put the its pointer in ESI (ESI = address to the string)

    .DATA
    myNumber BYTE "12345",0        ;for test purpose I declare a string '12345'
    
    Main Proc
        xor ebx,ebx                ;EBX = 0
        mov  esi,offset myNumber   ;ESI points to '12345'
    
    loopme:
    
        lodsb                      ;load the first byte pointed by ESI in al
    
        cmp al,'0'                 ;check if it's an ascii number [0-9]
        jb noascii                 ;not ascii, exit
        cmp al,'9'                 ;check the if it's an ascii number [0-9]
        ja noascii                 ;not ascii, exit
    
        sub al,30h                 ;ascii '0' = 30h, ascii '1' = 31h ...etc.
        cbw                        ;byte to word
        cwd                        ;word to dword
        push eax
        mov eax,ebx                ;EBX will contain '12345' in hexadecimal
        mov ecx,10
        mul ecx                    ;AX=AX*10
        mov ebx,eax
        pop eax
        add ebx,eax
        jmp loopme                 ;continue until ESI points to a non-ascii [0-9] character
        noascii:
        ret                        ;EBX = 0x00003039 = 12345
    Main EndP
    

提交回复
热议问题