This program does simple arithmetic calculation (+. -, *, /, %) in masm. I've tested the code.

disp_str macro msg     ;print a string
    lea dx, msg
    mov ah, 09h
    int 21h

input macro            ;move values to ax & bx for execution
    call clear_reg
    mov ax, num1
    mov bx, num2

output macro msg, num  ;display numerical values
    disp_str msg
    mov ax, num
    call write

.model small
    msg1 db 0Ah,0Dh, "Enter the first number > $"
    msg2 db 0Ah,0Dh, "Enter the second number > $"
    msum db 0Ah,0Dh, "Sum = $"
    mdif db 0Ah,0Dh, "Difference = $"
    mprd db 0Ah,0Dh, "Product = $"
    mquo db 0Ah,0Dh, "Quotient = $"
    mrem db 0Ah,0Dh, "Remainder = $"

    num1 dw ?
    num2 dw ?
    temp dw 0
    rslt dw 0

    mov ax, @data
    mov ds, ax
    main proc
        disp_str msg1
        call read
        mov num1, ax

        disp_str msg2
        call read
        mov num2, ax

        add ax, bx
        mov rslt, ax
        output msum, rslt

        sub ax, bx
        mov rslt, ax
        output mdif, rslt

        mul bx
        mov rslt, ax
        output mprd, rslt

        div bx
        mov rslt, ax
        mov temp, dx
        output mquo, rslt
        output mrem, temp

        mov ah, 4Ch
        int 21h
    main endp

    read proc
        mov ax, 00h
        mov cx, 04h
        mov dl, 0Ah
        mul dx
        mov temp, ax
        mov ah, 01h
        int 21h
        sub al, 30h
        mov ah, 00h
        mov bx, temp
        add ax, bx
        loop L1
    read endp

    write proc
        mov bx, 0Ah
        mov cx, 00h
        mov dx, 00h
        inc cx
        div bx
        push dx
        cmp ax, 00h
        jne L2
        pop dx
        add dl, 30h
        mov ah, 02h
        int 21h
        loop L3
    write endp

    clear_reg proc    ;clears all the registers
        xor ax, ax
        xor bx, bx
        xor cx, cx
        xor dx, dx
    clear_reg endp

Output: Output

Also how does the procedure read & write work?

  • 1
    \$\begingroup\$ Your question about how read and write works suggests you didn't write the code yourself. Can you clarify if you're the author? \$\endgroup\$ – forsvarir Feb 11 at 13:18
  • 1
    \$\begingroup\$ No, I'm not the author, original program was given by the lab instructor, here p.ip.fi/LNsP, I tried to optimize it to the extent of my understanding of macros & procedures. \$\endgroup\$ – Jovial Joe Jayarson Feb 11 at 13:19
  • 2
    \$\begingroup\$ Other people's code is off topic. Read and write are essentially just wrapping the DOS api to read and write characters. spike.scu.edu.au/~barry/interrupts.html \$\endgroup\$ – forsvarir Feb 11 at 13:51

Browse other questions tagged or ask your own question.