Subversion Repositories Kolibri OS

Rev

Rev 1044 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1044 Rev 1189
Line 113... Line 113...
113
	mov	eax,[error_line]
113
	mov	eax,[error_line]
114
	or	eax,eax
114
	or	eax,eax
115
	jz	assemble_ok
115
	jz	assemble_ok
116
	mov	[current_line],eax
116
	mov	[current_line],eax
117
	jmp	near [error]
117
	call	error_handler
-
 
118
      error_handler:
-
 
119
	mov	eax,[error]
118
      next_pass:
120
	sub	eax,error_handler
-
 
121
	add	[esp],eax
-
 
122
	ret
-
 
123
      next_pass:
119
	inc	[current_pass]
124
	inc	[current_pass]
120
	mov	ax,[current_pass]
125
	mov	ax,[current_pass]
121
	cmp	ax,[passes_limit]
126
	cmp	ax,[passes_limit]
122
	je	code_cannot_be_generated
127
	je	code_cannot_be_generated
123
	jmp	assembler_loop
128
	jmp	assembler_loop
Line 357... Line 362...
357
;        mov     [rex_prefix],0
362
;        mov     [rex_prefix],0
358
	mov	dword [operand_size],0
363
	mov	dword [operand_size],0
359
	mov	[opcode_prefix],0
364
	mov	[opcode_prefix],0
360
	mov	[immediate_size],0
365
	mov	[immediate_size],0
361
	movzx	ebx,word [esi]
366
	call	instruction_handler
-
 
367
      instruction_handler:
-
 
368
	movzx	ebx,word [esi]
362
	mov	al,[esi+2]
369
	mov	al,[esi+2]
363
	add	ebx,assembler
370
	add	esi,3
364
	add	esi,3
-
 
365
	jmp	near ebx
371
	add	[esp],ebx
366
      instruction_assembled:
372
	ret
-
 
373
      instruction_assembled:
367
	mov	al,[esi]
374
	mov	al,[esi]
368
	cmp	al,0Fh
375
	cmp	al,0Fh
369
	je	line_assembled
376
	je	line_assembled
370
	or	al,al
377
	or	al,al
371
	jnz	extra_characters_on_line
378
	jnz	extra_characters_on_line
Line 892... Line 899...
892
	mov	byte [org_registers+1],bl
899
	mov	byte [org_registers+1],bl
893
	mov	byte [org_registers+2],ch
900
	mov	byte [org_registers+2],ch
894
	mov	byte [org_registers+3],cl
901
	mov	byte [org_registers+3],cl
895
	call	allocate_structure_data
902
	call	allocate_structure_data
896
	mov	word [ebx],virtual_directive-assembler
903
	mov	word [ebx],virtual_directive-instruction_handler
897
	not	eax
904
	not	eax
898
	not	edx
905
	not	edx
899
	add	eax,1
906
	add	eax,1
900
	adc	edx,0
907
	adc	edx,0
901
	add	eax,edi
908
	add	eax,edi
902
	adc	edx,0
909
	adc	edx,0
Line 991... Line 998...
991
	cmp	eax,0
998
	cmp	eax,0
992
	je	zero_repeat
999
	je	zero_repeat
993
	jl	negative_repeat
1000
	jl	negative_repeat
994
	call	allocate_structure_data
1001
	call	allocate_structure_data
995
	mov	word [ebx],repeat_directive-assembler
1002
	mov	word [ebx],repeat_directive-instruction_handler
996
	xchg	eax,[counter_limit]
1003
	xchg	eax,[counter_limit]
997
	mov	[ebx+10h],eax
1004
	mov	[ebx+10h],eax
998
	mov	eax,1
1005
	mov	eax,1
999
	xchg	eax,[counter]
1006
	xchg	eax,[counter]
1000
	mov	[ebx+14h],eax
1007
	mov	[ebx+14h],eax
1001
	mov	[ebx+8],esi
1008
	mov	[ebx+8],esi
Line 1036... Line 1043...
1036
	call	find_end_repeat
1043
	call	find_end_repeat
1037
	jmp	instruction_assembled
1044
	jmp	instruction_assembled
1038
      find_end_repeat:
1045
      find_end_repeat:
1039
	call	find_structure_end
1046
	call	find_structure_end
1040
	cmp	ax,repeat_directive-assembler
1047
	cmp	ax,repeat_directive-instruction_handler
1041
	jne	unexpected_instruction
1048
	jne	unexpected_instruction
1042
	ret
1049
	ret
