Baron-von-Riedesel / JWasm

Masm compatible assembler
107 stars 24 forks source link

Spurious segment overrides for LODSB, CMPSW, etc. without operands #8

Closed tkchia closed 4 years ago

tkchia commented 4 years ago

Hello @Baron-von-Riedesel,

Thank you for your fix (https://github.com/Baron-von-Riedesel/JWasm/commit/bdaff8f72c0ad6bd7d57a195ec6b84c8f003f10b) for the lack of segment overrides for LODS, CMPS, and MOVS I had earlier reported at https://github.com/JWasm/JWasm/issues/211 .

However, I am now getting an opposite problem with your updated code: a simple LODSB, LODSW, MOVSB, MOVSW, CMPSB, or CMPSW without operands may now sometimes get an extra CS: or ES: segment override, even though there should not be one.

Here is a test input that shows the problem:

CGROUP  GROUP   CODE
DGROUP  GROUP   DATA
EGROUP  GROUP   EXTRA

DATA    SEGMENT PUBLIC
DWLAB   DW  0
DBLAB   DB  0
DATA    ENDS

EXTRA   SEGMENT PUBLIC
EWLAB   DW  0
EBLAB   DB  0
EXTRA   ENDS

CODE    SEGMENT PUBLIC
    ASSUME  CS:CGROUP,DS:DGROUP,ES:EGROUP
CWLAB   DW  0
CBLAB   DB  0
    MOV CWLAB,1
    MOV CBLAB,1
    MOV DWLAB,1
    MOV DBLAB,1
    MOV EWLAB,1
    MOV EBLAB,1
    LODSW
    LODSB
    INT 3
    LODS    CWLAB
    LODS    CBLAB
    LODS    DWLAB
    LODS    DBLAB
    LODS    EWLAB
    LODS    EBLAB
    MOVSW
    MOVSB
    INT 3
    MOVS    EWLAB,CWLAB
    MOVS    EBLAB,CBLAB
    MOVSW
    MOVSB
    INT 3
    MOVS    EWLAB,DWLAB
    MOVS    EBLAB,DBLAB
    MOVSW
    MOVSB
    INT 3
    MOVS    EWLAB,EWLAB
    MOVS    EBLAB,EBLAB
    CMPSW
    CMPSB
    INT 3
    CMPS    CWLAB,EWLAB
    CMPS    CBLAB,EBLAB
    CMPS    DWLAB,EWLAB
    CMPS    DBLAB,EBLAB
    CMPS    EWLAB,EWLAB
    CMPS    EBLAB,EBLAB
    XLAT    CBLAB
    XLAT    DBLAB
    XLAT    EBLAB
CODE    ENDS
    END

Output:

$ jwasm -Zm -Zne -Zv8 -mh foo.asm
JWasm v2.14pre, Jun 19 2020, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.

foo.asm: 62 lines, 2 passes, 1127 ms, 0 warnings, 0 errors
$ wdis foo.o
Module: foo.asm
GROUP: 'DGROUP' _DATA,DATA
GROUP: 'CGROUP' CODE
GROUP: 'EGROUP' EXTRA

Segment: FOO_TEXT WORD USE16 00000000 bytes

Routine Size: 0 bytes,    Routine Base: FOO_TEXT + 0000

No disassembly errors

Segment: _DATA WORD USE16 00000000 bytes

Segment: DATA PARA USE16 00000003 bytes
0000                L$1:
0000  00 00                                           ..
0002                L$2:
0002  00                                              .

Segment: EXTRA PARA USE16 00000003 bytes
0000                L$3:
0000  00 00                                           ..
0002                L$4:
0002  00                                              .

Segment: CODE PARA USE16 00000060 bytes
0000                L$5:
0000  00 00                                           ..
0002                L$6:
0002  00                                              .
0003  2E C7 06 00 00 01 00      mov     word ptr cs:L$5,0x0001
000A  2E C6 06 02 00 01         mov     byte ptr cs:L$6,0x01
0010  C7 06 00 00 01 00         mov     word ptr DGROUP:L$1,0x0001
0016  C6 06 02 00 01            mov     byte ptr DGROUP:L$2,0x01
001B  26 C7 06 00 00 01 00      mov     word ptr es:L$3,0x0001
0022  26 C6 06 02 00 01         mov     byte ptr es:L$4,0x01
0028  26 AD             lods        word ptr es:[si]
002A  26 AC             lods        byte ptr es:[si]
002C  CC                int     0x03
002D  2E AD             lods        word ptr cs:[si]
002F  2E AC             lods        byte ptr cs:[si]
0031  AD                lodsw
0032  AC                lodsb
0033  26 AD             lods        word ptr es:[si]
0035  26 AC             lods        byte ptr es:[si]
0037  A5                movsw
0038  A4                movsb
0039  CC                int     0x03
003A  2E A5             movs        word ptr [di],word ptr cs:[si]
003C  2E A4             movs        byte ptr [di],byte ptr cs:[si]
003E  2E A5             movs        word ptr [di],word ptr cs:[si]
0040  2E A4             movs        byte ptr [di],byte ptr cs:[si]
0042  CC                int     0x03
0043  A5                movsw
0044  A4                movsb
0045  A5                movsw
0046  A4                movsb
0047  CC                int     0x03
0048  26 A5             movs        word ptr [di],word ptr es:[si]
004A  26 A4             movs        byte ptr [di],byte ptr es:[si]
004C  26 A7             cmps        word ptr es:[si],word ptr [di]
004E  26 A6             cmps        byte ptr es:[si],byte ptr [di]
0050  CC                int     0x03
0051  2E A7             cmps        word ptr cs:[si],word ptr [di]
0053  2E A6             cmps        byte ptr cs:[si],byte ptr [di]
0055  A7                cmpsw
0056  A6                cmpsb
0057  26 A7             cmps        word ptr es:[si],word ptr [di]
0059  26 A6             cmps        byte ptr es:[si],byte ptr [di]
005B  2E D7             xlat        word ptr cs:[bx]
005D  D7                xlatb
005E  26 D7             xlat        word ptr es:[bx]

Routine Size: 96 bytes,    Routine Base: CODE + 0000

No disassembly errors

The string instructions just before each int 0x03 should by right have no segment overrides.

Thank you!

Baron-von-Riedesel commented 4 years ago

Confirmed. Even a crash of the assembler was possible. It should be fixed now.

tkchia commented 4 years ago

Thanks @Baron-von-Riedesel !

XVilka commented 4 years ago

@Baron-von-Riedesel are you the original author? I could transfer you rights to JWasm GitHub organization since it really belongs to you. I opened it because the original site was down:

Also the site https://jwasm.info is at https://github.com/JWasm/jwasm.github.io

Baron-von-Riedesel commented 4 years ago

Yes, I'm the original author.

I could transfer you rights to JWasm GitHub organization since it really belongs to you.

No, thanks! There are already too many places where outdated versions of jwasm are offered.

On Tue, Jul 7, 2020 at 7:12 AM Anton Kochkov notifications@github.com wrote:

@Baron-von-Riedesel are you the original author? I could transfer you rights to JWasm GitHub organization since it really belongs to you. I opened it because the original site was down:

https://github.com/JWasm

Also the site https://jwasm.info is at https://github.com/JWasm/jwasm.github.io

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

tkchia commented 4 years ago

Hello @Baron-von-Riedesel,

Yes, I'm the original author.

I could transfer you rights to JWasm GitHub organization since it really belongs to you.

No, thanks! There are already too many places where outdated versions of jwasm are offered.

While we are at it, may I know if you intend to make further updates to JWlink?

I am currently using @JWasm's repository for JWlink because it happens to have a working port to Linux which I need.

Thank you!

Baron-von-Riedesel commented 4 years ago

While we are at it, may I know if you intend to make further updates to JWlink?

Yes, although with low priority. Creating a fully working 64-bit linux version might need some adjustments.