



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




mov al, character ;move the character into AL cmp al, PLUS ;compare AL to "+" jz doadd ;if equal, jump to addition label cmp al, MINUS ;compare AL to "-" jz dosub ;if equal, jump to subtraction label cmp al, MULTIPLY ;compare AL to "*" jz domul ;if equal, jump to multiplication label cmp al, DIVIDE ;compare AL to "/" jz dodiv ;if equal, jump to division label invoke displaymesg, addr errormes, errorlen ;fall through to display error message jmp operation ;jump to operation and ask again doadd: mov ax, number1 ;move first number into AX mov bx, number2 ;move second number into BX add ax, bx ;add AX and BX, store in AX jmp choose ;jump to choose label dosub: mov ax, number1 ;move first number into AX mov bx, number2 ;move second number into BX sub ax, bx ;subract BX from AX, store in AX jmp choose ;jump to choose label domul: mov dx, 0 ;clear out DX register mov ax, number1 ;move first number into AX mov bx, number2 ;move second number into BX imul bx ;signed multiplication of AX and BX, store in AX jmp choose ;jump to choose label dodiv: mov ax, number1 ;move first number into AX mov bx, number2 ;move second number into BX cwd ;convert AX word to double word idiv bx ;signed divide AX by BX, store in AX choose: invoke displaymesg, addr response, reslen ;display result message call putdec ;display result of arithmetic operation to stdout invoke displaymesg, addr crlf, 2 ;display carraige return, linefeed invoke displaymesg, addr choice, choicelen ;prompt user for choice to continue invoke keyread, addr character ;read user selection from keyboard cmp character, YES1 ;compare user choice to "Y" jz again ;if equal, jump to again cmp character, YES2 ;compare user choice to "y" jz again ;if equal, jump to again .exit main endp
;************************************************* ;Function: displaymesg ;Description: ; This function takes a pointer to a string ; as input and the length of the string and ; prints the result to stdout. It does this ; by using the OS int 21h and function 040h. ; BX holds the device (1), cl holds the ; length of string, dx holds the address of ; the string to be displayed. Flags and ; the 32-bit registers are pushed and popped ; of the stack. ;Input: ; m - a pointer to the string which is to be ; displayed to stdout ; l - an short integer indicating the length ; of the string to display ;Output: ; None ;Return: ; None ;************************************************* displaymesg proc near c uses ax bx cx dx, m:word,l:word pushf pushad mov ah, 040h mov bx, 1 mov cx, l mov dx, m int 21h popad popf ret displaymesg endp
;************************************************* ;Function: keyread ;Description: ; This function takes a pointer to a string
; as an inputbuffer and attempts to read the ; input from stdin. The keystrokes are stored ; as characters in the inputbuffer ; It does this by using the OS int 21h and ; function 0Ah. Dx holds the address of ; the string to be displayed. Flags and ; the 16-bit registers (AX, DX are pushed and ; popped ; of the stack. ;Input: ; input - a pointer to the string which is ; to be modified ;Output: ; input - a pointer to the string which has ; been modified ;Return: ; None ;************************************************* keyread proc near c uses ax dx, k:word pushf ;push the flags onto the stack mov ah, 01h ;put function number 0AH into AH int 21h ;request service from OS mov bx, k mov BYTE PTR [bx], al; ;put the address of inputbuffer into DX popf ;pop flags off of stack ret ;return control flow to the caller keyread endp