Viewing disassembly on OSX – Using objdump.

On linux you can use something called objdump. On OSX you need to install binutils. To do that use macports:

sudo port install binutils

For my machine it got installed in:

/opt/local/x86_64-apple-darwin10.8.0/bin/objdump

You can then call it.

/opt/local/x86_64-apple-darwin10.8.0/bin/objdump -M intel -D a.out | grep -A20 main.:

-M puts the disassembly into intel format
-D specifies the file

the pipe to grep prevents looking at the whole listing and the -A20 shows 20 lines following the matched line which is going to be main().

Here is what it outputs:

0000000100000f10 <_main>:
   100000f10:	55                   	push   rbp
   100000f11:	48 89 e5             	mov    rbp,rsp
   100000f14:	48 8d 3d 13 00 00 00 	lea    rdi,[rip+0x13]        # 100000f2e <_puts$stub+0x6>
   100000f1b:	e8 08 00 00 00       	call   100000f28 <_puts$stub>
   100000f20:	c9                   	leave  
   100000f21:	c3                   	ret    

Disassembly of section __TEXT.__symbol_stub1:

0000000100000f22 <_exit$stub>:
   100000f22:	ff 25 10 01 00 00    	jmp    QWORD PTR [rip+0x110]        # 100001038 <_exit$stub>

0000000100000f28 <_puts$stub>:
   100000f28:	ff 25 12 01 00 00    	jmp    QWORD PTR [rip+0x112]        # 100001040 <_puts$stub>

Disassembly of section .cstring:

0000000100000f2e <.cstring>:
   100000f2e:	48                   	rex.W
   100000f2f:	65                   	gs

Interpolation Functions – Smoothstep, Gamma, Bias, Gain

I have been doing some hand coded animations recently and I was sick of having to go into the OSX grapher every time I wanted to come up with a function. I would always repeat work that I have done before. So in order to save time in the future I am going to put up a couple of functions that I think will be useful for tweening.

There is a function who has a value of zero and slope zero at zero, and it has a value one and a slope zero at one. That function is 3x^2 – 2x^3. Or in code y = x*x*(3-2*x);

public static float SmoothStep(float a, float b, float x)
{
    if(x < 0)
        return 0.0f;
    if(x >= b)
        return 1.0f;
 
    x = (x - a)/(b - a); //normalizes x
    return (x*x * (3 - 2*x));
}

There are other functions that are useful when you combine them with other functions that are in the range 0->1.

    public static float gammacorrect(float gamma, float x)
	{
		return Mathf.Pow(x, 1.0f/gamma);
	}

A function that is a lot like gamma is called bias but if its parameters are restricted to the range (0..1) which makes it a lot more intuitive to use than gamma.

    public static float bias(float b, float x)
	{
		return Mathf.Pow(x, Mathf.Log(b)/Mathf.Log(0.5f));
	}

Another useful function that is like smoothstep but you can control its curvature and the slope at the ends is called gain.

    public static float gain(float g, float x)
	{
		if(x < 0.5)
			return bias(1-g,2*x)/2;
		else
			return 1 - bias(1-g,2 - 2*x)/2;
	}

Here is a Mac OSX Grapher project file that shows how to make these graphs. It is an example of using functions and piecewise definitions of graphs.

BiasAndGain.gcx