-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiniCalculator.asm
More file actions
88 lines (73 loc) · 1.11 KB
/
MiniCalculator.asm
File metadata and controls
88 lines (73 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
.model small
.stack 100h
.data
msg1 db 'Enter first digit: $'
msg2 db 0Dh,0Ah,'Enter operator (+ - * /): $'
msg3 db 0Dh,0Ah,'Enter second digit: $'
msg4 db 0Dh,0Ah,'Result: $'
.code
main:
mov ax, @data
mov ds, ax
; First number
lea dx, msg1
mov ah, 09h
int 21h
mov ah, 01h
int 21h
sub al, '0'
mov bl, al
; Operator
lea dx, msg2
mov ah, 09h
int 21h
mov ah, 01h
int 21h
mov bh, al
; Second number
lea dx, msg3
mov ah, 09h
int 21h
mov ah, 01h
int 21h
sub al, '0'
mov cl, al
; Perform Operation
cmp bh, '+'
je add_op
cmp bh, '-'
je sub_op
cmp bh, '*'
je mul_op
cmp bh, '/'
je div_op
jmp exit
add_op:
mov al, bl
add al, cl
jmp display
sub_op:
mov al, bl
sub al, cl
jmp display
mul_op:
mov al, bl
mul cl
jmp display
div_op:
mov ax, 0
mov al, bl
div cl
jmp display
display:
add al, '0'
lea dx, msg4
mov ah, 09h
int 21h
mov dl, al
mov ah, 02h
int 21h
exit:
mov ah, 4Ch
int 21h
end main