Aseembler problems with #< and >#

Discuss all aspects of programming here. From 8-bit through to modern architectures.
User avatar
sydney
Posts: 1986
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Aseembler problems with #< and >#

Postby sydney » Fri Sep 01, 2017 6:27 pm

The following two snippets of code have got me pretty confused. I've included the beebasm output too.
The first one seem to be assembling incorrectly, I'd expect &9A to hold the lsb and &9B to hold the msb like in the second snippet. Is my understanding of this wrong?

Code: Select all

.start_rooms   
   lda #<room1   
   sta current_room
   lda #>room1
   sta current_room+1

.room1      ;(&1986)
   EQUB 0,0,0,0,0,0,0,0,0
.room2
   EQUB 0,0,0,0,0,0,0,0,0
rts

.start_rooms
     09D3   A9 19      LDA #&19
     09D5   85 9A      STA &9A
     09D7   A9 86      LDA #&86
     09D9   85 9B      STA &9B
     09DB   60         RTS

Code: Select all

MAPSTART = &26A0
.fill_map_with_space
   lda #<MAPSTART ;(&26a0)
   sta map_pointer
   lda #>MAPSTART
   sta map_pointer+1
   ldy #0
   
.fill_map_with_space
     0A56   A9 A0      LDA #&A0
     0A58   85 98      STA &98
     0A5A   A9 26      LDA #&26
     0A5C   85 99      STA &99
     0A5E   A0 00      LDY #&00

User avatar
MartinB
Posts: 4555
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity

Re: Aseembler problems with #< and >#

Postby MartinB » Fri Sep 01, 2017 7:02 pm

I think the difference is occurring because in the second, you have explicitly declared MAPSTART as big-endian (hi first) but in the first, room1 is an implicit address which is naturally stored as little-endian (lo first). Thus, your apparently common syntax produces opposite results.

User avatar
tricky
Posts: 1916
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Aseembler problems with #< and >#

Postby tricky » Fri Sep 01, 2017 7:27 pm

Are you sure that you have the correct address for .room1?
I use LO() and HI() with beebasm.

SteveF
Posts: 439
Joined: Fri Aug 28, 2015 8:34 pm

Re: Aseembler problems with #< and >#

Postby SteveF » Fri Sep 01, 2017 8:32 pm

I don't understand this. I couldn't quite assemble the source from your post, but here's a tweaked version which I don't think is significantly different:

Code: Select all

steven@nine:~/src/beebasm$ cat z9.6502
current_room = &9a

org &900
.start_rooms   
   lda #<room1   
   sta current_room
   lda #>room1
   sta current_room+1

org &1986
.room1      ;(&1986)
   EQUB 0,0,0,0,0,0,0,0,0
.room2
   EQUB 0,0,0,0,0,0,0,0,0
rts

and when I assemble that:

Code: Select all

steven@nine:~/src/beebasm$ ./beebasm -do z9.ssd -v -i z9.6502
.start_rooms
     0900   A9 86      LDA #&86
     0902   85 9A      STA &9A
     0904   A9 19      LDA #&19
     0906   85 9B      STA &9B
.room1
     1986   00
     1987   00
     1988   00
     1989   00
     198A   00
     198B   00
     198C   00
     198D   00
     198E   00
.room2
     198F   00
     1990   00
     1991   00
     1992   00
     1993   00
     1994   00
     1995   00
     1996   00
     1997   00
     1998   60         RTS
Processed file 'z9.6502' ok
warning: no SAVE command in source file.

&9A does have the low byte.

I think tricky's advice to use lo()/hi() instead of </> is good style, but I think you are using them the correct way round - beebasm's about.txt says:
LO(val) or <val Return lsb of 16-bit expression (like 'val MOD 256')
HI(val) or >val Return msb of 16-bit expression (like 'val DIV 256')


Can you please post a complete (but ideally not too large) beebasm input file which demonstrates the problem? Something more or less like the fragment I've got above, except that works and yours doesn't for reasons we need to figure out...

