Jump to content
IGNORED

Smartbranching question


Primordial Ooze

Recommended Posts

According to the bataribasic online reference turning on smartbranching will reduce the code size of goto statements at the cost of speed and making the assembly code harder to read. I would like to know if it also effects the gosub command as both are very similar and peform similar actions?

 

Sincerely,

 

Open Source Pong

Link to comment
Share on other sites

According to the bataribasic online reference turning on smartbranching will reduce the code size of goto statements at the cost of speed and making the assembly code harder to read. I would like to know if it also effects the gosub command as both are very similar and peform similar actions?

 

Sincerely,

 

Open Source Pong

It does not affect goto by itself, and does not affect gosub at all.

 

With smartbranching off, if you try to use a statement like "if x=4 then 20" it may or may not work, depending how far away line 20 is. Using "if x=4 then goto 20" will always work, but at the cost of some space. "then 20" always uses 6 bytes, but "then goto 20" always uses 9 bytes. It doesn't sound like much but it does add up.

 

With smartbranching on, you may always use "if x=4 then 20" and bB will insert conditional directives in the assembly code to automatically determine if it should use "then" or "then goto" internally, and will use the 6-byte version if it can, but in doing so, the assembly code will be much more obfuscated.

 

To compare, "if x=4 then 20" with smartbranching off compiles to:

		 LDA x
	CMP #4
	beq .20

But with smartbranching on, it compiles to:

		LDA x
	CMP #4
 if ((* - .20) < 127) && ((* - .20) > -128)
	BEQ .20
 else
	bne .1skip20
	jmp .20
.1skip20
endif

If you don't even intend to look at the assembly code, you can leave smartbranching on and never worry about where to use "then goto."

Link to comment
Share on other sites

i save 3 bytes per "if goto" statement but, i lose x ticks per "fix" with smartbranching turned on right?

 

Sincerely,

 

Open Source Pong

Not sure what you mean by "ticks." If you never want to look at the assembly, with smartbranching on, you won't lose anything, and can only save ROM space.

 

But, you don't always save 3 bytes. That only happens if the target label in an if-then statement is somewhat near. If it's far away, you will use just as much space as an if-then goto statement.

Link to comment
Share on other sites

i save 3 bytes per "if goto" statement but, i lose x ticks per "fix" with smartbranching turned on right?

Not sure what you mean by "ticks."

He means cycles-- ticks of the CPU clock. ;)

 

You always save with smartbranching-- you save on cycles as well as bytes. That is to say, you never *lose* bytes or cycles with smartbranching turned on.

 

You know, it might make sense to have smartbranching turned on by default, and then make the user specifically turn it off if they don't want to use it. I know you were thinking the compiler directives would make the code more difficult to read, but (1) there are a lot of compiler directives in the code anyway, (2) most bB users don't ever look at the compiled assembly code anyway, and (3) most users would probably prefer that smatrbranching be turned on automatically so they don't have to worry about trying to remember to turn it on.

 

Michael

Link to comment
Share on other sites

By ticks i mean the amount of processing time the action takes. I believe the max ticks for the atari 2600 is 2700 ticks, anything higher then that and the game will jitter, shake and roll. Also SeaGtGruff answered my question about smartbranching not affecting game speed.

 

Sincerely,

 

Open Source Pong

Edited by Open Source Pong
Link to comment
Share on other sites

By ticks i mean the amount of processing time the action takes. I believe the max ticks for the atari 2600 is 2700 ticks, anything higher then that and the game will jitter, shake and roll. Also SeaGtGruff answered my question about smartbranching not affecting game speed.

 

Sincerely,

 

Open Source Pong

Aha. As SeaGtGruff said, smartbranching will not use any extra clock cycles either. The longer code you see consists of an assembler directive to select one set of code or another. Not all of that code actually gets compiled into the final binary.

Link to comment
Share on other sites

By ticks i mean the amount of processing time the action takes. I believe the max ticks for the atari 2600 is 2700 ticks, anything higher then that and the game will jitter, shake and roll. Please let me know if turning on smartbranching will decrease my games speed due to the additional assembly code required by smartbranching.

 

Sincerely,

 

Open Source Pong

Smartbranching doesn't require additional assembly code. What it does is add *conditional* code that's used only by the assembler, while the assembler is converting the assembly op-codes into binary machine code. So the "additional" code never makes it into the final binary code, although you can see it in the assembly listing.

 

For example:

 

   IFCONST do_it_this_way
	 LDA #1
	 STA some_RAM_location
  ELSE
	 LDA #2
	 STA some_RAM_location
  ENDIF

If you use the variable name "do_it_this_way" somewhere in your program, then DASM will compile your code with the first version-- otherwise, it will compile your code with the second version. Either way, you only get one version, not both. The "extra code" doesn't make its way into the final binary, but it does affect what the final binary will have in it.

 

Michael

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...