Coding question

emulators, hardware and classic software for atom + system machines
Post Reply
highfell
Posts: 24
Joined: Sat Feb 29, 2020 8:36 am
Contact:

Coding question

Post by highfell » Wed Apr 01, 2020 10:02 pm

I am trying to learn assembler coding using a an old 6502 assembler language book and have got a 156 Assembler error caused by a forward BCC jump.

The error code suggests that to resolve the issue I need to initialise the value of the label to P before assembling , but I have no idea what to do.

Can someone help me please ?

thanks

dp11
Posts: 1068
Joined: Sun Aug 12, 2012 9:47 pm
Contact:

Re: Coding question

Post by dp11 » Wed Apr 01, 2020 10:29 pm

If you are using BASIC look up the OPT directive.

If you are using an assembler make sure your forward reference are less <128 bytes away.

User avatar
IanS
Posts: 1199
Joined: Mon Aug 31, 2009 7:02 pm
Contact:

Re: Coding question

Post by IanS » Wed Apr 01, 2020 10:38 pm

Does this thread help - viewtopic.php?f=2&t=18695

Check the section on "Two-Pass Assemply" in the Atomic Theory & Practise" 23.7 on page 172.

viewtopic.php?f=32&t=6370

Note that DIM P(-1) is defined each time round the loop.

highfell
Posts: 24
Joined: Sat Feb 29, 2020 8:36 am
Contact:

Re: Coding question

Post by highfell » Thu Apr 02, 2020 5:05 pm

Thanks Ian. I now understand the process of trying to initialise P to the labels but no success as yet. I still get the same error when the assembler runs when it works out the link to a label. It seems though that the workaround of using P+X or P-Y will work, so I will try this next.

User avatar
IanS
Posts: 1199
Joined: Mon Aug 31, 2009 7:02 pm
Contact:

Re: Coding question

Post by IanS » Thu Apr 02, 2020 5:19 pm

Can you post a small example, it's difficult to help further without a bit more info.

highfell
Posts: 24
Joined: Sat Feb 29, 2020 8:36 am
Contact:

Re: Coding question

Post by highfell » Thu Apr 02, 2020 6:08 pm

IanS wrote:
Thu Apr 02, 2020 5:19 pm
Can you post a small example, it's difficult to help further without a bit more info.
Thanks.

As long as no one laughs ! I am trying to learn assembly language so have entered a multiplication programme from a old 6502 assembly programming book, so i can try and understand and build on it. Screen shots to follow.

User avatar
tricky
Posts: 4231
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Coding question

Post by tricky » Thu Apr 02, 2020 6:23 pm

Did you try something like:

Code: Select all

for p=0 to 3 step 3
{Opt p
RTS
}
I only use beebasm, so appologies if my syntax is off.

highfell
Posts: 24
Joined: Sat Feb 29, 2020 8:36 am
Contact:

Re: Coding question

Post by highfell » Thu Apr 02, 2020 6:24 pm

Image
Attachments
Muiliplier atom 2.jpg
Muiliplier atom 2.jpg (8.99 KiB) Viewed 396 times
Muiliplier atom 1.jpg
Muiliplier atom 1.jpg (9.92 KiB) Viewed 396 times

User avatar
hoglet
Posts: 9091
Joined: Sat Oct 13, 2012 7:21 pm
Location: Bristol
Contact:

Re: Coding question

Post by hoglet » Thu Apr 02, 2020 6:58 pm

You need to assemble the code twice.

Add a line 12:

Code: Select all

12 FOR I=0 TO 1
This must be just before the DIM P(-1).

And a line 185:

Code: Select all

185 NEXT I
That will allow the forward reference to AA2 to be properly resolved in the second pass.

Also, don't forget to add an RTS at the end!

Dave

User avatar
IanS
Posts: 1199
Joined: Mon Aug 31, 2009 7:02 pm
Contact:

Re: Coding question

Post by IanS » Thu Apr 02, 2020 7:10 pm

tricky wrote:
Thu Apr 02, 2020 6:23 pm
Did you try something like:

Code: Select all

for p=0 to 3 step 3
{Opt p
RTS
}
I only use beebasm, so appologies if my syntax is off.
Note the forum it's in, this is an Atom question. No OPT on the Atom.

highfell
Posts: 24
Joined: Sat Feb 29, 2020 8:36 am
Contact:

Re: Coding question

Post by highfell » Thu Apr 02, 2020 7:25 pm

hoglet wrote:
Thu Apr 02, 2020 6:58 pm
You need to assemble the code twice.

Add a line 12:

Code: Select all

12 FOR I=0 TO 1
This must be just before the DIM P(-1).

And a line 185:

Code: Select all

185 NEXT I


That will allow the forward reference to AA2 to be properly resolved in the second pass.

Also, don't forget to add an RTS at the end!

Dave
Thanks so much , but not sure this will work since I don’t get an Out of Range message but an Error 156 ,
I don’t get an a chance to run the assembler code twice. Am I correct ?

User avatar
hoglet
Posts: 9091
Joined: Sat Oct 13, 2012 7:21 pm
Location: Bristol
Contact:

Re: Coding question

Post by hoglet » Thu Apr 02, 2020 7:50 pm

highfell wrote:
Thu Apr 02, 2020 7:25 pm
Thanks so much , but not sure this will work since I don’t get an Out of Range message but an Error 156 ,
I don’t get an a chance to run the assembler code twice. Am I correct ?
The two passes are still needed, but you are correct.

I think the cause of your ERROR 156 is the use of AA as a label.

I think what's happening is the assembler is getting confused between your AA labels and the accumulator addressing mode. It thinks you are trying to do BCC A, which is illegal, hence the error 156.

Try changing this to something else, for example LL.

It's basically a bug in the assembler, albeit a rather obscure one!

Dave

User avatar
tricky
Posts: 4231
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Coding question

Post by tricky » Thu Apr 02, 2020 8:46 pm

Sorry, I didn't look past the title, but I would have got it from the screen shot.

highfell
Posts: 24
Joined: Sat Feb 29, 2020 8:36 am
Contact:

Re: Coding question

Post by highfell » Thu Apr 02, 2020 10:14 pm

hoglet wrote:
Thu Apr 02, 2020 7:50 pm
highfell wrote:
Thu Apr 02, 2020 7:25 pm
Thanks so much , but not sure this will work since I don’t get an Out of Range message but an Error 156 ,
I don’t get an a chance to run the assembler code twice. Am I correct ?
The two passes are still needed, but you are correct.

I think the cause of your ERROR 156 is the use of AA as a label.

I think what's happening is the assembler is getting confused between your AA labels and the accumulator addressing mode. It thinks you are trying to do BCC A, which is illegal, hence the error 156.

Try changing this to something else, for example LL.

It's basically a bug in the assembler, albeit a rather obscure one!

Dave
Thanks Dave - yep changed to the label to LL and no longer got the 156 error. Also needed your for next loop as you suggested in order to get it to assemble correctly .

User avatar
1024MAK
Posts: 9904
Joined: Mon Apr 18, 2011 5:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: Coding question

Post by 1024MAK » Fri Apr 03, 2020 10:56 am

Any source code that has labels where the value of the label is not known on the first pass, will need the assembler to go through the code a second time. On the second time, now all label values should be know, so the assembler can correctly code forward jumps, branches etc. Hence at one time commercial assemblers often were advertised as two pass assemblers.

Mark

Post Reply

Return to “acorn atom and acorn system series”