1043
while_directive:
1050
while_directive:
1044
	cmp	[prefixed_instruction],0
1051
	cmp	[prefixed_instruction],0
1045
	jne	unexpected_instruction
1052
	jne	unexpected_instruction
1046
	call	allocate_structure_data
1053
	call	allocate_structure_data
1047
	mov	word [ebx],while_directive-assembler
1054
	mov	word [ebx],while_directive-instruction_handler
1048
	mov	eax,1
1055
	mov	eax,1
1049
	xchg	eax,[counter]
1056
	xchg	eax,[counter]
1050
	mov	[ebx+10h],eax
1057
	mov	[ebx+10h],eax
1051
	mov	[ebx+8],esi
1058
	mov	[ebx+8],esi
1052
	mov	eax,[current_line]
1059
	mov	eax,[current_line]
1053
	mov	[ebx+4],eax
1060
	mov	[ebx+4],eax
Line 1083... Line 1090...
1083
	mov	esi,[ebx+8]
1090
	mov	esi,[ebx+8]
1084
	jmp	do_while
1091
	jmp	do_while
1085
      find_end_while:
1092
      find_end_while:
1086
	call	find_structure_end
1093
	call	find_structure_end
1087
	cmp	ax,while_directive-assembler
1094
	cmp	ax,while_directive-instruction_handler
1088
	jne	unexpected_instruction
1095
	jne	unexpected_instruction
1089
	ret
1096
	ret
1090
if_directive:
1097
if_directive:
1091
	cmp	[prefixed_instruction],0
1098
	cmp	[prefixed_instruction],0
1092
	jne	unexpected_instruction
1099
	jne	unexpected_instruction
1093
	call	calculate_logical_expression
1100
	call	calculate_logical_expression
Line 1103... Line 1110...
1103
	jc	instruction_assembled
1110
	jc	instruction_assembled
1104
	mov	al,[esi]
1111
	mov	al,[esi]
1105
	cmp	al,1
1112
	cmp	al,1
1106
	jne	else_true
1113
	jne	else_true
1107
	cmp	word [esi+1],if_directive-assembler
1114
	cmp	word [esi+1],if_directive-instruction_handler
1108
	jne	else_true
1115
	jne	else_true
1109
	add	esi,4
1116
	add	esi,4
1110
	jmp	if_directive
1117
	jmp	if_directive
1111
      if_true:
1118
      if_true:
1112
	xor	al,al
1119
	xor	al,al
1113
      make_if_structure:
1120
      make_if_structure:
1114
	call	allocate_structure_data
1121
	call	allocate_structure_data
1115
	mov	word [ebx],if_directive-assembler
1122
	mov	word [ebx],if_directive-instruction_handler
1116
	mov	byte [ebx+2],al
1123
	mov	byte [ebx+2],al
1117
	mov	eax,[current_line]
1124
	mov	eax,[current_line]
1118
	mov	[ebx+4],eax
1125
	mov	[ebx+4],eax
1119
	jmp	instruction_assembled
1126
	jmp	instruction_assembled
1120
      else_true:
1127
      else_true:
1121
	or	al,al
1128
	or	al,al
Line 1126... Line 1133...
1126
	jmp	make_if_structure
1133
	jmp	make_if_structure
1127
      else_directive:
1134
      else_directive:
1128
	cmp	[prefixed_instruction],0
1135
	cmp	[prefixed_instruction],0
1129
	jne	unexpected_instruction
1136
	jne	unexpected_instruction
1130
	mov	ax,if_directive-assembler
1137
	mov	ax,if_directive-instruction_handler
1131
	call	find_structure_data
1138
	call	find_structure_data
1132
	jc	unexpected_instruction
1139
	jc	unexpected_instruction
1133
	cmp	byte [ebx+2],0
1140
	cmp	byte [ebx+2],0
1134
	jne	unexpected_instruction
1141
	jne	unexpected_instruction
1135
      found_else:
1142
      found_else:
1136
	mov	al,[esi]
1143
	mov	al,[esi]
1137
	cmp	al,1
1144
	cmp	al,1
1138
	jne	skip_else
1145
	jne	skip_else
1139
	cmp	word [esi+1],if_directive-assembler
1146
	cmp	word [esi+1],if_directive-instruction_handler
1140
	jne	skip_else
1147
	jne	skip_else
1141
	add	esi,4
1148
	add	esi,4
1142
	call	find_else
1149
	call	find_else
1143
	jnc	found_else
1150
	jnc	found_else
1144
	call	remove_structure_data
1151
	call	remove_structure_data
