flat assembler
Message board for the users of flat assembler.
Index
> Windows > mov vs cmove (with the identical arguments) - OK vs Error |
Author |
|
alexfru 07 Feb 2018, 23:55
cmovcc's source operand is either a register or a memory operand. It does not take an immediate.
|
|||
07 Feb 2018, 23:55 |
|
revolution 08 Feb 2018, 03:15
It is a serious oversight on Intel's part. CMOVcc doesn't support immediate operands, as alexfru states.
One possible way around it is this: Code: mov rdx,modbus_ascii_txt ; use a temporary register cmove rax,rdx |
|||
08 Feb 2018, 03:15 |
|
fatygant 08 Feb 2018, 08:35
Thank you alexfru and revolution!
|
|||
08 Feb 2018, 08:35 |
|
MatQuasar 14 May 2024, 10:56
Learned 'cmove' today from Ville's example code in another thread. It cuts down at least two unnecessary branches.
Code: _str1 db '1' _str2 db '2' _input rb 1 lea eax, [_str1] lea ebx, [_str2] cmp [_input], '1' cmove ebx, eax Code: _str1 db '1' _str2 db '2' _input rb 1 cmp [_input], '1' jz .f lea ebx, [_str2] jmp .g .f: lea ebx, [_str1] .g: Last edited by MatQuasar on 14 May 2024, 11:07; edited 1 time in total |
|||
14 May 2024, 10:56 |
|
MatQuasar 14 May 2024, 11:04
But both sizes are same:
Code: PS C:\Users\User\projects> format-hex a.bin Path: C:\Users\User\projects\a.bin 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00000000 31 32 00 66 8D 06 00 00 66 8D 1E 01 00 80 3E 02 12.f...f...>. 00000010 00 31 66 0F 44 D8 .1f.DØ PS C:\Users\User\projects> format-hex b.bin Path: C:\Users\User\projects\b.bin 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00000000 31 32 00 80 3E 02 00 31 74 07 66 8D 1E 01 00 EB 12.>..1t.f...ë 00000010 05 66 8D 1E 00 00 .f... PS C:\Users\User\projects> dir *.bin Directory: C:\Users\User\projects Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 14/5/2024 7:02 PM 22 a.BIN -a---- 14/5/2024 7:03 PM 22 b.BIN But if put "use32", there is difference by 1 byte, "cmove" version is shorter. |
|||
14 May 2024, 11:04 |
|
bitRAKE 14 May 2024, 12:02
Coding for size, we'd use:
Code: cmp [_input], '1' mov eax, _str1 cmove eax, [_other] Code: mov eax, _str1 cmp [_input], '1' jz @F add eax, _str2-_str1 @@: We loose RIP addressing and need relocation data, etc. It's all trade-offs depending on what you need. Edit: the FPU probably wins the code density prize: FBSTP [RSI] ; two bytes for all that! (Ignoring system instructions.) _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
14 May 2024, 12:02 |
|
MatQuasar 14 May 2024, 17:14
Good and efficient codes, bitRAKE.
|
|||
14 May 2024, 17:14 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.