flat assembler
Message board for the users of flat assembler.
Index
> Main > Logic operators in expression evaluation |
Author |
|
macomics 19 Nov 2022, 20:50
Code: ; Starting with Pentium (i586) ; if op1 == op2 then al = 1 else al = 0 mov ax, [op1] cmp ax, [op2] setz al ; fl.zf == 1 ; if op1 <> op2 then al = 1 else al = 0 mov ax, [op1] cmp ax, [op2] setnz al ; fl.zf == 0 ; unsigned integer ; if op1 > op2 then al = 1 else al = 0 mov ax, [op1] cmp ax, [op2] seta al ; fl.zf == 0 && fl.cf == 0 ; if op1 >= op2 then al = 1 else al = 0 mov ax, [op1] cmp ax, [op2] setae al ; cf = 0 ; if op1 <= op2 then al = 1 else al = 0 mov ax, [op1] cmp ax, [op2] setbe al ; fl.zf == 1 || fl.cf == 1 ; if op1 < op2 then al = 1 else al = 0 mov ax, [op1] cmp ax, [op2] setb al ; fl.cf == 1 ; signed integer ; if op1 > op2 then al = 1 else al = 0 mov ax, [op1] cmp ax, [op2] setg al ; fl.zf == 0 || fl.sf == fl.of ; if op1 >= op2 then al = 1 else al = 0 mov ax, [op1] cmp ax, [op2] setge al ; fl.sf == fl.of ; if op1 <= op2 then al = 1 else al = 0 mov ax, [op1] cmp ax, [op2] setle al ; fl.zf == 1 || fl.zf <> fl.of ; if op1 < op2 then al = 1 else al = 0 mov ax, [op1] cmp ax, [op2] setl al ; fl.zf <> fl.of ; float (single/double/extended) ; if op1 == op2 then al = 1 else al = 0 fld [op1] fcomip [op2] ; swr.c3 == 1 && swr.c1 == 0 setz al ; fl.zf == 1 ; if op1 <> op2 then al = 1 else al = 0 fld [op1] fcomip [op2] ; swr.c3 == 0 && swr.c1 == 0 setnz al ; fl.zf == 0 ; if op1 > op2 then al = 1 else al = 0 fld [op1] fcomip [op2] ; swr.c3 == swr.c2 == swr.c1 == swr.c0 == 0 seta al ; fl.zf == 0 && fl.cf == 0 ; if op1 >= op2 then al = 1 else al = 0 fld [op1] fcomip [op2] ; swr.c0 == 0 && swr.c1 == 0 setae al ; cf = 0 ; if op1 <= op2 then al = 1 else al = 0 fld [op1] fcomip [op2] ; (swr.c3 == 1 || swr.c0 == 1) && swr.c1 == 0 setbe al ; fl.zf == 1 || fl.cf == 1 ; if op1 < op2 then al = 1 else al = 0 fld [op1] fcomip [op2] ; swr.c0 == 1 && swr.c1 == 0 setb al ; fl.cf == 1 Last edited by macomics on 20 Nov 2022, 09:29; edited 2 times in total |
|||
19 Nov 2022, 20:50 |
|
geekbasic@gmx.com 19 Nov 2022, 23:14
Thank you! Now I can grab my asm books and study those functions. If they are even covered in my books. They are from the 80s. Maybe I will need a newer book.
These will only work on a 586? What is the equivalent for 286 or 386? Is it much harder or just less effective? I just found this site explaining the instructions you have provided me. http://www.mathemainzel.info/files/x86asmref.html#setb It says they work on a 386. Is it 586 or 386? |
|||
19 Nov 2022, 23:14 |
|
geekbasic@gmx.com 20 Nov 2022, 07:04
setnae didn't work for the >=
Instead I was able to use setae |
|||
20 Nov 2022, 07:04 |
|
sts-q 20 Nov 2022, 07:18
From macomics post i learned about this setcc instruction. It works on my i3-550 and should go on all other amd/intel x86(_64), too.
Looks like setcc works only with byte or word registers, at least in 64-bit-mode. I didn't know there is a r10b register, but there is! Anyway i want the whole r10 register set to 0 or to 1. (Looked like it is faster, too, but i don't guarantee on that.) That's why i stay with: Code: cmp r1, r1 ; compare: set flags mov rax, 1 ; don't change flags between cmp and cmovxx mov r1, 0 ; set result := false cmovl r1,rax ; conditional move: move only if lesser: set result := true https://www.felixcloutier.com/x86/cmovcc |
|||
20 Nov 2022, 07:18 |
|
bitRAKE 20 Nov 2022, 07:29
sts-q wrote: Anyway i want the whole r10 register set to 0 or to 1. Code: mov r10, 0 setl r10b Code: setl r10b
movzx r10, r10b ... using just the single register. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
20 Nov 2022, 07:29 |
|
sts-q 20 Nov 2022, 07:41
(Thanks!) |
|||
20 Nov 2022, 07:41 |
|
macomics 20 Nov 2022, 08:18
geekbasic@gmx.com wrote: setnae didn't work for the >= geekbasic@gmx.com wrote: These will only work on a 586? geekbasic@gmx.com wrote: What is the equivalent for 286 or 386? Is it much harder or just less effective? Code: mov ax, [op1] cmp ax, [op2] sahf ; ah = fl & 255 shl ah, 2 ; ah = xZxxxxxx -> cf = Z sbb ax, ax ; if op1 == op2 then ax = -1 else ax = 0 sts-q wrote:
Last edited by macomics on 20 Nov 2022, 08:37; edited 3 times in total |
|||
20 Nov 2022, 08:18 |
|
geekbasic@gmx.com 20 Nov 2022, 08:28
thank you for explaining
|
|||
20 Nov 2022, 08:28 |
|
macomics 20 Nov 2022, 09:31
Added descriptions of flags and logic for checking them to determine conditions so that you can write code without using setxx commands.
|
|||
20 Nov 2022, 09:31 |
|
geekbasic@gmx.com 26 Nov 2022, 22:27
Thank you. This information is very important.
I wonder if I should have a compiler option to allow for either method. It would be nice to have a language that compiles for platforms with the simplest requirements. |
|||
26 Nov 2022, 22:27 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.