Hello. I was wondering if anybody may tell me if there is a kind of case and or switch method which i can use to check "numbers" with instead of using .ifs all the time. Cheers. :dance:
.IF does contain a case statement ....
.IF eax ==1
; case 1 code here
.ELSEIF eax == 2
; case 2 code here
.ELSEIF eax == 3
; case 3 code here
.ELSEIF ebx==7 .OR. ecx !=32
; funny powefull switch
.ELSE
; default/ no match case here
.ENDIF
Please note that unlike CASE / SWITCH in C here you can use another register or variable in .ELSEIF statements .
And you can also use expressions.
Yeah i already knew that. It's a bit... weird though for me. Is their anything else i can use to check the numbers with?. :\ Thanks.
The best way, is not using both of them. SWITCH is actually IF, it's the same thing, you're not doing anything faster or better with SWITCH
Can you show me a quick example on how to use the switch method in masm32 please ramguru ? :)
c:\masm32\examples\exampl08\switch\
An alternative using what in basic was called a computed goto
implemented by a jump table.
It requires extra data to hold the jump table and code to fill the table,
(unless there is an assembly time technique to eliminate the fill code).
It doesn't use any cmp ( if ) just loads the computed jump address then jumps.
.data
jtable dd 4 dup (0)
szCaption db "Example of computed goto via jump table",0
szItem0 db " Item 0 ",0
szItem1 db " Item 1 ",0
szItem2 db " Item 2 ",0
szItem3 db " Item 3 ",0
.code
start:
mov jtable+0*4, offset G0
mov jtable+1*4, offset G1
mov jtable+2*4, offset G2
mov jtable+3*4, offset G3
mov ebx, 0
L0:
mov eax, [jtable+ebx*4]
jmp eax
G0:
invoke MessageBox, NULL, ADDR szItem0, ADDR szCaption, MB_OK
jmp Past
G1:
invoke MessageBox, NULL, ADDR szItem1, ADDR szCaption, MB_OK
jmp Past
[attachment deleted by admin]
I appreciate every bodies suggestions.
Success !
The fill code is eliminated. Now it is done at assembly time.
.data
jtable dd G0, G1, G2, G3
szCaption db "Example of computed goto via jump table",0
[attachment deleted by admin]