04 January 2020, 19:42 | #1 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Direct PC-offset in assembler
What code would you expect to be generated, when writing
Code:
section code,code lea 2(pc),a0 rts Code:
org $0 lea 2(pc),a0 rts Many assemblers (Devpac doesn't) would encode the offset of 2 directly into the instruction, making the LEA effectively load the address of RTS. Is this an often used feature? I'm currently working on improving the absolute ORG-mode in vasm and the second example gives me headaches, because labels and numbers are both becoming absolute. (The advantage is that any arithmetic operation will be allowed with labels.) |
04 January 2020, 19:48 | #2 |
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
|
I would expect the code in both cases to be generated as lea *+2(pc),a0. I wouldn't ever use something like this though.
|
04 January 2020, 20:45 | #3 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
hmm, I would consider 3 different cases, but I change the ORG to $100 otherwise there would be accidentally two assembly with same encoding for ORG $0
|
04 January 2020, 21:07 | #4 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
In case of
Code:
lea 2(pc),a0 I think that in a real example yould actually write somethinng like Code:
MyLabel: some code here lea MyLabel(pc),a0 |
04 January 2020, 21:08 | #5 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
Make it configurable via flag?
Putting everything aside, I'd say the expected is to encode the offset into instruction. It does make sense to me, since you are not referencing a label/symbol so the additional -2 adjustment for the opcode shouldn't be carried out. But if you make it relative to *, I don't think it's wrong either. Just like devpac, asm-one family interprets it that way as well, so that's what I'd expect as the outcome. But theoretically, I find it 'less accurate'. In such cases I'd generally go with how it already works (asm-one), but it's an interesting question to me (I'm working on something related), and I'd make it configurable with the default set to devpac-compatible. |
04 January 2020, 21:26 | #6 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Thanks for the input. My feeling is also that an expression without any label or external symbol in it should be encoded directly, without subtracting the PC.
But what about this? Code:
VECTAB equ $1000 org $100 lea VECTAB(pc),a0 (I would also encode it directly, which may be irritating.) |
04 January 2020, 21:33 | #7 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
Why should this be any different than lea 2(pc).
Code:
lea 2(pc),a0 Code:
VECTAB EQU 2 lea VECTAB(pc),a0 IMO the difference is only wether its a lable, meaning I want to point to the specified address, vs. a constant meaning I want that value. You should mention this in the doc, though. |
04 January 2020, 21:52 | #8 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
When I specify the ORG directive I want a direct access to this memory location. If I want anyway a related to PC ptr I can use *. (or a label for every other cases) For normal SECTION, directly encoding the value is acceptable. EDIT: apart, this is hacky code in Amiga Last edited by ross; 04 January 2020 at 22:06. Reason: better explained |
|
04 January 2020, 22:27 | #9 |
Going nowhere
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
|
I personally wouldn't ever use that, i'd directly reference the RTS with a label, I wouldn't ever reference something so close with that code.
|
04 January 2020, 22:29 | #10 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
External symbol (xref), not a 'regular' EQU/SET/= symbol. And also I wasn't sufficiently specific when I said label/symbol earlier.
So if it's a label or xref, use pc-relative addressing, otherwise encode specified offset. |
04 January 2020, 22:49 | #11 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
Maybe a bit OT, but what does the asterisk mean? Don't think I've seen that addressing mode before.
|
04 January 2020, 22:51 | #12 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
* = current address
|
04 January 2020, 22:57 | #13 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
|
04 January 2020, 23:00 | #14 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
i.e. Code:
lea *(pc),a0 rts dc.w $41fa,$fffe Last edited by ross; 04 January 2020 at 23:07. Reason: i.e. |
|
04 January 2020, 23:02 | #15 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Ross and Sparhawk have a point, expecting to handle 1234(pc) and label(pc) equally. It would be much more logical and also much easier to implement (I spent the last two days on terrible hacks for supporting direct encoding when there is no label in the expression). Also Volker urges me to refrain from any special handling.
So the question is also: how many old source texts would it break if 1234(pc) would be seen as a reference to address 1234 in absolute ORG sections? Probably not so many, when I read the answers here...? I guess something like "JMP (2,pc,d0)" can be sometimes seen in jump tables, although I agree that I would always use a label or the '*'-symbol myself. |
04 January 2020, 23:06 | #16 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
|
04 January 2020, 23:08 | #17 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
|
04 January 2020, 23:20 | #18 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
The problem with "lea 2(pc)" is that it kind of defeats the purpose of using an assembler in the first place, if somebody expectes a direct encoding.
So you have some code like this: Code:
lea <target without label>(pc),a0 move.w ... jsr bla btst bla beq somewhere ... <target without label> move.l #1,d0 Maybe somebody has an example where this indeed would be usefull? |
04 January 2020, 23:30 | #19 | ||
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
Quote:
On 000 offset is so tiny that in any case even using an absolute location would be inconvenient. It doesn't occur to me for normal SECTIONs... |
||
05 January 2020, 21:43 | #20 |
Registered User
Join Date: Nov 2006
Location: Stockholm, Sweden
Posts: 237
|
I expect that blah in blah(pc) or (blah,pc) to be a reference to a symbol or an absolute address. I expect it to never be a literal displacement value. If it ever can be a displacement value (like it is in blah(an)) then there is room for misinterpretation. I want the assembler to point out potential mistakes to me.
Therefore, I expect the following results: Code:
section code,code lea label(pc),a0 label: rts Code:
section code,code lea $1234(pc),a0 rts Code:
ORG $100 lea label(pc),a0 label: rts Code:
ORG $100 lea $1234(pc),a0 label: rts If I ever want to encode an displacement (like, "read from 128 bytes ahead") then I would use a *+number encoding, like this: Code:
section code,code lea *+128(pc),a0 label: rts Code:
ORG $100 lea *+128(pc),a0 label: rts I don't know how good this particular strategy is for other legacy sources. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Scanlines offset in WinUAE | lbg83430 | support.WinUAE | 9 | 05 November 2018 15:27 |
Calculate offset using labels | Beska | Coders. Asm / Hardware | 7 | 09 May 2016 18:56 |
It seem the JIT direct mode is not work in fs-uae. direct mode is important | bernd roesch | support.FS-UAE | 27 | 20 September 2015 21:44 |
gfxbase negative offset | Asman | Coders. System | 14 | 28 May 2015 23:24 |
Program Counter with Offset - why? | Jherek Carnelia | Coders. General | 26 | 21 March 2011 10:49 |
|
|