Jump to content

Recommended Posts

Hi y'all!

 

I have the following code:

 

processor 6502

org $033C ;SYS 828

LDA #$48

JSR $FFD2

LDA #$49

JSR $FFD2

 

 

This prints "hi", but when I call this from basic:

 

100 for j = 1 to 10

105 sys 828

110 next j

 

... it only prints "HI" one time (using VICE emulator), or it is printing it 10 times one on top of the other, I'm not sure.

 

The question really is, why doesn't it print: HIHIHIHIHIHIHIHIHIHI ???

 

 

 

Thanks,

 

 

 

JR

Link to comment
https://forums.atariage.com/topic/203692-c64-asm-question/
Share on other sites

Okay, a little more help for the ASM impaired please...

 

Now that I think about it, I'm not sure about something....

 

Why DO you need the RTS? Why must we return from the subroutine (I think that is what RTS does)?

 

Does that return the program back to memory location 033C to start all over again?

 

And you mentioned that in my original iteration, the program probably hit a BRK and ended, but where is the BRK located in the program?

 

Thanks!

 

 

JR

Link to comment
https://forums.atariage.com/topic/203692-c64-asm-question/#findComment-2615375
Share on other sites

Why DO you need the RTS? Why must we return from the subroutine (I think that is what RTS does)?

 

Because by calling the routine with a SYS command you've basically started a subroutine and without the RTS the processor doesn't know when to hand control back to the program doing the calling.

 

And you mentioned that in my original iteration, the program probably hit a BRK and ended, but where is the BRK located in the program?

 

There's no way for machine code to know that your code had ended after the second JSR $ffd2 so it just carries on fetching whatever is in memory after that point and trying to execute it. Since the memory is usually filled with patterns of $00 and $ff after powering up, it'll almost certainly hit one of those; $ff isn't a valid command so does nothing when executed, $00 is BRK.

 

BRK forces an interrupt to occur and can be used for debugging purposes, in your program's case it did pretty much the equivalent of slam the Run/Stop and Restore keys.

Link to comment
https://forums.atariage.com/topic/203692-c64-asm-question/#findComment-2615583
Share on other sites

JR, since your ASM routine resides in the cassette buffer, the 64 just executes whatever random data happens to be in the buffer after returning from your second JSR $FFD2. In those cases, it's always just a matter of time before it runs into an unintentional BRK instruction and stops.

Link to comment
https://forums.atariage.com/topic/203692-c64-asm-question/#findComment-2617278
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...