Cheers.

Steve

SteveF
Posts: 439
Joined: Fri Aug 28, 2015 8:34 pm

Re: Aseembler problems with #< and >#

Postby SteveF » Fri Sep 01, 2017 8:33 pm

PS Can you try giving the '-d' option to beebasm to tell it to dump the global symbol table? It would be interesting to see what it thinks the value of room1 is in your example. In my example it says:

Code: Select all

[{'room1':6534L,'room2':6543L,'start_rooms':2304L}]

and 6534=&1986 as we'd expect.

User avatar
sydney
Posts: 1986
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Re: Aseembler problems with #< and >#

Postby sydney » Fri Sep 01, 2017 8:54 pm

LO and HI seems to have fixed it. I'll post more later once the wife drifts off to sleep!

User avatar
Rich Talbot-Watkins
Posts: 1117
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca

Re: Aseembler problems with #< and >#

Postby Rich Talbot-Watkins » Fri Sep 01, 2017 9:20 pm

Which version of BeebAsm are you on? From my release notes:

1.03 Bugfix: Corrected the unary < and > operators to correspond to HI and LO as appropriate.


I never use < and > as they always confused the hell out of me (precisely why I created HI and LO), and evidenced by the fact that I got them the wrong way round in the first release :lol:

Looking at expression.cpp, it looks like > corresponds to HI, and < corresponds to LO, so you're using them the right way round in your snippet. Maybe just check that you're on the latest version.

Incidentally something else which I never fixed (but which would be really easy to do so) is to decrease the precedence of < and > to 1. In other assemblers, you should be able to write LDA #<blah+1 as if (blah+1) was parenthesised.

User avatar
sydney
Posts: 1986
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Re: Aseembler problems with #< and >#

Postby sydney » Fri Sep 01, 2017 9:34 pm

Rich Talbot-Watkins wrote:Which version of BeebAsm are you on? From my release notes:

1.03 Bugfix: Corrected the unary < and > operators to correspond to HI and LO as appropriate.


1.08 - I'm pretty sure I downloaded it from github

I never use < and > as they always confused the hell out of me (precisely why I created HI and LO), and evidenced by the fact that I got them the wrong way round in the first release :lol:


I always start off using HI and LO but forget to add the # and end up trying < and > then realise the # is missing!

Looking at expression.cpp, it looks like > corresponds to HI, and < corresponds to LO, so you're using them the right way round in your snippet. Maybe just check that you're on the latest version.

Incidentally something else which I never fixed (but which would be really easy to do so) is to decrease the precedence of < and > to 1. In other assemblers, you should be able to write LDA #<blah+1 as if (blah+1) was parenthesised.

I'm pretty sure I use 'LDA #<blah+1' elsewhere in the program so I'll change everything to HI and LO.

User avatar
Rich Talbot-Watkins
Posts: 1117
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca

Re: Aseembler problems with #< and >#

Postby Rich Talbot-Watkins » Fri Sep 01, 2017 9:35 pm

Hmmm having looked at it a bit more closely, I understand the problem - there should be no difference between the first two snippets, but they give different results. Which platform are you running on out of interest? Not an old big-endian PowerPC Mac?

(Edit: not that I can imagine why it ought to make the slightest difference)

User avatar
sydney
Posts: 1986
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Re: Aseembler problems with #< and >#

Postby sydney » Fri Sep 01, 2017 9:41 pm

SteveF wrote:PS Can you try giving the '-d' option to beebasm to tell it to dump the global symbol table? It would be interesting to see what it thinks the value of room1 is in your example. In my example it says:

Code: Select all

[{'room1':6534L,'room2':6543L,'start_rooms':2304L}]

and 6534=&1986 as we'd expect.


Well. I put everything back the way it was before trying HI and LO and it now assembles correctly. I've been banging my head against a wall all afternoon over this!

...'printstring':6468L,'room1':6534L,'room2':6543L...


Return to “programming”

Who is online

Users browsing this forum: No registered users and 2 guests