flat assembler
Message board for the users of flat assembler.

Index > Main > Rotating Bits

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 27 Apr 2010, 00:19
What's the best way to get the lower half of eax into the higher half while moving the higher into the lower, preferably w/o the possibility of ending up with the carry flag set? I'm doing some multiplying and I need to get dx into the higher half of eax while maintaining ax(not necessarily in ax, just the value of ax needs to keep from being lost).
Post 27 Apr 2010, 00:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
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?
Post 27 Apr 2010, 00:32
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
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..
Post 27 Apr 2010, 01:00
View user's profile Send private message Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
windwakr 27 Apr 2010, 01:22
ROL/ROR?


rol eax,16


EDIT:
Wait no, that messes with carry.

_________________
----> * <---- My star, won HERE
Post 27 Apr 2010, 01:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
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?
Post 27 Apr 2010, 01:34
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 27 Apr 2010, 01:42
revolution wrote:

Why not just save the carry flag, do the rotations, then restore the flags?

I guess that's what I'll do.
Post 27 Apr 2010, 01:42
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4341
Location: Now
edfed 27 Apr 2010, 01:49
Code:
push eax
push eax
pop ax
pop eax
lea esp,[ep+2]
    

will not mess the flags. Laughing
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
Post 27 Apr 2010, 01:49
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 790
Location: Adelaide
sinsi 27 Apr 2010, 01:53
Code:
  xchg al,ah
  bswap eax
  xchg al,ah
    

messy, but so is saving/restoring flags.
Post 27 Apr 2010, 01:53
View user's profile Send private message Reply with quote
ass0



Joined: 31 Dec 2008
Posts: 518
Location: ( . Y . )
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.

_________________
Image
Nombre: Aquiles Castro.
Location2: about:robots
Post 27 Apr 2010, 01:54
View user's profile Send private message Reply with quote
ass0



Joined: 31 Dec 2008
Posts: 518
Location: ( . Y . )
ass0 27 Apr 2010, 02:02
rotate with and without carry, rcl/rcr, rol/ror

Code:
mov cl,16
rol eax,cl
    

_________________
Image
Nombre: Aquiles Castro.
Location2: about:robots
Post 27 Apr 2010, 02:02
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4341
Location: Now
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. Wink
Post 27 Apr 2010, 02:06
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
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
Post 27 Apr 2010, 02:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
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.
Post 27 Apr 2010, 02:17
View user's profile Send private message Visit poster's website Reply with quote
ass0



Joined: 31 Dec 2008
Posts: 518
Location: ( . Y . )
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.

_________________
Image
Nombre: Aquiles Castro.
Location2: about:robots
Post 27 Apr 2010, 02:21
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
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?
Post 27 Apr 2010, 03:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
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.
Post 27 Apr 2010, 03:18
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 27 Apr 2010, 05:21
Just wondering, why do you need CF untouched? Can you show us the code you're working on?
Post 27 Apr 2010, 05:21
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
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.
Post 27 Apr 2010, 05:30
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
revolution 27 Apr 2010, 05:34
'imul eax,eax,2' == 'add eax,eax' == 'shl eax,1' == 'lea eax,[eax*2]' == 'lea eax,[eax+eax]'
Post 27 Apr 2010, 05:34
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 27 Apr 2010, 05:42
Okay, you got me...Smile 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 
    
Post 27 Apr 2010, 05:42
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.