flat assembler
Message board for the users of flat assembler.
Index
> Main > Rotating Bits Goto page 1, 2 Next |
Author |
|
revolution 27 Apr 2010, 00:32
"best" in what sense? Smallest code size? Fastest execution speed? Easiest for you to understand? Least amount of typing?
|
|||
27 Apr 2010, 00:32 |
|
Tyler 27 Apr 2010, 01:00
Sorry for the ambiguity, easiest to understand(less typing usually comes with this one). Is there anything that will rotate bits w/o setting the carry flag when it rotates out a 1 and will rotate bits from one end to the other(bits rotated out, rotate in at opposite end). If not, what would you use to accomplish my task I mentioned in my above post..
|
|||
27 Apr 2010, 01:00 |
|
windwakr 27 Apr 2010, 01:22
ROL/ROR?
rol eax,16 EDIT: Wait no, that messes with carry. |
|||
27 Apr 2010, 01:22 |
|
revolution 27 Apr 2010, 01:34
In X86 AFAIK there are no non-flags-setting rotation instructions or groups of instructions.
LEA would be the closest but that will discard the upper bits. Why not just save the carry flag, do the rotations, then restore the flags? |
|||
27 Apr 2010, 01:34 |
|
Tyler 27 Apr 2010, 01:42
revolution wrote:
I guess that's what I'll do. |
|||
27 Apr 2010, 01:42 |
|
edfed 27 Apr 2010, 01:49
Code: push eax push eax pop ax pop eax lea esp,[ep+2] will not mess the flags. the same, but now, with fixed memory Code: mem dd ?,? ... mov [mem],eax mov [mem+4],eax mov eax,[mem+2] personnaly, i prefer do it with ROR and ROL. about DX to high part... push dx ax pop eax |
|||
27 Apr 2010, 01:49 |
|
sinsi 27 Apr 2010, 01:53
Code: xchg al,ah bswap eax xchg al,ah messy, but so is saving/restoring flags. |
|||
27 Apr 2010, 01:53 |
|
ass0 27 Apr 2010, 01:54
I think you are confusing rol/ror with rcl/rcr
rol doesn't use carry flag while rcl does. _________________ Nombre: Aquiles Castro. Location2: about:robots |
|||
27 Apr 2010, 01:54 |
|
ass0 27 Apr 2010, 02:02
rotate with and without carry, rcl/rcr, rol/ror Code: mov cl,16 rol eax,cl _________________ Nombre: Aquiles Castro. Location2: about:robots |
|||
27 Apr 2010, 02:02 |
|
edfed 27 Apr 2010, 02:06
indead, that's pretty logic...
what should be passed ot carry in case of roX? the fisrt bit? the last bit? then, nothing pass through carry and it is clear. |
|||
27 Apr 2010, 02:06 |
|
Tyler 27 Apr 2010, 02:07
rol shifts bit to carry and low bit while rcl uses the carry flag as if it were a 17th bit.
http://webster.cs.ucr.edu/AoA/DOS/ch06/CH06-3.html#HEADING3-294 |
|||
27 Apr 2010, 02:07 |
|
revolution 27 Apr 2010, 02:17
Tyler: Download the manuals from Intel/AMD. Don't just rely on random websites to tell you about X86 instructions, get it from the original source.
|
|||
27 Apr 2010, 02:17 |
|
ass0 27 Apr 2010, 02:21
For the ROL and ROR instructions, the original value of the CF flag is not a part of the result, but the CF flag receives a copy of the bit that was shifted from one end to the other. Yeah a bit confusing. _________________ Nombre: Aquiles Castro. Location2: about:robots |
|||
27 Apr 2010, 02:21 |
|
Tyler 27 Apr 2010, 03:05
Was that a pun?
revolution: Okay, I'll reference a manual next time. That site was the first that come up with a search of "rol asm" on google and it agreed with what I'd already thought, so I assumed it was right, and it is an edu. Was I wrong? |
|||
27 Apr 2010, 03:05 |
|
revolution 27 Apr 2010, 03:18
I can't see how being "an edu" helps. Try intel.com or amd.com, anything else is just rehashing the originals and opening up the possibility of introducing mistakes.
|
|||
27 Apr 2010, 03:18 |
|
LocoDelAssembly 27 Apr 2010, 05:21
Just wondering, why do you need CF untouched? Can you show us the code you're working on?
|
|||
27 Apr 2010, 05:21 |
|
Tyler 27 Apr 2010, 05:30
I just didn't want it tampered with, that's all.
Code: print_str_bw: push ebp mov ebp,esp pushad label .param dword at ebp + 8 mov esi,[.param] call .update_print_pos mov ah,7 .next_char: lodsb cmp al,0ah je .lf cmp al,0dh je .cr cmp al,0 je .done stosw cmp [col],80 jae .eol add [col],1 jmp .next_char .cr: add esi,1 .lf: .eol: mov [col],0 cmp [row],23 jae .eos add [row],1 call .update_print_pos jmp .next_char .eos: call scroll_down call .update_print_pos jmp .next_char .update_print_pos: push eax edx call update_pos mov edi,[vid_mem] mov eax,[pos] imul eax,eax,2 add edi,eax pop edx eax ret .done: call update_cursor popad mov esp,ebp pop ebp ret I went ahead and used imul in .update_print_pos. If you see any mistakes or unnecessary instructions, please do tell. |
|||
27 Apr 2010, 05:30 |
|
revolution 27 Apr 2010, 05:34
'imul eax,eax,2' == 'add eax,eax' == 'shl eax,1' == 'lea eax,[eax*2]' == 'lea eax,[eax+eax]'
|
|||
27 Apr 2010, 05:34 |
|
Tyler 27 Apr 2010, 05:42
Okay, you got me... There's also this were I have to multiply by 80, forgot about it.
Code: update_pos: pushad xor eax,eax mov al,[row] ; Get new row mov dl,80 mul dl ; row*80 xor edx,edx mov dl,[col] add eax,edx ; row*80+col mov [pos],eax ; pos=row*80+col popad ret |
|||
27 Apr 2010, 05:42 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.