NONE = 0,
} CMDTYPE;
+extern int cmdcodesize;
+
/* 命令コードの配列 */
typedef struct {
char *cmd;
CMDCODEARRAY *cca;
} CMDCODETAB;
+extern CMDCODETAB *cmdtype_code[];
+extern CMDCODETAB *code_type[];
+
/* 命令と命令タイプがキーのハッシュ表を作成する */
bool create_cmdtype_code();
return 0xFFFF;
}
-/* 命令と命令タイプがキーのハッシュ表を表示する */
-void print_cmdtype_code()
-{
- int i;
- CMDCODETAB *np;
- for(i = 0; i < cmdcodesize; i++){
- np = cmdtype_code[i];
- while(np != NULL) {
- fprintf(stdout, "(%2d) - %s\t0%02o\t#%04X\n",
- i, np->cca->cmd, np->cca->type, np->cca->code);
- np = np->next;
- }
- }
-}
-
/* 命令と命令タイプがキーのハッシュ表を解放する */
void free_cmdtype_code()
{
return NONE;
}
-/* 命令コードがキーのハッシュ表を表示する */
-void print_code_type()
-{
- int i;
- CMDCODETAB *np;
- for(i = 0; i < cmdcodesize; i++){
- for(np = code_type[i]; np != NULL; np = np->next) {
- fprintf(stdout, "(%2d) - #%04X\t0%02o\t%s\n",
- i, np->cca->code, np->cca->type, np->cca->cmd);
- }
- }
-}
-
/* 命令コードがキーのハッシュ表を解放する */
void free_code_type()
{
-== CMDTYPE_CODE TABLE ==
-( 0) - SVC 030 #F000
-( 1) - JZE 030 #6300
-( 1) - SLL 010 #5200
-( 2) - SLA 010 #5000
-( 3) - ADDL 011 #2200
-( 3) - NOP 000 #0000
-( 4) - ADDA 011 #2000
-( 7) - OR 020 #3500
-(10) - CALL 030 #8000
-(11) - ADDL 020 #2600
-(12) - ADDA 020 #2400
-(13) - RET 000 #8100
-(14) - SUBL 011 #2300
-(15) - SUBA 011 #2100
-(19) - LAD 010 #1200
-(20) - JMI 030 #6100
-(21) - AND 011 #3000
-(22) - JUMP 030 #6400
-(22) - SUBL 020 #2700
-(23) - CPL 011 #4100
-(23) - SUBA 020 #2500
-(24) - CPA 011 #4000
-(25) - XOR 011 #3200
-(26) - JNZ 030 #6200
-(26) - LD 011 #1000
-(27) - JOV 030 #6600
-(29) - SRL 010 #5300
-(29) - AND 020 #3400
-(29) - ST 010 #1100
-(30) - SRA 010 #5100
-(31) - CPL 020 #4500
-(32) - JPL 030 #6500
-(32) - CPA 020 #4400
-(33) - POP 040 #7100
-(33) - XOR 020 #3600
-(34) - PUSH 030 #7000
-(34) - LD 020 #1400
-(37) - OR 011 #3100
+NOP 000 #0000
+LD 011 #1000
+ST 010 #1100
+LAD 010 #1200
+LD 020 #1400
+ADDA 011 #2000
+SUBA 011 #2100
+ADDL 011 #2200
+SUBL 011 #2300
+ADDA 020 #2400
+SUBA 020 #2500
+ADDL 020 #2600
+SUBL 020 #2700
+AND 011 #3000
+OR 011 #3100
+XOR 011 #3200
+AND 020 #3400
+OR 020 #3500
+XOR 020 #3600
+CPA 011 #4000
+CPL 011 #4100
+CPA 020 #4400
+CPL 020 #4500
+SLA 010 #5000
+SRA 010 #5100
+SLL 010 #5200
+SRL 010 #5300
+JMI 030 #6100
+JNZ 030 #6200
+JZE 030 #6300
+JUMP 030 #6400
+JPL 030 #6500
+JOV 030 #6600
+PUSH 030 #7000
+POP 040 #7100
+CALL 030 #8000
+RET 000 #8100
+SVC 030 #F000
#include "casl2.h"
-int main(){
- puts("== CMDTYPE_CODE TABLE ==");
+#include "cerr.h"
+#include <string.h>
+
+int compare_code(const void *a, const void *b)
+{
+ const CMDCODEARRAY ca = **(const CMDCODEARRAY **)a;
+ const CMDCODEARRAY cb = **(const CMDCODEARRAY **)b;
+ int diff;
+ if((diff = strcmp(ca.cmd, cb.cmd)) == 0) {
+ return ca.type - cb.type;
+ } else {
+ return diff;
+ }
+}
+
+/* 命令と命令タイプがキーのハッシュ表を表示する */
+void print_cmdtype_code()
+{
+ int i, j = 0;
+ CMDCODETAB *np;
+ CMDCODEARRAY **ar;
+ ar = malloc(sizeof(*ar) * cmdcodesize);
+ for(i = 0; i < cmdcodesize; i++) {
+ np = cmdtype_code[i];
+ while(np != NULL) {
+ ar[j++] = np->cca;
+ np = np->next;
+ }
+ }
+ qsort(ar, cmdcodesize, sizeof(*ar), (int (*)(const void*, const void*))compare_code);
+ for(i = 0; i < cmdcodesize; i++) {
+ fprintf(stdout, "%s\t0%02o\t#%04X\n", ar[i]->cmd, ar[i]->type, ar[i]->code);
+ }
+}
+
+int main()
+{
create_cmdtype_code();
print_cmdtype_code();
free_cmdtype_code();
--- /dev/null
+( 0) - SVC 030 #F000
+( 1) - JZE 030 #6300
+( 1) - SLL 010 #5200
+( 2) - SLA 010 #5000
+( 3) - ADDL 011 #2200
+( 3) - NOP 000 #0000
+( 4) - ADDA 011 #2000
+( 7) - OR 020 #3500
+(10) - CALL 030 #8000
+(11) - ADDL 020 #2600
+(12) - ADDA 020 #2400
+(13) - RET 000 #8100
+(14) - SUBL 011 #2300
+(15) - SUBA 011 #2100
+(19) - LAD 010 #1200
+(20) - JMI 030 #6100
+(21) - AND 011 #3000
+(22) - JUMP 030 #6400
+(22) - SUBL 020 #2700
+(23) - CPL 011 #4100
+(23) - SUBA 020 #2500
+(24) - CPA 011 #4000
+(25) - XOR 011 #3200
+(26) - JNZ 030 #6200
+(26) - LD 011 #1000
+(27) - JOV 030 #6600
+(29) - SRL 010 #5300
+(29) - AND 020 #3400
+(29) - ST 010 #1100
+(30) - SRA 010 #5100
+(31) - CPL 020 #4500
+(32) - JPL 030 #6500
+(32) - CPA 020 #4400
+(33) - POP 040 #7100
+(33) - XOR 020 #3600
+(34) - PUSH 030 #7000
+(34) - LD 020 #1400
+(37) - OR 011 #3100
--- /dev/null
+UCLASS = COMMON
+TESTSRCFILE = ../CERRARRAY.c print_cmdtype_code.c
+include ../TEST.mk
--- /dev/null
+#include "casl2.h"
+
+/* 命令と命令タイプがキーのハッシュ表を表示する */
+void print_cmdtype_code()
+{
+ int i;
+ CMDCODETAB *np;
+ for(i = 0; i < cmdcodesize; i++){
+ np = cmdtype_code[i];
+ while(np != NULL) {
+ fprintf(stdout, "(%2d) - %s\t0%02o\t#%04X\n",
+ i, np->cca->cmd, np->cca->type, np->cca->code);
+ np = np->next;
+ }
+ }
+}
+
+int main(){
+ create_cmdtype_code();
+ print_cmdtype_code();
+ free_cmdtype_code();
+ if(cerrno != 0) {
+ printf("\terror - %d: %s\n", cerrno, cerrmsg);
+ freecerr();
+ exit(-1);
+ }
+ return 0;
+}
-== CODE_TYPE TABLE ==
-( 0) - #2600 020 ADDL
-( 0) - #0000 000 NOP
-( 1) - #2700 020 SUBL
-( 4) - #5000 010 SLA
-( 5) - #5100 010 SRA
-( 6) - #5200 010 SLL
-( 7) - #5300 010 SRL
-(10) - #3000 011 AND
-(11) - #3100 011 OR
-(12) - #F000 030 SVC
-(12) - #3200 011 XOR
-(14) - #8000 030 CALL
-(14) - #3400 020 AND
-(15) - #8100 000 RET
-(15) - #3500 020 OR
-(16) - #3600 020 XOR
-(16) - #1000 011 LD
-(17) - #1100 010 ST
-(18) - #1200 010 LAD
-(20) - #1400 020 LD
-(21) - #6100 030 JMI
-(22) - #6200 030 JNZ
-(23) - #6300 030 JZE
-(24) - #6400 030 JUMP
-(25) - #6500 030 JPL
-(26) - #6600 030 JOV
-(26) - #4000 011 CPA
-(27) - #4100 011 CPL
-(30) - #4400 020 CPA
-(31) - #4500 020 CPL
-(32) - #2000 011 ADDA
-(33) - #2100 011 SUBA
-(34) - #2200 011 ADDL
-(35) - #2300 011 SUBL
-(36) - #7000 030 PUSH
-(36) - #2400 020 ADDA
-(37) - #7100 040 POP
-(37) - #2500 020 SUBA
+#0000 000 NOP
+#1000 011 LD
+#1100 010 ST
+#1200 010 LAD
+#1400 020 LD
+#2000 011 ADDA
+#2100 011 SUBA
+#2200 011 ADDL
+#2300 011 SUBL
+#2400 020 ADDA
+#2500 020 SUBA
+#2600 020 ADDL
+#2700 020 SUBL
+#3000 011 AND
+#3100 011 OR
+#3200 011 XOR
+#3400 020 AND
+#3500 020 OR
+#3600 020 XOR
+#4000 011 CPA
+#4100 011 CPL
+#4400 020 CPA
+#4500 020 CPL
+#5000 010 SLA
+#5100 010 SRA
+#5200 010 SLL
+#5300 010 SRL
+#6100 030 JMI
+#6200 030 JNZ
+#6300 030 JZE
+#6400 030 JUMP
+#6500 030 JPL
+#6600 030 JOV
+#7000 030 PUSH
+#7100 040 POP
+#8000 030 CALL
+#8100 000 RET
+#F000 030 SVC
#include "casl2.h"
#include "cerr.h"
+int compare_code(const void *a, const void *b)
+{
+ return (**(const CMDCODEARRAY **)a).code - (**(const CMDCODEARRAY **)b).code;
+}
+
+/* 命令コードがキーのハッシュ表を表示する */
+void print_code_type()
+{
+ int i, j = 0;
+ CMDCODETAB *np;
+ CMDCODEARRAY **ar;
+ ar = malloc(sizeof(*ar) * cmdcodesize);
+ for(i = 0; i < cmdcodesize; i++) {
+ np = code_type[i];
+ while(np != NULL) {
+ ar[j++] = np->cca;
+ np = np->next;
+ }
+ }
+ qsort(ar, cmdcodesize, sizeof(*ar), (int (*)(const void*, const void*))compare_code);
+ for(i = 0; i < cmdcodesize; i++) {
+ fprintf(stdout, "#%04X\t0%02o\t%s\n", ar[i]->code, ar[i]->type, ar[i]->cmd);
+ }
+}
+
int main()
{
- puts("== CODE_TYPE TABLE ==");
create_code_type();
print_code_type();
free_code_type();
--- /dev/null
+( 0) - #2600 020 ADDL
+( 0) - #0000 000 NOP
+( 1) - #2700 020 SUBL
+( 4) - #5000 010 SLA
+( 5) - #5100 010 SRA
+( 6) - #5200 010 SLL
+( 7) - #5300 010 SRL
+(10) - #3000 011 AND
+(11) - #3100 011 OR
+(12) - #F000 030 SVC
+(12) - #3200 011 XOR
+(14) - #8000 030 CALL
+(14) - #3400 020 AND
+(15) - #8100 000 RET
+(15) - #3500 020 OR
+(16) - #3600 020 XOR
+(16) - #1000 011 LD
+(17) - #1100 010 ST
+(18) - #1200 010 LAD
+(20) - #1400 020 LD
+(21) - #6100 030 JMI
+(22) - #6200 030 JNZ
+(23) - #6300 030 JZE
+(24) - #6400 030 JUMP
+(25) - #6500 030 JPL
+(26) - #6600 030 JOV
+(26) - #4000 011 CPA
+(27) - #4100 011 CPL
+(30) - #4400 020 CPA
+(31) - #4500 020 CPL
+(32) - #2000 011 ADDA
+(33) - #2100 011 SUBA
+(34) - #2200 011 ADDL
+(35) - #2300 011 SUBL
+(36) - #7000 030 PUSH
+(36) - #2400 020 ADDA
+(37) - #7100 040 POP
+(37) - #2500 020 SUBA
--- /dev/null
+UCLASS = COMMON
+TESTSRCFILE = ../CERRARRAY.c print_code_type.c
+include ../TEST.mk
--- /dev/null
+#include "casl2.h"
+#include "cerr.h"
+
+/* 命令コードがキーのハッシュ表を表示する */
+void print_code_type()
+{
+ int i;
+ CMDCODETAB *np;
+ for(i = 0; i < cmdcodesize; i++){
+ for(np = code_type[i]; np != NULL; np = np->next) {
+ fprintf(stdout, "(%2d) - #%04X\t0%02o\t%s\n", i, np->cca->code, np->cca->type, np->cca->cmd);
+ }
+ }
+}
+
+int main()
+{
+ create_code_type();
+ print_code_type();
+ free_code_type();
+ if(cerrno != 0) {
+ printf("\terror - %d: %s\n", cerrno, cerrmsg);
+ freecerr();
+ exit(-1);
+ }
+ return 0;
+}