Author Topic: Simple 32bit rol  (Read 11369 times)

Offline proggic

  • Jr. Member
  • *
  • Posts: 2
Simple 32bit rol
« on: January 17, 2015, 02:27:50 AM »
Hi,

i would be pleased if someone could help me to understand why the folling example code doesnt work as aspected and of course if there is a solution. Tried for a couple of hours now, but without luck.

nasm  -f elf64 -g -F stabs -o bittest.o bittest.asm
ld ./bittest.o

>>: error: invalid combination of opcode and operands

I tried to store the result of dx and paste it to rol but more or less - same same.

Thx

Code: [Select]
SECTION .data

SECTION .text
global _main

_main:
    mov r8d, 0xF000FF00
    mov r9d, 0xF000FF00
    rol r8d, 62        ; could be any uint32 by scenario

    mov eax, 62     ; ok let's reduce it by
    mov ebx, 32     ; edx = eax % ebx
    div ebx             ; edx = 30
    rol r9d, [edx]    ; r9d << [edx] ????
                            ; error: invalid combination of opcode and operands
    ret

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Simple 32bit rol
« Reply #1 on: January 17, 2015, 05:33:45 AM »
AFAIK, the only register that can be used as the second operand to "rol" is cl. Try...

Code: [Select]
SECTION .data

SECTION .text
global _main

_main:
    mov r8d, 0xF000FF00
    mov r9d, 0xF000FF00
    rol r8d, 62        ; could be any uint32 by scenario

    mov eax, 62     ; ok let's reduce it by
    mov ebx, 32     ; edx = eax % ebx
xor edx, edx ; "div" divides edx:eax by ebx!!!
    div ebx             ; edx = 30
;    rol r9d, [edx]    ; r9d << [edx] ????
                            ; error: invalid combination of opcode and operands

; even if this assembled, attempting to access memory
; at [30] would surely crash

    mov cl, dl
    rol r9d, cl

    ret

Untested!!!

Best,
Frank


Offline proggic

  • Jr. Member
  • *
  • Posts: 2
Re: Simple 32bit rol
« Reply #2 on: January 17, 2015, 12:16:17 PM »
Hi Frank,

thx - that works great!

I use this code only inside gdb therefore the crash is calculated but for now r8d and r9d have the same value and that's what i want so far.