6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 9:21 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Jan 05, 2012 2:50 am 
Offline

Joined: Wed Jan 04, 2012 11:59 pm
Posts: 5
I'm developing a 65816 assembler, and I've noticed an oddity with at least some other assemblers. Suppose we have this code:

bra $12

...what does it mean? Is the $12 relative or absolute? To me it makes sense that $12 is taken as an absolute address and so, assuming a PC of 0 (for the sake of example), this will emit 80 10 (since the absolute address $12 gets converted to the relative address $10). That way labels can simply resolve to absolute addresses as they do in every other context and it should just work. But the assemblers xkas and WLA don't see it that way; they output the operand verbatim, producing 80 12. Thus they behave differently depending on whether the operand is an integer literal or a label. (bass, a later 65816 assembler by the same author as xkas -- rewritten from scratch I believe -- does emit 80 10.)

Is there any 'right' way for this to behave? Or is it just an implementation detail, since (as far as I know) proper assembly code should never need to pass an integer literal to a relative branch instruction anyway?


Last edited by furrykef on Thu Jan 05, 2012 2:58 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 05, 2012 5:27 am 
Offline

Joined: Sun Nov 08, 2009 1:56 am
Posts: 411
Location: Minnesota
I vote for 'just works'. I think it's probably simpler to write an assembler that way anyway, as to have two different behaviors means there has to be additional code to distinguish seperate cases.

But it's your assembler in the end, and you can make it do whatever you want. That's part of the fun.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 05, 2012 9:28 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
My 6502/65816 assembler treats the operand to a relative branch as a absolute address and derives the relative offset from it.

I don't think I've ever come across an assembler for any processor with relative branches that works differently from this.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 05, 2012 10:33 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
That sounds pretty normal. I think most assemblers would take it as an absolute address, and, if you wanted for example to branch forward past an instruction, without a label, you'd do something like BNE $+2.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jan 06, 2012 5:18 am 
Offline

Joined: Wed Jan 04, 2012 11:59 pm
Posts: 5
Thanks, guys. I think I posted in the wrong forum, though... perhaps it should be moved to the Programming forum?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jan 06, 2012 5:54 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
no big deal-- it's ok.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: hoglet and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: