Mercurial > hg > Members > kono > os9 > sbc09
comparison a09.c @ 29:3c14d647bb51
assembler and emulator fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 11 Jul 2018 21:16:06 +0900 |
parents | 51a35f0347f6 |
children | 7c5379eb406e |
comparison
equal
deleted
inserted
replaced
28:d34482fd6945 | 29:3c14d647bb51 |
---|---|
41 New: debugging parameter/option. | 41 New: debugging parameter/option. |
42 Fixed additional possible issue PC relative addressing. | 42 Fixed additional possible issue PC relative addressing. |
43 Compatibility: Octal number prefix "&". | 43 Compatibility: Octal number prefix "&". |
44 2014-07-15 j at klasek at | 44 2014-07-15 j at klasek at |
45 Fixed usage message. | 45 Fixed usage message. |
46 2018-07-11 | |
47 leax $ED00/256,x kernel offset in map | |
48 should be positive offset expr should be int(32bit) | |
46 */ | 49 */ |
47 | 50 |
48 #include <stdlib.h> | 51 #include <stdlib.h> |
49 #include <stdio.h> | 52 #include <stdio.h> |
50 #include <string.h> | 53 #include <string.h> |
352 c=*srcptr++; | 355 c=*srcptr++; |
353 } while(c==' '||c=='\t'); | 356 } while(c==' '||c=='\t'); |
354 srcptr--; | 357 srcptr--; |
355 } | 358 } |
356 | 359 |
357 short scanexpr(int); | 360 int scanexpr(int); |
358 | 361 |
359 short scandecimal() | 362 int scandecimal() |
360 { | 363 { |
361 char c; | 364 char c; |
362 short t=0; | 365 int t=0; |
363 c=*srcptr++; | 366 c=*srcptr++; |
364 while(isdigit(c)) { | 367 while(isdigit(c)) { |
365 t=t*10+c-'0'; | 368 t=t*10+c-'0'; |
366 c=*srcptr++; | 369 c=*srcptr++; |
367 } | 370 } |
368 srcptr--; | 371 srcptr--; |
369 return t; | 372 return t; |
370 } | 373 } |
371 | 374 |
372 short scanhex() | 375 int scanhex() |
373 { | 376 { |
374 short t=0,i=0; | 377 int t=0,i=0; |
375 srcptr++; | 378 srcptr++; |
376 scanname(); | 379 scanname(); |
377 while(namebuf[i]>='0'&&namebuf[i]<='F') { | 380 while(namebuf[i]>='0'&&namebuf[i]<='F') { |
378 t=t*16+namebuf[i]-'0'; | 381 t=t*16+namebuf[i]-'0'; |
379 if(namebuf[i]>'9')t-=7; | 382 if(namebuf[i]>'9')t-=7; |
381 } | 384 } |
382 if(i==0)error|=1; | 385 if(i==0)error|=1; |
383 return t; | 386 return t; |
384 } | 387 } |
385 | 388 |
386 short scanchar() | 389 int scanchar() |
387 { | 390 { |
388 short t; | 391 int t; |
389 srcptr++; | 392 srcptr++; |
390 t=*srcptr; | 393 t=*srcptr; |
391 if(t)srcptr++; | 394 if(t)srcptr++; |
392 if (*srcptr=='\'')srcptr++; | 395 if (*srcptr=='\'')srcptr++; |
393 return t; | 396 return t; |
394 } | 397 } |
395 | 398 |
396 short scanbin() | 399 int scanbin() |
397 { | 400 { |
398 char c; | 401 char c; |
399 short t=0; | 402 int t=0; |
400 srcptr++; | 403 srcptr++; |
401 c=*srcptr++; | 404 c=*srcptr++; |
402 while(c=='0'||c=='1') { | 405 while(c=='0'||c=='1') { |
403 t=t*2+c-'0'; | 406 t=t*2+c-'0'; |
404 c=*srcptr++; | 407 c=*srcptr++; |
405 } | 408 } |
406 srcptr--; | 409 srcptr--; |
407 return t; | 410 return t; |
408 } | 411 } |
409 | 412 |
410 short scanoct() | 413 int scanoct() |
411 { | 414 { |
412 char c; | 415 char c; |
413 short t=0; | 416 int t=0; |
414 srcptr++; | 417 srcptr++; |
415 c=*srcptr++; | 418 c=*srcptr++; |
416 while(c>='0'&&c<='7') { | 419 while(c>='0'&&c<='7') { |
417 t=t*8+c-'0'; | 420 t=t*8+c-'0'; |
418 c=*srcptr++; | 421 c=*srcptr++; |
420 srcptr--; | 423 srcptr--; |
421 return t; | 424 return t; |
422 } | 425 } |
423 | 426 |
424 | 427 |
425 short scanlabel() | 428 int scanlabel() |
426 { | 429 { |
427 struct symrecord * p; | 430 struct symrecord * p; |
428 scanname(); | 431 scanname(); |
429 p=findsym(namebuf); | 432 p=findsym(namebuf); |
430 if(p->cat==13) { | 433 if(p->cat==13) { |
441 if(exprcat==8||exprcat==6||exprcat==10)exprcat=2; | 444 if(exprcat==8||exprcat==6||exprcat==10)exprcat=2; |
442 return p->value; | 445 return p->value; |
443 } | 446 } |
444 | 447 |
445 | 448 |
446 short scanfactor() | 449 int scanfactor() |
447 { | 450 { |
448 char c; | 451 char c; |
449 short t; | 452 int t; |
450 skipspace(); | 453 skipspace(); |
451 c=*srcptr; | 454 c=*srcptr; |
452 if(isalpha(c))return scanlabel(); | 455 if(isalpha(c))return scanlabel(); |
453 else if(isdigit(c))return scandecimal(); | 456 else if(isdigit(c))return scandecimal(); |
454 else switch(c) { | 457 else switch(c) { |
482 exprcat|=oldcat;\ | 485 exprcat|=oldcat;\ |
483 /* resolve such cases as constant added to address or difference between | 486 /* resolve such cases as constant added to address or difference between |
484 two addresses in same module */ | 487 two addresses in same module */ |
485 | 488 |
486 | 489 |
487 short scanexpr(int level) /* This is what you call _recursive_ descent!!!*/ | 490 int scanexpr(int level) /* This is what you call _recursive_ descent!!!*/ |
488 { | 491 { |
489 short t,u; | 492 int t,u; |
490 char oldcat,c; | 493 char oldcat,c; |
491 exprcat=0; | 494 exprcat=0; |
492 if(level==10)return scanfactor(); | 495 if(level==10)return scanfactor(); |
493 t=scanexpr(level+1); | 496 t=scanexpr(level+1); |
494 while(1) { | 497 while(1) { |