- Code: Select all
extern void f0(void);
extern void f1(void);
extern void f2(void);
extern void f3(void);
extern void f4(void);
extern void f5(void);
extern void f6(void);
extern void f7(void);
extern void f8(void);
extern void f9(void);
extern void f10(void);
extern void f11(void);
extern void f12(void);
extern void f13(void);
extern void f14(void);
extern void f15(void);
extern void f16(void);
extern void f17(void);
extern void f18(void);
extern void f19(void);
extern void f20(void);
extern void f21(void);
extern void f22(void);
extern void f23(void);
extern void f24(void);
extern void f25(void);
extern void f26(void);
extern void f27(void);
extern void f28(void);
extern void f29(void);
extern void f30(void);
extern void f31(void);
extern void f32(void);
extern void f33(void);
extern void f34(void);
extern void f35(void);
extern void f36(void);
extern void f37(void);
extern void f38(void);
extern void f39(void);
extern void f40(void);
extern void f41(void);
extern void f42(void);
extern void f43(void);
extern void f44(void);
extern void f45(void);
extern void f46(void);
extern void f47(void);
extern void f48(void);
extern void f49(void);
extern void f50(void);
extern void f51(void);
extern void f52(void);
extern void f53(void);
extern void f54(void);
extern void f55(void);
extern void f56(void);
extern void f57(void);
extern void f58(void);
extern void f59(void);
extern void f60(void);
extern void f61(void);
extern void f62(void);
extern void f63(void);
extern void f64(void);
extern void f65(void);
extern void f66(void);
extern void f67(void);
extern void f68(void);
extern void f69(void);
extern void f70(void);
extern void f71(void);
extern void f72(void);
extern void f73(void);
extern void f74(void);
extern void f75(void);
extern void f76(void);
extern void f77(void);
extern void f78(void);
extern void f79(void);
extern void f80(void);
extern void f81(void);
extern void f82(void);
extern void f83(void);
extern void f84(void);
extern void f85(void);
extern void f86(void);
extern void f87(void);
extern void f88(void);
extern void f89(void);
extern void f90(void);
extern void f91(void);
extern void f92(void);
extern void f93(void);
extern void f94(void);
extern void f95(void);
extern void f96(void);
extern void f97(void);
extern void f98(void);
extern void f99(void);
void f(unsigned v)
{
switch (v) {
case 0: f0(); break;
case 1: f1(); break;
case 2: f2(); break;
case 3: f3(); break;
case 4: f4(); break;
case 5: f5(); break;
case 6: f6(); break;
case 7: f7(); break;
case 8: f8(); break;
case 9: f9(); break;
case 10: f10(); break;
case 11: f11(); break;
case 12: f12(); break;
case 13: f13(); break;
case 14: f14(); break;
case 15: f15(); break;
case 16: f16(); break;
case 17: f17(); break;
case 18: f18(); break;
case 19: f19(); break;
case 20: f20(); break;
case 21: f21(); break;
case 22: f22(); break;
case 23: f23(); break;
case 24: f24(); break;
case 25: f25(); break;
case 26: f26(); break;
case 27: f27(); break;
case 28: f28(); break;
case 29: f29(); break;
case 30: f30(); break;
case 31: f31(); break;
case 32: f32(); break;
case 33: f33(); break;
case 34: f34(); break;
case 35: f35(); break;
case 36: f36(); break;
case 37: f37(); break;
case 38: f38(); break;
case 39: f39(); break;
case 40: f40(); break;
case 41: f41(); break;
case 42: f42(); break;
case 43: f43(); break;
case 44: f44(); break;
case 45: f45(); break;
case 46: f46(); break;
case 47: f47(); break;
case 48: f48(); break;
case 49: f49(); break;
case 50: f50(); break;
case 51: f51(); break;
case 52: f52(); break;
case 53: f53(); break;
case 54: f54(); break;
case 55: f55(); break;
case 56: f56(); break;
case 57: f57(); break;
case 58: f58(); break;
case 59: f59(); break;
case 60: f60(); break;
case 61: f61(); break;
case 62: f62(); break;
case 63: f63(); break;
case 64: f64(); break;
case 65: f65(); break;
case 66: f66(); break;
case 67: f67(); break;
case 68: f68(); break;
case 69: f69(); break;
case 70: f70(); break;
case 71: f71(); break;
case 72: f72(); break;
case 73: f73(); break;
case 74: f74(); break;
case 75: f75(); break;
case 76: f76(); break;
case 77: f77(); break;
case 78: f78(); break;
case 79: f79(); break;
case 80: f80(); break;
case 81: f81(); break;
case 82: f82(); break;
case 83: f83(); break;
case 84: f84(); break;
case 85: f85(); break;
case 86: f86(); break;
case 87: f87(); break;
case 88: f88(); break;
case 89: f89(); break;
case 90: f90(); break;
case 91: f91(); break;
case 92: f92(); break;
case 93: f93(); break;
case 94: f94(); break;
case 95: f95(); break;
case 96: f96(); break;
case 97: f97(); break;
case 98: f98(); break;
case 99: f99(); break;
default: return;
}
}
$ arm-none-eabi-gcc -Os -mcpu=cortex-m4 -mthumb -S test.c
Видим switch таки делается через таблицу:
- Code: Select all
.syntax unified
.cpu cortex-m4
.fpu softvfp
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 1
.eabi_attribute 30, 4
.eabi_attribute 18, 4
.thumb
.file "test.c"
.text
.align 1
.global f
.thumb
.thumb_func
.type f, %function
f:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
cmp r0, #99
bhi .L1
tbh [pc, r0, lsl #1]
.L103:
.2byte (.L3-.L103)/2
.2byte (.L4-.L103)/2
.2byte (.L5-.L103)/2
.2byte (.L6-.L103)/2
.2byte (.L7-.L103)/2
.2byte (.L8-.L103)/2
.2byte (.L9-.L103)/2
.2byte (.L10-.L103)/2
.2byte (.L11-.L103)/2
.2byte (.L12-.L103)/2
.2byte (.L13-.L103)/2
.2byte (.L14-.L103)/2
.2byte (.L15-.L103)/2
.2byte (.L16-.L103)/2
.2byte (.L17-.L103)/2
.2byte (.L18-.L103)/2
.2byte (.L19-.L103)/2
.2byte (.L20-.L103)/2
.2byte (.L21-.L103)/2
.2byte (.L22-.L103)/2
.2byte (.L23-.L103)/2
.2byte (.L24-.L103)/2
.2byte (.L25-.L103)/2
.2byte (.L26-.L103)/2
.2byte (.L27-.L103)/2
.2byte (.L28-.L103)/2
.2byte (.L29-.L103)/2
.2byte (.L30-.L103)/2
.2byte (.L31-.L103)/2
.2byte (.L32-.L103)/2
.2byte (.L33-.L103)/2
.2byte (.L34-.L103)/2
.2byte (.L35-.L103)/2
.2byte (.L36-.L103)/2
.2byte (.L37-.L103)/2
.2byte (.L38-.L103)/2
.2byte (.L39-.L103)/2
.2byte (.L40-.L103)/2
.2byte (.L41-.L103)/2
.2byte (.L42-.L103)/2
.2byte (.L43-.L103)/2
.2byte (.L44-.L103)/2
.2byte (.L45-.L103)/2
.2byte (.L46-.L103)/2
.2byte (.L47-.L103)/2
.2byte (.L48-.L103)/2
.2byte (.L49-.L103)/2
.2byte (.L50-.L103)/2
.2byte (.L51-.L103)/2
.2byte (.L52-.L103)/2
.2byte (.L53-.L103)/2
.2byte (.L54-.L103)/2
.2byte (.L55-.L103)/2
.2byte (.L56-.L103)/2
.2byte (.L57-.L103)/2
.2byte (.L58-.L103)/2
.2byte (.L59-.L103)/2
.2byte (.L60-.L103)/2
.2byte (.L61-.L103)/2
.2byte (.L62-.L103)/2
.2byte (.L63-.L103)/2
.2byte (.L64-.L103)/2
.2byte (.L65-.L103)/2
.2byte (.L66-.L103)/2
.2byte (.L67-.L103)/2
.2byte (.L68-.L103)/2
.2byte (.L69-.L103)/2
.2byte (.L70-.L103)/2
.2byte (.L71-.L103)/2
.2byte (.L72-.L103)/2
.2byte (.L73-.L103)/2
.2byte (.L74-.L103)/2
.2byte (.L75-.L103)/2
.2byte (.L76-.L103)/2
.2byte (.L77-.L103)/2
.2byte (.L78-.L103)/2
.2byte (.L79-.L103)/2
.2byte (.L80-.L103)/2
.2byte (.L81-.L103)/2
.2byte (.L82-.L103)/2
.2byte (.L83-.L103)/2
.2byte (.L84-.L103)/2
.2byte (.L85-.L103)/2
.2byte (.L86-.L103)/2
.2byte (.L87-.L103)/2
.2byte (.L88-.L103)/2
.2byte (.L89-.L103)/2
.2byte (.L90-.L103)/2
.2byte (.L91-.L103)/2
.2byte (.L92-.L103)/2
.2byte (.L93-.L103)/2
.2byte (.L94-.L103)/2
.2byte (.L95-.L103)/2
.2byte (.L96-.L103)/2
.2byte (.L97-.L103)/2
.2byte (.L98-.L103)/2
.2byte (.L99-.L103)/2
.2byte (.L100-.L103)/2
.2byte (.L101-.L103)/2
.2byte (.L102-.L103)/2
.L3:
b f0
.L4:
b f1
.L5:
b f2
.L6:
b f3
.L7:
b f4
.L8:
b f5
.L9:
b f6
.L10:
b f7
.L11:
b f8
.L12:
b f9
.L13:
b f10
.L14:
b f11
.L15:
b f12
.L16:
b f13
.L17:
b f14
.L18:
b f15
.L19:
b f16
.L20:
b f17
.L21:
b f18
.L22:
b f19
.L23:
b f20
.L24:
b f21
.L25:
b f22
.L26:
b f23
.L27:
b f24
.L28:
b f25
.L29:
b f26
.L30:
b f27
.L31:
b f28
.L32:
b f29
.L33:
b f30
.L34:
b f31
.L35:
b f32
.L36:
b f33
.L37:
b f34
.L38:
b f35
.L39:
b f36
.L40:
b f37
.L41:
b f38
.L42:
b f39
.L43:
b f40
.L44:
b f41
.L45:
b f42
.L46:
b f43
.L47:
b f44
.L48:
b f45
.L49:
b f46
.L50:
b f47
.L51:
b f48
.L52:
b f49
.L53:
b f50
.L54:
b f51
.L55:
b f52
.L56:
b f53
.L57:
b f54
.L58:
b f55
.L59:
b f56
.L60:
b f57
.L61:
b f58
.L62:
b f59
.L63:
b f60
.L64:
b f61
.L65:
b f62
.L66:
b f63
.L67:
b f64
.L68:
b f65
.L69:
b f66
.L70:
b f67
.L71:
b f68
.L72:
b f69
.L73:
b f70
.L74:
b f71
.L75:
b f72
.L76:
b f73
.L77:
b f74
.L78:
b f75
.L79:
b f76
.L80:
b f77
.L81:
b f78
.L82:
b f79
.L83:
b f80
.L84:
b f81
.L85:
b f82
.L86:
b f83
.L87:
b f84
.L88:
b f85
.L89:
b f86
.L90:
b f87
.L91:
b f88
.L92:
b f89
.L93:
b f90
.L94:
b f91
.L95:
b f92
.L96:
b f93
.L97:
b f94
.L98:
b f95
.L99:
b f96
.L100:
b f97
.L101:
b f98
.L102:
b f99
.L1:
bx lr
.size f, .-f
.ident "GCC: (Linaro GCC 4.5-2011.02-0) 4.5.2"