Changeset 2081 for rtcg/trunk/src/print.c
- Timestamp:
- 01/19/10 14:59:03 (2 years ago)
- Files:
-
- 1 modified
-
rtcg/trunk/src/print.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
rtcg/trunk/src/print.c
r2079 r2081 1 1 #include "asm.h" 2 2 3 char* regs[]={"eax", "ecx", "edx", "ebx"}; 3 #define _GNU_SOURCE 4 #include <stdio.h> 5 #include <stdlib.h> 4 6 5 void AsmPrintCode(char* out, int length) 7 #include <x86/modrm.h> 8 9 char* regs[]={"eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi"}; 10 11 void AsmPrintCode(char* code, int length, FILE* outBuffer, int outLength) 6 12 { 7 13 int i=0; 8 unsigned char* ins=(unsigned char*) out;14 unsigned char* ins=(unsigned char*)code; 9 15 10 printf("optimizedCode:\n"); 11 12 while (ins < out+length) 16 while (ins < (unsigned char*)code+length) 13 17 { 18 printf("\t"); 19 14 20 switch (*ins) 15 21 { … … 22 28 unsigned char mod, reg, rm; 23 29 AsmModRm(ins[1], &mod, ®, &rm); 24 printf(" \txor\t%s, %s\n", regs[reg], regs[rm]);30 printf("xor\t%s, %s\n", regs[reg], regs[rm]); 25 31 ins+=2; 26 32 break; … … 28 34 29 35 case INSTR_TEST: 30 printf(" \ttest ecx, ecx\n");36 printf("test ecx, ecx\n"); 31 37 ins+=2; 32 38 break; … … 35 41 { 36 42 char regs[]="acdb"; 37 printf(" \tmov\te%cx, %#x\n", regs[*ins-0xB8], *(unsigned long*)&ins[1]);43 printf("mov\te%cx, %#lx\n", regs[*ins-0xB8], *(unsigned long*)&ins[1]); 38 44 ins+=5; 39 45 break; … … 42 48 case INSTR_PUSH_START ... INSTR_PUSH_STOP: 43 49 { 44 printf(" \tpush\t%s\n", regs[*ins-INSTR_PUSH_START]);50 printf("push\t%s\n", regs[*ins-INSTR_PUSH_START]); 45 51 ins+=1; 52 break; 53 } 54 55 case INSTR_SUB: 56 { 57 unsigned char mod, reg, rm; 58 AsmModRm(ins[1], &mod, ®, &rm); 59 60 switch (mod) 61 { 62 case MOD_REG: 63 printf("sub [%s], %#X", regs[rm], ins[3]); 64 break; 65 66 default: 67 printf("INSTR_SUB: TODO\n"); 68 exit(0); 69 } 70 71 ins += 4; 46 72 break; 47 73 } … … 49 75 case INSTR_POP_START ... INSTR_POP_STOP: 50 76 { 51 char* regs[]={"eax", "ecx", "edx", "ebx"}; 52 printf("\tpop\t%s\n", regs[*ins-INSTR_POP_START]); 77 printf("pop\t%s", regs[*ins-INSTR_POP_START]); 53 78 ins+=1; 54 79 break; … … 56 81 57 82 case INSTR_RET: 58 printf(" \tret\n");83 printf("ret"); 59 84 ins++; 60 85 break; … … 64 89 ins++; 65 90 } 91 92 printf("\n"); 66 93 } 67 94 }