1145
	jmp	instruction_assembled
1152
	jmp	instruction_assembled
Line 1159... Line 1166...
1159
	call	remove_structure_data
1166
	call	remove_structure_data
1160
	jmp	instruction_assembled
1167
	jmp	instruction_assembled
1161
      find_else:
1168
      find_else:
1162
	call	find_structure_end
1169
	call	find_structure_end
1163
	cmp	ax,else_directive-assembler
1170
	cmp	ax,else_directive-instruction_handler
1164
	je	else_found
1171
	je	else_found
1165
	cmp	ax,if_directive-assembler
1172
	cmp	ax,if_directive-instruction_handler
1166
	jne	unexpected_instruction
1173
	jne	unexpected_instruction
1167
	stc
1174
	stc
1168
	ret
1175
	ret
1169
      else_found:
1176
      else_found:
1170
	clc
1177
	clc
1171
	ret
1178
	ret
1172
      find_end_if:
1179
      find_end_if:
1173
	call	find_structure_end
1180
	call	find_structure_end
1174
	cmp	ax,if_directive-assembler
1181
	cmp	ax,if_directive-instruction_handler
1175
	jne	unexpected_instruction
1182
	jne	unexpected_instruction
1176
	ret
1183
	ret
1177
      find_structure_end:
1184
      find_structure_end:
1178
	push	[error_line]
1185
	push	[error_line]
1179
	mov	eax,[current_line]
1186
	mov	eax,[current_line]
1180
	mov	[error_line],eax
1187
	mov	[error_line],eax
Line 1193... Line 1200...
1193
      labels_ok:
1200
      labels_ok:
1194
	cmp	byte [esi],1
1201
	cmp	byte [esi],1
1195
	jne	find_end_directive
1202
	jne	find_end_directive
1196
	mov	ax,[esi+1]
1203
	mov	ax,[esi+1]
1197
	cmp	ax,prefix_instruction-assembler
1204
	cmp	ax,prefix_instruction-instruction_handler
1198
	je	find_end_directive
1205
	je	find_end_directive
1199
	add	esi,4
1206
	add	esi,4
1200
	cmp	ax,repeat_directive-assembler
1207
	cmp	ax,repeat_directive-instruction_handler
1201
	je	skip_repeat
1208
	je	skip_repeat
1202
	cmp	ax,while_directive-assembler
1209
	cmp	ax,while_directive-instruction_handler
1203
	je	skip_while
1210
	je	skip_while
1204
	cmp	ax,if_directive-assembler
1211
	cmp	ax,if_directive-instruction_handler
1205
	je	skip_if
1212
	je	skip_if
1206
	cmp	ax,else_directive-assembler
1213
	cmp	ax,else_directive-instruction_handler
1207
	je	structure_end
1214
	je	structure_end
1208
	cmp	ax,end_directive-assembler
1215
	cmp	ax,end_directive-instruction_handler
1209
	jne	find_end_directive
1216
	jne	find_end_directive
1210
	cmp	byte [esi],1
1217
	cmp	byte [esi],1
1211
	jne	find_end_directive
1218
	jne	find_end_directive
1212
	mov	ax,[esi+1]
1219
	mov	ax,[esi+1]
1213
	add	esi,4
1220
	add	esi,4
1214
	cmp	ax,repeat_directive-assembler
1221
	cmp	ax,repeat_directive-instruction_handler
1215
	je	structure_end
1222
	je	structure_end
1216
	cmp	ax,while_directive-assembler
1223
	cmp	ax,while_directive-instruction_handler
1217
	je	structure_end
1224
	je	structure_end
1218
	cmp	ax,if_directive-assembler
1225
	cmp	ax,if_directive-instruction_handler
1219
	jne	find_end_directive
1226
	jne	find_end_directive
1220
      structure_end:
1227
      structure_end:
1221
	pop	[error_line]
1228
	pop	[error_line]
1222
	ret
1229
	ret
1223
      no_end_directive:
1230
      no_end_directive:
1224
	mov	eax,[error_line]
1231
	mov	eax,[error_line]
Line 1237... Line 1244...
1237
	call	find_else
1244
	call	find_else
1238
	jc	if_block_skipped
1245
	jc	if_block_skipped
1239
	cmp	byte [esi],1
1246
	cmp	byte [esi],1
1240
	jne	skip_after_else
1247
	jne	skip_after_else
1241
	cmp	word [esi+1],if_directive-assembler
1248
	cmp	word [esi+1],if_directive-instruction_handler
