The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: ilian007 on October 21, 2009, 03:51:40 PM

Title: SHR - Shift to the RIGHT ?
Post by: ilian007 on October 21, 2009, 03:51:40 PM
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














Title: Re: SHR - Shift to the RIGHT ?
Post by: FORTRANS on October 21, 2009, 04:23:51 PM
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
Title: Re: SHR - Shift to the RIGHT ?
Post by: MichaelW on October 21, 2009, 04:56:04 PM
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.


Title: Re: SHR - Shift to the RIGHT ?
Post by: dedndave on October 21, 2009, 04:58:30 PM
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
Title: Re: SHR - Shift to the RIGHT ?
Post by: ilian007 on October 21, 2009, 05:04:54 PM
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:   
.............
Title: Re: SHR - Shift to the RIGHT ?
Post by: dedndave on October 21, 2009, 05:08:10 PM
try this...

        mov     ax,fixingnumber
        mov     cx,BADBIT
        shr     ax,cl
Title: Re: SHR - Shift to the RIGHT ?
Post by: ilian007 on October 21, 2009, 05:15:05 PM
yeahhh that works!
thank you dedndave :)))

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

thanks everybody :)

Title: Re: SHR - Shift to the RIGHT ?
Post by: dedndave on October 21, 2009, 09:55:40 PM
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