Jump to content
Dr Do

Newbie trying assembly: help please!

Recommended Posts

Posted (edited)

** EDIT: Problem described below now solved **

 

Sorry if this is the wrong place to post newbie questions like the one that follows.  I've been trying to learn 6502 assembly, but it hasn't taken me long to get stuck.

 

I was trying one of the examples from "Machine Language for Beginners", which was supposed to put ten "A"s on the screen.  I soon  realised that the code in the book needed tweaking to work, and so after a bit of trial and error came up with this...

 

		*=20000

        ldy #10
loop	lda #33
	   sta (88),Y
	   dey
	   cpy #0
	   bne loop
        brk

(Excuse the tab spacing, it was lined up properly in the code edit window!)

 

If I compile this in ATasm and then attempt to run the object code in the Atari800Win emulator using DOS Option L, it will display 10 "A"s as intended but then crash straight away.  Changing the compile address from $4E20 (for example to $0600) or changing the last instruction to "brk" (or removing it completely) leads to the emulated machine crashing as soon as the object code is started.

 

But switching to WUDSN (with the opening statement changed to "org" for the MADS compiler) makes the code behave differently; there, it causes nothing to happen except the debugger opening with a message about an "illegal operation".  Sometimes, if I run it and then start Altirra separately then it will behave the same way as Atari800Win did.  Changing "brk" to "rts" though will cause WUDSN to open up Altirra automatically, which will then display the As but immediately reboot into BASIC - which makes sense...I think?

 

All this is leaving me scratching my head, but I'm guessing there's a simple solution.  Any suggestions please?

Edited by Dr Do

Share this post


Link to post
Share on other sites
Posted (edited)

You need to change the BRK instruction to something else, such as an endless loop ("completed jmp completed") or a jump to another location to give the control back to, for instance DOS.

 

I think that using RTS with a 

  *=$2E2
  .word 20000

might return control to DOS, but it will depend on the DOS or the loader you use.

 

If you are just creating an XEX and run it from the PC with a double click or from your developing framework, probably the best option is the endless loop for tests.

Edited by vitoco
typo
  • Thanks 1

Share this post


Link to post
Share on other sites
12 hours ago, vitoco said:

You need to change the BRK instruction to something else, such as an endless loop ("completed jmp completed") or a jump to another location to give the control back to, for instance DOS.

 

I think that using RTS with a 

  *=$2E2
  .word 20000

might return control to DOS, but it will depend on the DOS or the loader you use.

 

If you are just creating an XEX and run it from the PC with a double click or from your developing framework, probably the best option is the endless loop for tests.

Now why didn't I think of that? Thanks vitoco, problem solved.

Share this post


Link to post
Share on other sites
Posted (edited)

For what it's worth - the lda #33 could stay outside the loop start to save cycles.

The cpy #0 isn't needed.   Practically any instruction that modifies a register or memory location (RTI being one exception) will modify some of the P flags to reflect what's happened.

So for a DEY, the Z and N flags will reflect zero or negative state.

Edited by Rybags
  • Like 1
  • Thanks 1

Share this post


Link to post
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...