-
Notifications
You must be signed in to change notification settings - Fork 0
/
CALCULATOR_VDU.ASM
executable file
·114 lines (94 loc) · 1.46 KB
/
CALCULATOR_VDU.ASM
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
;MAIN
CLO
MOV BL,B0 ; MEMORY
CALL 8A ;INPUT
;----------------
MOV DL,[B1] ; SIGN
MOV AL,[B0] ; NUMBER 1
MOV BL,[B2] ; NUMBER 2
;----------------
SUB AL,30 ; TO GET CORRECT NUMBER
SUB BL,30
;-----SIGN CHECK---
CMP DL,2B ; +
JZ PLUS ;IF SIGN +
CMP DL,2D ; -
JZ MINUS ;IF SIGN -
CMP DL,2A ; *
JZ MULTI ;IF SIGN *
CMP DL,2F ; /
JZ DIVID ;IF SIGN /
;=================
JMP STOPP ; IF NO SIGN
PLUS:
ADD AL,BL
JMP CONTROL
MINUS:
SUB AL,BL
JS NEGAT ; S=1=NEGATIVE RESULT
CALL A8
HALT
MULTI:
MUL AL,BL
JMP CONTROL
DIVID:
DIV AL,BL
CALL A8
HALT
NEGAT: ;NEGATIVE RESULT
MOV AL,[B2] ; NUMBER 2
MOV BL,[B0] ; NUMBER 1
SUB AL,30 ; TO GET CORRECT NUMBER
SUB BL,30
SUB AL,BL ;NUM2-NUM1=POSITIVE RESULT
MOV CL,2D ; MINUS SIGN
MOV [C0],CL ; OUTPUT -
CALL A8 ; OUTPUT NUMBER
HALT
CONTROL:
MOV [B4],AL
CMP AL,0A ; 9-10= -1 , 10-10= +0 , 24-10= +14
JS OUPUT ; IF AL 0-9
DIV AL,0A ; IF AL 10-99, 24/10= 2 NUMBER OF TENS
MOV [B5],AL
MUL AL,0A ; 2*10= 20
MOV BL,[B4]
SUB BL,AL ; 24-20= 4 NUMBER OF UNITS
PUSH BL
MOV AL,[B5]
ADD AL,30
MOV [C0],AL ; VDU
POP AL
ADD AL,30
MOV [C1],AL
HALT ; PRESS CPU RESET
OUPUT:
CALL A8
STOPP:
HALT
;---INPUT---
ORG 8A
;PUSH AL
;PUSH BL
PUSHF
MOV CL,3 ; COUNTER
REP:
IN 00
MOV [BL],AL
INC BL
DEC CL
JNZ REP ; IF CL=0 STOP
STOP:
MOV AL,0
MOV [BL],AL
POPF
;POP BL
;POP AL
RET
;----OUTPUT VDU----
ORG A8
ADD AL,30 ; TO GET CORRECT SIGN CODE
MOV [C1],AL
RET
; PRESS CPU RESET
END