flat assembler
Message board for the users of flat assembler.
Index
> Main > How to extract one bit from a register? |
Author |
|
MHajduk 28 Aug 2011, 14:56
You may consider use of the bt instruction for bits testing.
|
|||
28 Aug 2011, 14:56 |
|
emc 28 Aug 2011, 15:19
Thanks, so this following code:
Code: mov eax, 42 bt ecx, eax This code stores the 42nd bit of ECX in CF flag? Am I right? |
|||
28 Aug 2011, 15:19 |
|
edfed 28 Aug 2011, 15:22
ecx is only 32 bits. maximum value is then 31 for a 32 bit register.
bit 0 to 31. 42 is illegal, but can work if you test on a memory operand, and it will let scan very large bitstreams in memory. but for BT on registers, it is limited to the register size, sorry, a 32 bit register cannot hold more than 32 bits. |
|||
28 Aug 2011, 15:22 |
|
emc 28 Aug 2011, 15:28
Yes, I was distracted, sorry for the 42.
But this code is alright with 64-bits registers (or a value lesser than 31)? |
|||
28 Aug 2011, 15:28 |
|
edfed 28 Aug 2011, 18:52
RTFM (Read The Fucking Manual)
en français, lire le foutu manuel, car justement, tout et dit sur les instructions dans les manuels du programmeur disponibles sur les sites d'intel, AMD, ou autre fondeur. pour un debutant, le manuel amd est plus facile à aborder, les instructions sont expliquées avec des dessins, ce qui facilite la comprehension, par rapport aux explications à base de pseudo code d'intel. bienvenue dans le monde magique de fasm. |
|||
28 Aug 2011, 18:52 |
|
emc 28 Aug 2011, 19:18
Je ne connaissais pas BT avant, c'est justement grâce au "foutu manuel" que j'ai pu savoir ce que ça faisait (donc je le lis, et plutôt bien je pense. On ne peut pas deviner à propos de CF).
Je demandais juste une confirmation pour savoir si j'avais bien compris, où est le mal ? -- I didn't know the BT instruction earlier, but it's the "fucking manual" that given to me a knowledge about BT (so, I read it; I didn't could guess for CF). I just asked if my code was alright because I wanted a confirmation. Nothing bad? edfed wrote: bienvenue dans le monde magique de fasm. Merci bien edfed. |
|||
28 Aug 2011, 19:18 |
|
edfed 28 Aug 2011, 19:55
pas de mal, juste la reponse la plus pertinente, car si à chaque instruction, on demande comment ça marche, on a pas fini. il y a plusieurs centaines d'instructions X86
nothing bad, just the more pertinent answer, because if for each instruction, man ask how it works, it will take mounth, there are several hundred x86 instructions. BT have BTC, BTS and BTR variations: Complement, complement the tested bit Set, set the tested bit to 1 Reset, set the tested bit to 0 |
|||
28 Aug 2011, 19:55 |
|
ouadji 28 Aug 2011, 20:21
Quote: But this code is alright with 64-bits registers? (or a value lesser than 31)? Je taquinne emc, rien de plus ... pas pu m'empêcher (oui, je vais au coin, punis) c'est vrai que de demander, même si c'est écrit noir sur blanc, ça rassure. Ceci dit, quand il y a un doute, rien de tel qu'un bon debugger et de tester ça en "vrai", y'a pas mieux pour apprendre. |
|||
28 Aug 2011, 20:21 |
|
emc 28 Aug 2011, 20:24
Ok sorry about that, I am yet beginner, so I feel the need to be reassured...
But no problem, I shall try to test alone in the future. I did the program that I wanted to do thanks to you. Thanks! PS: je penserai à mon gdb ouadji ! |
|||
28 Aug 2011, 20:24 |
|
ouadji 28 Aug 2011, 20:33
rien que de la taquine emc, rien de plus. bein si que tu peux demander, un forum ça sert à ça. Juste que les réponses étaient un poil évidentes par rapport au texte du bouquin. ceci dit, facile de taquiner quand on épluche lesdits bouquins depuis 15 ans. Au début, c'était tout pareil que toi. Donc, reviens poser tes soucis quand tu veux. |
|||
28 Aug 2011, 20:33 |
|
emc 28 Aug 2011, 20:42
Merci ouadji, c'est vrai que moi j'épluche le manuel que depuis hier, mais je vais songer à regarder un peu le manuel AMD (pour ses dessins) comme edfed le conseille, ça sera peut-être moins ardue.
|
|||
28 Aug 2011, 20:42 |
|
revolution 28 Aug 2011, 23:52
And also remember the instruction PEXT. It can be used to transfer the desired bit directly to a register and doesn't affect the flags.
|
|||
28 Aug 2011, 23:52 |
|
emc 29 Aug 2011, 00:06
Here, affecting CF suited me, to use JC/JNC then. But I'll remember the PEXT instruction, thanks revolution.
|
|||
29 Aug 2011, 00:06 |
|
Madis731 29 Aug 2011, 06:01
PEXTR* extracts full bytes/words/dwords, single bits still need to be extracted separately through use of BT or AND,SHR instructions.
|
|||
29 Aug 2011, 06:01 |
|
emc 29 Aug 2011, 14:13
Unfortunately, I don't have SSE4.1 and AVX so I can't use PEXTR*
|
|||
29 Aug 2011, 14:13 |
|
revolution 29 Aug 2011, 17:55
And you'll need AVX2 for PEXT.
|
|||
29 Aug 2011, 17:55 |
|
Madis731 31 Aug 2011, 16:04
oh nice one, revolution!
I didn't catch that. I plan on investing in AVX2 CPU, because I haven't got anything newer than Penryn. It's got some really nice integer instructions. Maybe I can help make the world better helping Tomasz, Agner etc. |
|||
31 Aug 2011, 16:04 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.