Emulator Calcu
Emulator Calcu
Emulator Calcu
PUTC MACRO char push ax, mov al, char mov ah, 0EH int 10h pop ax
endm
msg0 db "note: calculator works with integer values only.",0Dh,0Ah db "",0Dh,0Ah,'$' msg1 db 0Dh,0Ah, 0Dh,0Ah, 'enter first number: $' msg2 db "enter the operator: + - * / msg3 db "enter second number: $" : $"
msg4 db 0dh,0ah , 'the approximate result of my calculations is : $' err1 db "wrong operator!", 0Dh,0Ah , '$' smth db " and something.... $"
opr db '?'
num1 dw ? num2 dw ?
call scan_num
mov num1, cx
call scan_num
mov num2, cx
int 21h
exit:
ret
do_plus:
jmp exit
do_minus:
jmp exit
do_mult:
jmp exit
do_div:
mov dx, 0 mov ax, num1 idiv num2 cmp dx, 0 jnz approx call print_num jmp exit approx: call print_num lea dx, smth mov ah, 09h int 21h jmp exit
scan_num
PROC NEAR
MOV
CX, 0
MOV
CS:make_minus, 0
next_digit:
MOV INT
MOV INT
CMP JE
backspace_checked:
cmp jne
dx, 0 too_big
sub
al, 30h
jmp
next_digit
too_big2: mov mov too_big: mov div mov AX, CX CS:ten CX, AX CX, DX DX, 0
stop_input:
CS:make_minus, 0 not_minus CX
SI AX DX
make_minus SCAN_NUM
DB ENDP
PROC NEAR
CMP JNZ
AX, 0 not_zero
not_zero:
AX, 0 positive AX
PUTC '-'
MOV
CX, 1
MOV
BX, 10000
CMP JZ
AX, 0 print_zero
begin_print:
CMP JZ
BX,0 end_print
CMP JE
CX, 0 calc
AX, BX skip
CX, 0
MOV DIV
DX, 0 BX
ADD
AL, 30h
PUTC AL
MOV
AX, DX
skip:
CS:ten BX, AX AX
JMP
begin_print
end_print:
DX CX BX AX
PRINT_NUM_UNS ENDP
ten
DW
10
PROC NEAR
MOV
CX, 0
CMP JBE
DX, 1 empty_buffer
DEC
DX
wait_for_key:
MOV INT
AH, 0 16h
CMP
AL, 0Dh
JZ
exit_GET_STRING
CMP JNE
AL, 8 add_to_buffer
add_to_buffer:
CMP JAE
CX, DX wait_for_key
[DI], AL DI CX
MOV INT
JMP
wait_for_key
;============================
exit_GET_STRING:
MOV
[DI], 0
empty_buffer:
DX DI CX AX
GET_STRING
ENDP