Jump to content
IGNORED

Write Register


Recommended Posts

In my travels I am coming across two programming statement of which one I understand completely and the 2nd I need help with.

 

I understand Call WRITE_REGISTER, It is self explanatory.

 

However I keep coming across this in many of the older games.

JP WRITE_REGISTER.
Of course it does the same thing but how do we return from this Jump?
I can make an educated guess that at the end of the routine there is a RET command that would what, return it to the last call before the JP command?

 

Is there something in Write Register that adjusts the stack pointer or does it go through the BIOS and find it's way back.

I just wanted to know if anyone has encountered this and what did you find out.

 

TIA

CC

Link to comment
Share on other sites

3 hours ago, Captain Cozmos said:

I can make an educated guess that at the end of the routine there is a RET command that would what, return it to the last call before the JP command?

This is my understanding.  I like to think of JP (and JR, etc.) as being smaller hops inside the same larger/longer function (assuming a mental model of C code) which I loosely consider "everything between the CALL and the RET".  But of course in asm you can do things that don't easily map to C code.  So if you arrange your CALLs just right and you know a certain jump will always be made during a particular set of circumstances, you can save yourself an extra CALL/RET pair, which is a nice optimization.

Link to comment
Share on other sites

On 8/21/2022 at 11:01 PM, Captain Cozmos said:

In my travels I am coming across two programming statement of which one I understand completely and the 2nd I need help with.

 

I understand Call WRITE_REGISTER, It is self explanatory.

 

However I keep coming across this in many of the older games.

JP WRITE_REGISTER.
Of course it does the same thing but how do we return from this Jump?
I can make an educated guess that at the end of the routine there is a RET command that would what, return it to the last call before the JP command?

 

Is there something in Write Register that adjusts the stack pointer or does it go through the BIOS and find it's way back.

I just wanted to know if anyone has encountered this and what did you find out.

 

TIA

CC

At the end of an asm function you have RET instruction. If you call a subroutine just before you RET, you'll made a double jump (one to call subroutine and one of your RET). To avoid this,you can do a JUMP to subroutine instead CALL it to save clock cycles. There's a lot of optimizations to apply. Another is to use JP instead JR which is 3 bytes long instead 2 but it's faster (JR needs to calculate the relative address, JP not). "OR a" to test the accumulator, "XOR a" to clean it (instead LD a,0) and so on... 

 

 

  • 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...
 Share

  • Recently Browsing   0 members

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