Jump to content
  • Advertisement
  • entries
  • comments
  • views

Assembly! Oh Noes!

Sign in to follow this  


Well, I've jumped headfirst into assembly programming for the Propeller, and let me tell you it's been quite the radical change for me. On the one hand, I miss nice things like generic lists, exceptions, and OOP. On the other, assembly has some cool things built in that you just can't do with higher level languages.

Take a look at this short snippet of PASM (Propeller ASseMbly) that I wrote while creating pong.

mins player1_position, #16 wc
if_b mov player1_speed, #0

maxs player1_position, #112 wz, wc
if_a mov player1_speed, #0

What we have here is bounds checking on player1's paddle. The first line says, whichever value (player1's position or the number 16) is greater, take it and store it in the first location. So effectively, the mins instruction (min for signed numbers) will do a lower bounds cap on player1_position, with 16 being that lower bound.

The wc is one of two special flags that each instruction can use to affect further operations (the other is wz). In this case, specifying wc tells the instruction that when it performs the check, if value1 (player1_position) was less than value2 (16), write a '1' into the C register. Otherwise, write a '0'. So, in this case, if the value was less, it means that the position got capped (aka, we ran into a wall), so reset the speed back to 0.

The next two lines of course do the opposite, in that they cap the position on an upper bound, and if a collision occured, reset the speed. Note that we need wc AND wz here, since wc still gets written if the value is lower, and wz gets written if the values are the same. The if_a instruction checks if C isn't set and Z isn't set (ie. the value wasn't lower and the value wasn't the same), which is the same thing as saying the value was greater.

Now let's look at the equivalent C/C++/C# code:

if( player1_position < 16 )
player1_position = 16;
player1_speed = 0;
else if( player1_position > 112 )
player1_position = 112;
player1_speed = 0;

Ah. Much more readable. But almost much more verbose, and much more space-hungry. While I wouldn't want to go around programming in ASM all the time, it IS nice to try something new and get a taste for it. And in a small scale project like Pong, on a simple microchip instead of a very complex PC, I don't mind the lower level language.

That said, I still want to get some sort of scripting language set up that will let me compile down to this stuff. Hopefully that's on the horizon, but for now, I need to press onward and finish this Pong game. Once that's done, I'm not sure which project I should work on next. Any ideas or suggestions for cool old school games to make on it would be welcome. I'm thinking something like PacMan would be a next step. I thought of going with a Breakout clone, but that's practically the same thing as Pong.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!