flat assembler
Message board for the users of flat assembler.
Index
> Main > Little CMP Logic help. |
Author |
|
Overflowz 30 Jan 2011, 11:54
I've tried 1 logic but I'll be thankful if some of you will write ur own.. Here's mine what I though.
Code: xor eax,eax cmp eax,0 jae .stage1 .stage1: cmp eax,10 jbe .stage2 ret .stage2: do something Equal C Code. Code: if(int a >=0 && int a<= 10){ do something } |
|||
30 Jan 2011, 11:54 |
|
ManOfSteel 30 Jan 2011, 12:09
Code: mov eax,5 cmp eax,10 jae exit test eax,eax jbe exit ; do something exit: ~~~~ Overflowz wrote:
So it's running stage1 either way? |
|||
30 Jan 2011, 12:09 |
|
cod3b453 30 Jan 2011, 12:15
For signed a:
Code: cmp eax,0 jl @f cmp eax,10 jg @f ; do something @@: Code: cmp eax,10 ja @f ; do something @@: |
|||
30 Jan 2011, 12:15 |
|
Overflowz 30 Jan 2011, 14:00
ManOfSteel
Nice one, thank you. Yes stage1 will run anyway and if you don't want it then just retn insturcion there. I'll do something later about that.. cod3b453 Nice trick on second example but I need numbers between values :p |
|||
30 Jan 2011, 14:00 |
|
mindcooler 30 Jan 2011, 14:54
Overflowz wrote:
Isn't between 0 and 10 numbers between values? value1 <= eax <= value2 Code: sub eax,value1 cmp eax,(value2-value1) jbe .ok _________________ This is a block of text that can be added to posts you make. |
|||
30 Jan 2011, 14:54 |
|
Overflowz 30 Jan 2011, 15:21
mindcooler
Yes it is but look what I mean: from 0 to 10 = do task 1 from 10 to 20 = do task 2 and so on.. |
|||
30 Jan 2011, 15:21 |
|
mindcooler 30 Jan 2011, 15:52
Just build on my example:
value1 <= eax <= value2 value2 <= eax <= value3 Code: sub eax,value1 cmp eax,(value2-value1) jbe .ok1 sub eax,(value2-value1) cmp eax,(value3-value2) jbe .ok2 so: 0 <= eax <= 10 10 <(=) eax <= 20 Code: ;sub eax,0 cmp eax,10 jbe .ok1 sub eax,10 cmp eax,10 jbe .ok2 This could be simplified greatly by a macro. _________________ This is a block of text that can be added to posts you make. |
|||
30 Jan 2011, 15:52 |
|
Overflowz 30 Jan 2011, 17:37
mindcooler
Can you post with using macros now ? Thanks. |
|||
30 Jan 2011, 17:37 |
|
mindcooler 30 Jan 2011, 17:44
I don't have any macro for pascal style case switches, perhaps some macro buff has?
|
|||
30 Jan 2011, 17:44 |
|
edfed 30 Jan 2011, 18:00
post summary:
lowbound<eax<highbound == (eax-lowbound)<(highbound-lowbound) due to the signed binary representation of integers. |
|||
30 Jan 2011, 18:00 |
|
mindcooler 30 Jan 2011, 21:14
Perhaps something like this:
Code: macro switch reg,[a,b,label] { common base=0 lastbase=0 forward sub reg,(a-base) cmp reg,b-a jbe label base=base+a-lastbase lastbase=a } start: mov eax,25 switch eax,0,3,.1,6,15,.2,22,25,.3 .default: mov edx,22 jmp .out .1: mov edx,7 jmp .out .2: mov edx,11 jmp .out .3: mov edx,14 .out: _________________ This is a block of text that can be added to posts you make. |
|||
30 Jan 2011, 21:14 |
|
b1528932 30 Jan 2011, 21:30
bound instruction?
|
|||
30 Jan 2011, 21:30 |
|
Picnic 30 Jan 2011, 23:34
Hi, you might find useful this macro.
Code: macro JumpIf reg, uplimit, lowlimit, lbl { lea ecx, [reg-1-uplimit] lea edx, [reg-lowlimit] xor ecx, edx js lbl } Code: mov eax, 10 JumpIf eax, 10, 0, someLabel |
|||
30 Jan 2011, 23:34 |
|
revolution 31 Jan 2011, 00:18
b1528932 wrote: bound instruction? |
|||
31 Jan 2011, 00:18 |
|
cod3b453 31 Jan 2011, 00:21
You can expand what I said to multiple ranges:
Code: cmp eax,10 jae @f ; do something 0-9 jmp .done @@: cmp eax,20 jae @f ; do something 10-19 jmp .done @@: ; ... .done: Code: mov ebx,0x1999999A ; ebx = round(2^32 / 10) xor edx,edx mul ebx ; reciprocal multply eax so that edx = eax / 10 mov eax,dword [4*edx+lut] ; find the label in LUT jmp eax ; jump to it do_0_9: ; do something 0-9 jmp .done do_10_19: ; do something 10-19 jmp .done ; ... .done: ; ... lut: dd do_0_9,do_10_19; ... |
|||
31 Jan 2011, 00:21 |
|
b1528932 31 Jan 2011, 01:32
Quote: Have you ever used it? I've never seen it used. It ain't so simple to use, especially in a PM environment. im almost sure there is a way to supress exception, propable eflags or msr, i dont recall it now. |
|||
31 Jan 2011, 01:32 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.