1242
	jne	skip_after_else
1249
	jne	skip_after_else
1243
	add	esi,4
1250
	add	esi,4
1244
	jmp	skip_if_block
1251
	jmp	skip_if_block
1245
      skip_after_else:
1252
      skip_after_else:
1246
	call	find_end_if
1253
	call	find_end_if
1247
      if_block_skipped:
1254
      if_block_skipped:
Line 1251... Line 1258...
1251
	cmp	al,1
1258
	cmp	al,1
1252
	jne	invalid_argument
1259
	jne	invalid_argument
1253
	lods	word [esi]
1260
	lods	word [esi]
1254
	inc	esi
1261
	inc	esi
1255
	cmp	ax,virtual_directive-assembler
1262
	cmp	ax,virtual_directive-instruction_handler
1256
	je	end_virtual
1263
	je	end_virtual
1257
	cmp	ax,repeat_directive-assembler
1264
	cmp	ax,repeat_directive-instruction_handler
1258
	je	end_repeat
1265
	je	end_repeat
1259
	cmp	ax,while_directive-assembler
1266
	cmp	ax,while_directive-instruction_handler
1260
	je	end_while
1267
	je	end_while
1261
	cmp	ax,if_directive-assembler
1268
	cmp	ax,if_directive-instruction_handler
1262
	je	end_if
1269
	je	end_if
1263
	cmp	ax,data_directive-assembler
1270
	cmp	ax,data_directive-instruction_handler
1264
	je	end_data
1271
	je	end_data
1265
	jmp	invalid_argument
1272
	jmp	invalid_argument
1266
break_directive:
1273
break_directive:
1267
	mov	ebx,[structures_buffer]
1274
	mov	ebx,[structures_buffer]
1268
	mov	al,[esi]
1275
	mov	al,[esi]
1269
	or	al,al
1276
	or	al,al
Line 1273... Line 1280...
1273
      find_breakable_structure:
1280
      find_breakable_structure:
1274
	cmp	ebx,[additional_memory_end]
1281
	cmp	ebx,[additional_memory_end]
1275
	je	unexpected_instruction
1282
	je	unexpected_instruction
1276
	mov	ax,[ebx]
1283
	mov	ax,[ebx]
1277
	cmp	ax,repeat_directive-assembler
1284
	cmp	ax,repeat_directive-instruction_handler
1278
	je	break_repeat
1285
	je	break_repeat
1279
	cmp	ax,while_directive-assembler
1286
	cmp	ax,while_directive-instruction_handler
1280
	je	break_while
1287
	je	break_while
1281
	cmp	ax,if_directive-assembler
1288
	cmp	ax,if_directive-instruction_handler
1282
	je	break_if
1289
	je	break_if
1283
	add	ebx,20h
1290
	add	ebx,20h
1284
	jmp	find_breakable_structure
1291
	jmp	find_breakable_structure
1285
      break_if:
1292
      break_if:
1286
	push	[current_line]
1293
	push	[current_line]
1287
	mov	eax,[ebx+4]
1294
	mov	eax,[ebx+4]
Line 1686... Line 1693...
1686
	call	get_dword_value
1693
	call	get_dword_value
1687
	pop	ebx
1694
	pop	ebx
1688
	mov	edx,eax
1695
	mov	edx,eax
1689
	sub	[esp],edx
1696
	sub	[esp],edx
1690
      position_ok:
1697
	jc	value_out_of_range
-
 
1698
      position_ok:
1691
	cmp	byte [esi],','
1699
	cmp	byte [esi],','
1692
	jne	size_ok
1700
	jne	size_ok
1693
	inc	esi
1701
	inc	esi
1694
	cmp	byte [esi],'('
1702
	cmp	byte [esi],'('
1695
	jne	invalid_argument
1703
	jne	invalid_argument
Line 1698... Line 1706...
1698
	je	invalid_value
1706
	je	invalid_value
1699
	push	ebx edx
1707
	push	ebx edx
1700
	call	get_dword_value
1708
	call	get_dword_value
1701
	pop	edx ebx
1709
	pop	edx ebx
1702
	mov	[esp],eax
1710
	cmp	eax,[esp]
-
 
1711
	ja	value_out_of_range
-
 
1712
	mov	[esp],eax
1703
      size_ok:
1713
      size_ok:
1704
	xor	al,al
1714
	xor	al,al
1705
	call	lseek
1715
	call	lseek
1706
	pop	ecx
1716
	pop	ecx
1707
	mov	edx,edi
1717
	mov	edx,edi