用汇编语言输入数字

Input numbers with assembly language

我正在尝试使用 Irvine32 库以汇编语言从用户输入两个数字,但不知道如何操作。这是我目前所拥有的:

INCLUDE Irvine32.inc
.data

number1 WORD
number2 WORD

.code
main PROC



exit
main ENDP
END main

我对irvine不熟悉,但是自己写输入和解码例程怎么样?

DOS int 21/a 从标准输入读取一行,并将其放入您的缓冲区

从 ascii 解码到寄存器是一个但更棘手的问题;你必须通过移动当前值

来遍历每个数字并一个一个地添加它们

这里有一个方法,仅供参考: (语法抱歉,max与masm不兼容,我还是用Eric Isaacson的A86汇编器)

.org 0100
JMP start

buffer: db 10,"          "  ; space for 10 digits

; read input to buffer
input:  mov ah, 0ah         ; input value
        mov dx, buffer
        int 21h
        ret

; decode buffer to CX
decode: mov dx,0
        mov si, buffer+2
        mov cl, [buffer+1]    ; while (numChars>0)

decLoop: cmp cl,0
        je decEnd

        mov ax, dx          ; mul DX by 10
        shl ax, 2
        add ax, dx
        shl ax, 1
        mov dx, ax

        mov al,[si]        ; get current digit
        inc si             ; and point to next one
        sub al,'0'
        mov ah, 0
        add dx, ax          ; add the digit read

        dec cl              ; numChars--
        jmp decLoop
decEnd: ret


; main()
start:  call input
        call decode
        push dx
        call input
        call decode
        pop cx

        ; CX now holds first, DX second number
        ; feel free to do with em what you feel like

        int 20h             ; quit