Re: Ideas I've been toying with September 07, 2008 11:34PM | Registered: 16 years ago Posts: 443 |
Re: Ideas I've been toying with September 16, 2008 01:13AM | Registered: 16 years ago Posts: 289 |
Re: Ideas I've been toying with September 21, 2008 01:05AM | Registered: 16 years ago Posts: 443 |
Re: Ideas I've been toying with September 22, 2008 11:44PM | Registered: 16 years ago Posts: 289 |
Re: Ideas I've been toying with September 23, 2008 01:18AM | Registered: 16 years ago Posts: 114 |
True, but when subroutines and GOTO statements are unsupported you have a fairly large problem.Quote
strongfan
pfft. GOTO statements are frowned upon anyway.
Re: Ideas I've been toying with September 23, 2008 10:16AM | Registered: 16 years ago Posts: 443 |
Quote
strongfan
pfft. GOTO statements are frowned upon anyway.
JMP (standard jump) JGE (jump if comparison was greater than or equal to)
for_start: mov ..... cmp i, 2 jl for_start
Re: Ideas I've been toying with September 23, 2008 05:50PM | Registered: 16 years ago Posts: 138 |
Re: Ideas I've been toying with September 23, 2008 09:22PM | Registered: 16 years ago Posts: 289 |
Re: Ideas I've been toying with September 24, 2008 09:08AM | Registered: 16 years ago Posts: 443 |
Re: Ideas I've been toying with September 24, 2008 10:31AM | Registered: 16 years ago Posts: 211 |
Re: Ideas I've been toying with September 24, 2008 11:31AM | Registered: 16 years ago Posts: 443 |
switch( argc ) { case < 2: printf("You must have at least two arguments"); break; case 2: case 3: printf("Yay!"); break; default: print("Too many arguments for me to handle"); break; }
mov eax, argc cmp eax, 2 jnl @case_generated_1 push offset message_too_few_args call printf jmp @case_generated_4 @case_generated_1: cmp eax, 2 je @case_generated_2 cmp eax, 3 jne @case_generated_3 @case_generated_2: push offset message_just_the_right_amount call printf jmp @case_generated_4 @case_generated_3: push offset message_too_many_args call printf @case_generated_4:
Re: Ideas I've been toying with September 25, 2008 04:00PM | Registered: 16 years ago Posts: 211 |
Re: Ideas I've been toying with September 25, 2008 05:43PM | Registered: 16 years ago Posts: 443 |
switch_offsets: case1 dd offset @case_generated1 case2 dd offset @case_generated2 case3 dd offset @case_generated3 ... code ... mov eax, argc cmp eax, 2 jnl @case_generated_1skip call dword ptr [case1] jmp @case_generated_finish @case_generated_1skip: cmp eax, 2 je @case_generated_2okay cmp eax, 3 jne @case_generated_2skip @case_generated_2okay: call dword ptr [case2] jmp @case_generated_finish @case_generated_2skip: call dword ptr [case3] @case_generated_finish: ... code ... ;---------------------------------------- Subroutines @case_generated1: push offset message_too_few_args call printf ret @case_generated2: push offset message_just_the_right_amount call printf ret @case_generated_3: push offset message_too_many_args call printf ret
Re: Ideas I've been toying with September 26, 2008 01:55AM | Registered: 16 years ago Posts: 138 |
void *PtrTable[] = {case1, case2and3, case2and3, case4}; if(Index > 3) goto casedefault; goto PtrTable[Index]; case1: //... goto endswitch case2and3: //... goto endswitch case4: //... goto endswitch casedefault: //... goto endswitch endswitch: //...Not sure if that's syntactically valid, because I've never used gotos :) but that's about how it looks in the ASM. There's a pointer table, and it reads an address from there and jumps to it. It's not a function call, so they don't do the register saving and restoring you normally would. Basically you'll see a left-shift by 2 (to turn the index into a pointer), load word, jump to the register it just loaded to, and then several pieces of code one after another that just do one or two instructions and then all branch to the same place.
Re: Ideas I've been toying with September 26, 2008 10:40AM | Registered: 16 years ago Posts: 443 |
Re: Ideas I've been toying with September 26, 2008 10:52PM | Registered: 16 years ago Posts: 289 |
Re: Ideas I've been toying with September 27, 2008 01:26AM | Registered: 16 years ago Posts: 443 |