Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'd like to multiply a vector by -1


mul    r0,    r0,    -1

When I try this, I get this error message:

SimpleShaderA.vsh(20,17): error X2000: syntax error : unexpected integer '1l'

How can I specify -1 in my (first) shader program?

share|improve this question
Why are you writing assembly shaders? Modern shader models (4+) do not allow you to do this, and unless you have a very compelling need to achieve a clever effect on a very low-end card you'll probably learn more writing in HLSL. –  Josh Petrie Oct 10 '11 at 15:24
i've been set an assignment that uses assembly shaders to teach us the math more than anything else ;) –  user3643 Oct 10 '11 at 15:55

1 Answer 1

up vote 2 down vote accepted

The mul assembly instruction takes registers as inputs, not constants. You can do this instead

def c0, -1, -1, -1, -1
mul r0, r0, c0

which uses the def instruction to define a constant vector in register c0 and uses that as the second multiplicand to mul.

You could also use swizzling on the c0 register, so you could put different constants you may need to multiply by in c0's components. You can also just write the multiplication in terms of c0 and assign it values via the Set***ShaderConstant* APIs.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.