-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseperation.asm
120 lines (93 loc) · 4.04 KB
/
seperation.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
115
116
117
118
119
120
.MODEL SMALL
.STACK 64
.DATA
operation DB 'MOV AX,BX','$'
instruction DB 5 DUP('$')
operands DB 20 dup('$')
operand1 DB 5 DUP('$')
operand2 DB 5 DUP('$')
sizeOfInstruction DW ?
sizeOfOperand1 DW ?
sizeOfOperand2 DW ?
.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX
;------------------------------------------------------------------------------------------------------
;-----here I seperated the operation into instruction+ operand1+operand2-------------
XOR SI,SI
XOR DI,DI
XOR AX,AX
XOR BX,BX
XOR CX,CX
XOR DX,DX
MOV SI, OFFSET operation
MOV BP,SI
MOV DI, OFFSET instruction
MOV sizeOfInstruction,SI
Prepare_instruction_Seperate: ; here you are trying to check if you found space or not, if u don't, it will jump to instruction_seperate Loop
CMP [SI],20h ; 20h= ASCII code of SPACE
JNE instruction_seperate
SUB SI,BP ;from the beginning of this line to the next JMP is shuffling between registers and variables to the size of the instruction
MOV sizeOfInstruction,SI
MOV SI,BP
ADD SI,sizeOfInstruction
JMP Prepare_operand_seperation
instruction_seperate: ;This loop is responsible for the copy the chars of instruction into instruction variable
MOV Al,[SI]
MOV [DI],Al
INC DI
INC SI
JMP Prepare_instruction_Seperate
Prepare_operand_seperation:
MOV DI,OFFSET operands
INC SI
label1:
CMP [SI],24H ;24h= ASCII code of $
JNE operand_seperation
JE prepare_seperation_first_operand
Operand_seperation:
MOV Al,[SI]
MOV [DI],Al
INC DI
INC SI
JMP label1
prepare_seperation_first_operand: ;this loop is to seperate the operands into operand1 and operand2
MOV SI,OFFSET operands
MOV DI,OFFSET OPERAND1
MOV BP,SI
MOV sizeOfOperand1,SI
label2: CMP [SI],','
JNZ seperate_first_operand
SUB SI,BP ;from the beginning of this line to the next JMP is shuffling between registers and variables to the size of the instruction
MOV sizeOfOperand1,SI
MOV SI,BP
ADD SI,sizeOfOperand1
JMP prepare_seperation_second_operand
seperate_first_operand:
MOV AL,[SI]
MOV [DI],AL
INC DI
INC SI
JMP label2
prepare_seperation_second_operand:
INC SI
MOV DI,OFFSET OPERAND2
MOV BP,SI
MOV sizeOfOperand2,SI
label3: CMP [SI],'$'
JNE seperate_second_operand
SUB SI,BP ;from the beginning of this line to the next JMP is shuffling between registers and variables to the size of the instruction
MOV sizeOfOperand2,SI
MOV SI,BP
ADD SI,sizeOfOperand2
JMP FINISHED_SEPERATION
seperate_second_operand:
MOV AL,[SI]
MOV [DI],AL
INC DI
INC SI
JMP label3
FINISHED_SEPERATION: ;now you have the instruction in instruction variable, also you have operand1 and operand2
MAIN ENDP
END MAIN