EASy68K
http://www.easy68k.com/EASy68Kforum/

Wrong assembly code for subi.b (solved)
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=5&t=948
Page 1 of 1

Author:  Olivier De Smet [ Sat Jan 15, 2011 8:41 am ]
Post subject:  Wrong assembly code for subi.b (solved)

With the following code :

Code:
--------------------------------------------------------------

   ORG   $1000
START:            ; first instruction of program

   subi.b   #$02,$820.w
   subi.b   #$04,$8210004

   MOVE.B   #9,D0
   TRAP   #15      ; halt simulator

* Variables and Strings

   END   START      ; last line of source
--------------------------------------------------------------


I got the following result :

Code:
--------------------------------------------------------------
00001000 Starting Address
Assembler used: EASy68K Editor/Assembler v5.6.1
Created On: 15/01/2011 09:37:43

00000000                             1 
00001000                             2          ORG     $1000
00001000                             3  START:                          ; first instruction of program
00001000                             4 
00001000  5538 0820                  5          subi.b  #$02,$820.w
00001004  5939 08210004              6          subi.b  #$04,$8210004
0000100A                             7 
0000100A  103C 0009                  8          MOVE.B  #9,D0
0000100E  4E4F                       9          TRAP    #15             ; halt simulator
00001010                            10 
00001010                            11  * Variables and Strings
00001010                            12 
00001010                            13          END     START           ; last line of source

No errors detected
1 warning generated


SYMBOL TABLE INFORMATION
Symbol-name         Value
-------------------------
START               1000

--------------------------------------------------------------


which is wrong for the two subi (wrong opcode and missing immediate value)

The assembler choose to use subq opcode, but is there a way to avoid this ?

Did someone has the same bug ?

Thanks in advance

Olivier

Author:  clive [ Sat Jan 15, 2011 3:23 pm ]
Post subject: 

This kind of behaviour is quite common in 68K assemblers where multiple opcode encodings can have the same effective function. They usually pick the shortest form as it would save 4 cycles per word. Typically they fold addresses, or convert local JSR's to BSR's, etc.

Disassembling the EASy68K code
Code:
$00001000   subq.b   #2,$0820.w
$00001004   subq.b   #4,$08210004.l

Your code assembled, and some equivalents, with the OASYS assembler
Code:
   13  0:00000040  043800020820                 subi.b  #$02,$820
   14  0:00000046  0439000408210004             subi.b  #$04,$8210004
   15
   16  0:0000004E  55380820                     sub.b  #$02,$820
   17  0:00000052  593908210004                 sub.b  #$04,$8210004
   18
   19  0:00000058  55380820                     subq.b  #$02,$820
   20  0:0000005C  593908210004                 subq.b  #$04,$8210004

Motorola/Bosworth
Code:
00001000                        org $1000

00001000 0438 0002 0820    subi.b   #$02,$820.w
00001006 0439 0004 0821    subi.b   #$04,$8210004
         0004

0000100e 0438 0002 0820    sub.b   #$02,$820.w
00001014 0439 0004 0821    sub.b   #$04,$8210004
         0004

0000101c 5538 0820         subq.b   #$02,$820.w
00001020 5939 0821 0004    subq.b   #$04,$8210004

                                end
                ----  Symbol table ----
       Name                       Value       Type
       ----                       -----       ----


Number of symbols = 0

MRI 7.0
Code:
33   000000CA 0438 0002 0820            subi.b  #$02,$820
34   000000D0 0439 0004 0821            subi.b  #$04,$8210004
              0004
35
36   000000D8 5538 0820                 sub.b  #$02,$820
37   000000DC 5939 0821 0004            sub.b  #$04,$8210004
38
39   000000E2 5538 0820                 subq.b  #$02,$820
40   000000E6 5939 0821 0004            subq.b  #$04,$8210004

Aztec 3.6B
Code:
    31 0032:  0438 0002 0820            subi.b  #$02,$820
    32 0038:  0439 0004 0821            subi.b  #$04,$8210004
       003e:  0004
    33 0040:
    34 0040:  5538 0820                 sub.b  #$02,$820
    35 0044:  5939 0821 0004            sub.b  #$04,$8210004
    36 004a:
    37 004a:  5538 0820                 subq.b  #$02,$820
    38 004e:  5939 0821 0004            subq.b  #$04,$8210004

Author:  Olivier De Smet [ Sat Jan 15, 2011 8:48 pm ]
Post subject: 

yes, I know about this kind of behavior, but I want to re-assemble some code, so I want to have the EXACT binary, even with non optimal forms.

Is there a way to ask for that in the assembler of easy68k ?

Olivier

Author:  clive [ Sat Jan 15, 2011 10:47 pm ]
Post subject: 

All assemblers have their own quirks, to assure an absolute byte for byte reassembly of some third party code you'd probably need you use the same tools. Then again some opcodes will be interpreted differently in a monolithic assembler file than multiple ones with external references resolved at link time. This is especially true of addresses, which will almost always be assumed to be long. Or single pass assemblers that make a similar choice with forward references, or even multi pass ones which leave space for long form, but back patch the short forms with trailing NOP's to avoid phase errors.

Overriding the immediate value with a .L in EASy68K resolves your specific issue.
Code:
00001000                             7          ORG     $1000
00001000                             8  START:                          ; first instruction of program
00001000                             9
00001000  0438 0004 1234            10          subi.b  #4.L,$1234
00001006  0439 0002 12345678        11          subi.b  #2.L,$12345678

Author:  Olivier De Smet [ Sun Jan 16, 2011 9:36 am ]
Post subject: 

Thanks clive, problem solved :)

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/