-3

I am trying to input two numbers from user in assembly language using Irvine32 library but don't know how. This is what I have so far:

INCLUDE Irvine32.inc
.data

number1 WORD
number2 WORD

.code
main PROC



exit
main ENDP
END main
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • 1
    Irvine32.inc contains a list of all the available functions along with a brief comment that explains the purpose of the function. – Michael Mar 08 '16 at 06:38

1 Answers1

2

i'm not familiar with irvine, but how about writing the input and decode routine yourself?

DOS int 21/a reads a line from stdin, and put's it to your buffer

the decoding from ascii to register is a but more tricky; you have to walk thoug each digit and add them one by one, by shifting the curent value

here's an approach, just to have an idea: (sorry for syntax, max be incompatible to masm, I still use Eric Isaacson's A86 assembler)

.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
Tommylee2k
  • 2,683
  • 1
  • 9
  • 22
  • This 16-bit DOS answer would be a better fit on [ASM 16Bit converting input buffer string to number](https://stackoverflow.com/q/64630595) – Peter Cordes Jan 09 '22 at 21:10