flamewing / asl-releases

Improved/bugfixed version of Alfred Arnold's The Macro Assembler AS
http://john.ccac.rwth-aachen.de:8000/as/
GNU General Public License v2.0
20 stars 2 forks source link

potential moveq solution/workaround #9

Open Awuwunya opened 3 years ago

Awuwunya commented 3 years ago

Since the moveq issue was talked about elsewhere, I had an idea on a simple way to specify how moveq should be treated. If you want to specifically ignore the 32-bit extension logic, you could use moveq.b. While its not really according to 68k spec, the .b could be used to specify that you don't care that values >= $80 will cause 32-bit sign extension. On the opposite, using moveq.l could be used to say that you want the assembler NOT ALLOW 32-bit extension for >= $80 values. moveq by itself could either show a warning or not allow as well. This way, the programmer can be explicit about their intentions and can use positive values for sake of convenience.

flamewing commented 3 years ago

That is one interesting idea. I will have to think about it.

flamewing commented 3 years ago

Here is the state of what I am thinking:

  1. the proposed solution with hard error on plain moveq (i.e., moveq := moveq.l):

    moveq.b #$80,d0     ; no error, sign extension
    moveq.l #$80,d0     ; error, value stored in register is not what you think it is
    moveq   #$80,d0     ; error, value stored in register is not what you think it is
  2. the proposed solution with warning on plain moveq:

    moveq.b #$80,d0     ; no error, sign extension
    moveq.l #$80,d0     ; error, value stored in register is not what you think it is
    moveq   #$80,d0     ; warning, value stored in register is not what you think it is
  3. as (1) but tacking on the .b or .l on the immediate instead of on the instruction:

    moveq   #$80.b,d0   ; no error, sign extension
    moveq   #$80.l,d0   ; error, value stored in register is not what you think it is
    moveq   #$80,d0     ; error, value stored in register is not what you think it is
  4. as (2) but tacking on the .b or .l on the immediate instead of on the instruction:

    moveq   #$80.b,d0   ; no error, sign extension
    moveq   #$80.l,d0   ; error, value stored in register is not what you think it is
    moveq   #$80,d0     ; warning, value stored in register is not what you think it is

    All options have precedents in 680X0 assembly. The version proposed by @NatsumiFox might imply to a new hacker that only the byte portion would be overwritten; but other than that, all versions introduce new syntax. The error/warning message should probably mention this as an option; maybe the messages could be something like:

For Natsumi's version: Error: sign extension: value stored to register is the sign extension of the value given; use 'moveq.b' instead if you want this

For my version: Error: sign extension: value stored to register is the sign extension of the value given; add a '.b' to the value if you want this

Any thoughts?

Awuwunya commented 3 years ago

I would prefer 1 only because it follows familiar 68k syntax. Maybe the error text could be: Error: moveq writes a sign-extended longword value. Use 'moveq.b' if you want to ignore this error or something like that. Or maybe it could show the value being written in full? when new hackers come across this I think it communicates the right idea about what is actually going on?

flamewing commented 3 years ago

The other option actually also follows 68k syntax, but 68k-family syntax instead of 68000 syntax. For example, the 68020's memory indirect postindexed mode:

move.l  ([10000.l,a3],d4.l*4,20000.l),d7

Though to be fair, these are not immediate fields.

Awuwunya commented 3 years ago

Fair, but for the 68k alone, having one exception like this is just weird, too Then again, link already is weird so it could be better :P

Brainulator9 commented 3 years ago

If it's not too late, I'm in favor of solution 2, with 4 as a possible alternative (assuming both can be implemented), simply because I'd rather not have code that works on every other assembler refuse to build here.