Changeset 31 for branches/UltimatOS/UInstructionWriter.pas
- Timestamp:
- Jul 6, 2022, 1:05:27 AM (23 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/UltimatOS/UInstructionWriter.pas
r29 r31 8 8 type 9 9 TInstructionParam = (ipNone, ipRegIndex, ipAddress, ipData, ipIndex, 10 ipRegIndexRel );10 ipRegIndexRel, ipAddressRel); 11 11 12 12 TInstructionDef = class … … 72 72 procedure WriteReg(Index: Byte); 73 73 procedure WriteByte(Value: Byte); 74 procedure WriteWord(Value: Word); 75 procedure WriteCardinal(Value: Cardinal); 74 76 constructor Create; 75 77 destructor Destroy; override; … … 190 192 end; 191 193 end; 194 end; 195 ipAddressRel: begin 196 Address := Trim(ParseText(Text, ',')); 197 if Address.StartsWith('(') and Address.EndsWith(')') then begin 198 Address := Copy(Address, 2, Length(Address) - 2); 199 if TryStrToInt(Address, Value) then begin 200 WriteAddress(Value); 201 end else begin 202 FoundConstant := Constants.SearchByName(UpperCase(Address)); 203 if Assigned(FoundConstant) then begin 204 WriteAddress(FoundConstant.Value); 205 Exit; 206 end; 207 FoundLabel := Labels.SearchByName(UpperCase(Address)); 208 if Assigned(FoundLabel) then begin 209 // Existing label 210 WriteAddress(FoundLabel.Address); 211 end else begin 212 // Forward label reference 213 with Labels.AddNew(UpperCase(Address), -1) do begin 214 SetLength(ForwardRefs, Length(ForwardRefs) + 1); 215 ForwardRefs[Length(ForwardRefs) - 1] := IP; 216 end; 217 WriteAddress(0); 218 end; 219 end; 220 end else Error('Expected indirect address ' + Address); 192 221 end; 193 222 ipRegIndex: begin … … 333 362 end else WriteByte(StrToInt(Param)); 334 363 end; 364 end else 365 if InstructionName = 'dw' then begin 366 while Text <> '' do begin 367 Param := ParseText(Text, ','); 368 if Param.StartsWith('"') and Param.EndsWith('"') then begin 369 Param := Copy(Param, 2, Length(Param) - 2); 370 for I := 1 to Length(Param) do 371 WriteWord(Ord(Param[I])); 372 end else WriteWord(StrToInt(Param)); 373 end; 374 end else 375 if InstructionName = 'dd' then begin 376 while Text <> '' do begin 377 Param := ParseText(Text, ','); 378 if Param.StartsWith('"') and Param.EndsWith('"') then begin 379 Param := Copy(Param, 2, Length(Param) - 2); 380 for I := 1 to Length(Param) do 381 WriteCardinal(Ord(Param[I])); 382 end else WriteCardinal(StrToInt(Param)); 383 end; 335 384 end else Error('Unsupported directive name ' + InstructionName); 336 385 end else begin … … 383 432 end; 384 433 434 procedure TInstructionWriter.WriteWord(Value: Word); 435 begin 436 PWord(@Memory.Data[IP])^ := Value; 437 Inc(IP, SizeOf(Word)); 438 end; 439 440 procedure TInstructionWriter.WriteCardinal(Value: Cardinal); 441 begin 442 PCardinal(@Memory.Data[IP])^ := Value; 443 Inc(IP, SizeOf(Cardinal)); 444 end; 445 385 446 constructor TInstructionWriter.Create; 386 447 begin … … 392 453 AddNew(inHalt, 'HALT'); 393 454 AddNew(inSet, 'SET', ipRegIndex, ipData); 394 AddNew(inInput, 'IN', ipRegIndex, ipAddress );395 AddNew(inOutput, 'OUT', ipAddress , ipRegIndex);455 AddNew(inInput, 'IN', ipRegIndex, ipAddressRel); 456 AddNew(inOutput, 'OUT', ipAddressRel, ipRegIndex); 396 457 AddNew(inInc, 'INC', ipRegIndex); 397 458 AddNew(inDec, 'DEC', ipRegIndex); … … 409 470 AddNew(inShr, 'SHR', ipRegIndex, ipIndex); 410 471 AddNew(inLoad, 'LD', ipRegIndex, ipRegIndexRel); 472 AddNew(inLoadi, 'LDI', ipRegIndex, ipAddressRel); 411 473 AddNew(inStore, 'ST', ipRegIndexRel, ipRegIndex); 412 474 AddNew(inMul, 'MUL', ipRegIndex, ipRegIndex); 413 475 AddNew(inAnd, 'AND', ipRegIndex, ipRegIndex); 476 AddNew(inAndi, 'ANDI', ipRegIndex, ipData); 414 477 AddNew(inOr, 'OR', ipRegIndex, ipRegIndex); 415 478 AddNew(inXor, 'XOR', ipRegIndex, ipRegIndex);
Note:
See TracChangeset
for help on using the changeset viewer.