News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

SHR - Shift to the RIGHT ?

Started by ilian007, October 21, 2009, 03:51:40 PM

Previous topic - Next topic

ilian007

Hello,

I am trying to SHR AX with the value of varible BADBIT.

here is the example

I have a fixingnumber --> 100000000000

...........
................
MOV BADBIT,AX (0101 - in my case but it changes depending on the input)
MOV AX,FIXINGNUMBER
SHR AX,BADBIT   ----> gives me an error
...............
...........
I tried:
MOV CL,BADBIT ----> gives me an error
MOV AX,CL     


How to make SHR to shift Fixingnumber aka AX with the value of BADBIT in that case it is SHR 5 which I can do by
MOV CL,5
SHR AX,CL

But the value of BADBIT changes depending on the input


Thank you















FORTRANS

Hi,

   If,

MOV BADBIT,AX

gives no error, and

MOV CL,BADBIT

gives an error, then BADBIT is a WORD value.  Move it into CX
and then use CL.  Or use;

QuoteMOV CL,BYTE PTR BADBIT

to put it into CL.

HTH,

Steve

MichaelW

ilian,

The value 100000000000 is too big even for a 32-bit register or memory variable. The maximum values, expressed as unsigned for the decimal values, are:

BYTE  255, 0FFh, 11111111b
WORD  65535, 0FFFFh, 1111111111111111b
DWORD 4294967295, 0FFFFFFFFh, 11111111111111111111111111111111b


Assuming that BADBIT is defined as a WORD:

BADBIT DW 5

For the instruction:

SHR AX, BADBIT

MASM will return: error A2070: invalid instruction operands

Because for SHL/SHR/SAL/SAR the source operand must be CL or an 8-bit constant (CL or 1 for the 8086/8088).

For the instruction:

MOV CL, BADBIT

MASM will again return: error A2070: invalid instruction operands

Because the operands must be the same size, and in this case they are not.


eschew obfuscation

dedndave

i think what you are trying to do is to shift by a variable count

        mov     ax,SomeValue
        mov     cl,ShiftCount
        shr     ax,cl

notice that, for a word register, shifting 0 to 15 bits is valid
it would be nice if they allowed shifting by 16 for some mathematical uses, but they do not

        SHR AX,BADBIT   ----> gives me an error

is also not allowed - you can shift by an immediate constant, or by a count in CL - those are your only choices

ilian007

I did it with a loop, but not sure if that is the best way ....

                MOV   CX,BADBIT
   MOV   fixingnumber,800h
   MOV   ax,fixingnumber
   CMP   CX,0
   JE    CONT
Shift:
   SHR  AX,1
   DEC   CX
   CMP CX,0
   JG SHIFT
      
cont:   
.............

dedndave

try this...

        mov     ax,fixingnumber
        mov     cx,BADBIT
        shr     ax,cl

ilian007

yeahhh that works!
thank you dedndave :)))

I think that decoding program (i am doing) will be done very soon :P 

thanks everybody :)


dedndave

Ilian,
glad you got it going
you should read and try to understand the info that Steve and Michael have presented to you, as well
they had the clues you needed to make it work
important stuff if you want to get better at assembler