Author Topic: Strange jWasm  (Read 3522 times)

Gunther

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Strange jWasm
« on: December 07, 2014, 06:26:30 AM »
The following code assembles flawless with TASM 4:
Code: [Select]
        .486p

; Publics for PB

        public     CopyString

; Externals

        extrn      Get$Loc: FAR          ; internal PB functions
        extrn      Get$Alloc: FAR


DATA    segment word use16 public 'DATA'

str     db "Text from the Assembly Language Data Segment."

slen    equ $ - str                      ; string length

DATA    ends


code16  segment para public use16
        assume  cs:code16, ds:DATA

; FUNCTION CopyString
; Purpose:         Copy a string into a PB string.
; Input:           None
; Output:          ax = string handle ===> success
;                  ax = 0             ===> failed
CopyString proc far
        push       bp
        mov        bp, sp
        sub        sp, 2                 ; temporary storage
        push       ds
        push       es
        push       di
        push       si
        mov        ax, slen              ; get string length
        push       ax                    ; length onto stack
        call       Get$Alloc             ; allocate string space
        or         ax, ax                ; space available?
        jz         CopyString3           ; no: jump
        mov        [bp-2], ax            ; save new handle
        push       ax                    ; handle at stack
        call       Get$Loc               ; determine string address
                                         ; dx:ax = string address
                                         ; cx    = string length
        mov        es, dx
        mov        di, ax                ; es:di -> destinaton
        mov        si, offset str        ; ds:si -> source
       
CopyString1:

        mov        al, ds:[si]           ; read 1 byte
        mov        byte ptr es:[di], al  ; write 1 byte
        inc        di                    ; update pointers and counter
        inc        si
        dec        cx
        jnz        CopyString1
        mov        ax, [bp-2]            ; load string handle

CopyString2:

        pop        si
        pop        di
        pop        es
        pop        ds
        mov        sp, bp       
        pop        bp
        ret

CopyString3:

        xor        ax, ax                ; indicate error
        jmp        short CopyString2
CopyString endp

code16  ends
        end
There's nothing special. But the DOS version of jWasm produces the following error protocol:
Code: [Select]
ASMTEST.ASM(15) : Error A2218: Syntax error: db
ASMTEST.ASM(38) : Error A2066: Operand is expected
ASMTEST.ASM(50) : Error A2066: Operand is expected
What happens here? I've included the complete source and the running EXE into the archive ASMTEST.ZIP.

Gunther
Get your facts first, and then you can distort them.

FORTRANS

  • Member
  • ****
  • Posts: 945
Re: Strange jWasm
« Reply #1 on: December 07, 2014, 07:37:39 AM »
Hi,

   Just a WAG, but "str" seems to be acting like a reserved word.
Or that is what the errors are telling me.  Try renaming it.

Regards,

Steve N.

Gunther

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Re: Strange jWasm
« Reply #2 on: December 07, 2014, 07:42:50 AM »
Hi Steve,

   Just a WAG, but "str" seems to be acting like a reserved word.
Or that is what the errors are telling me.  Try renaming it.

yes, renaming str in str1 eliminates the first error (strange!). But the other 2 remain.

Gunther
Get your facts first, and then you can distort them.

sinsi

  • Member
  • ****
  • Posts: 996
Re: Strange jWasm
« Reply #3 on: December 07, 2014, 08:00:46 AM »
str shows up in three places, did you rename them all?
I can walk on water but stagger on beer.

Gunther

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Re: Strange jWasm
« Reply #4 on: December 07, 2014, 12:50:01 PM »
Hi sinsi,

str shows up in three places, did you rename them all?

that's it.  :t That was my fault. By renaming, jWasm assembles now without error messages, but with errors. I've included the new source under this post. It is 16-bit code inside a 16-bit segment.The procedure is declared FAR, which needs the complete address (segment:offset) and not only the offset. The resulting EXE with the jWasm OBJ file crashes. Here are the reasons:

  • jWasm generates false addresses for the EXTERNAL procedures.
         
Code: [Select]
     call       Get$Loc = 9A 00000000se
     
     That's the right way what TASM does. jWasm produces for the same sequenz:
     
Code: [Select]
     call       Get$Loc = 669A000000000000
   
    [/li]
  • jWasm doesn't generate the appropriate RET instruction although the entire procedure is declared as FAR.
I've included both listing files (tasm.txt and jwasm.txt) into the archive LISTING.ZIP. So what's wrong? The EXE generated with the TASM OBJ file works fine.

Gunther
Get your facts first, and then you can distort them.

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Strange jWasm
« Reply #5 on: December 07, 2014, 12:57:53 PM »
it would seem that JwAsm doesn't know to use a RETF in a FAR proc
just use explicit form of RETF

sinsi

  • Member
  • ****
  • Posts: 996
Re: Strange jWasm
« Reply #6 on: December 07, 2014, 01:58:04 PM »
What if you remove the .486 from the start? Jwasm seems to be using a 66h override.
I can walk on water but stagger on beer.

jj2007

  • Member
  • *****
  • Posts: 7559
  • Assembler is fun ;-)
    • MasmBasic
Re: Strange jWasm
« Reply #7 on: December 07, 2014, 06:52:27 PM »
JWasm seems to work, but where is the linker supposed to find the externals?

Code: [Select]
*** Assemble 16-bit app using JWasm /c /omf /Fo "ASMTEST" ***
JWasm v2.12pre, Feb 18 2014, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.

Tmp_File.asm: 81 lines, 2 passes, 0 ms, 0 warnings, 0 errors
*** Link using link16   ***

Microsoft (R) Segmented Executable Linker  Version 5.60.339 Dec  5 1994
Copyright (C) Microsoft Corp 1984-1993.  All rights reserved.

LINK : warning L4021: no stack segment

ASMTEST.obj(Tmp_File.asm) : error L2029: 'Get$Loc' : unresolved external
ASMTEST.obj(Tmp_File.asm) : error L2029: 'Get$Alloc' : unresolved external

LINK : warning L4038: program has no starting address

There were 2 errors detected
*** Link error ***

Gunther

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Re: Strange jWasm
« Reply #8 on: December 07, 2014, 08:55:44 PM »
Dave,

it would seem that JwAsm doesn't know to use a RETF in a FAR proc
just use explicit form of RETF

Yes that works. But this is weak.

sinsi,

What if you remove the .486 from the start? Jwasm seems to be using a 66h override.

I'll try that.

Jochen,

JWasm seems to work, but where is the linker supposed to find the externals?

No, not really. What I'm doing here is to call an internal PB procedure from assembly language. The OBJ file must be linked into the PB EXE; that's the compiler's job. No external linker is needed. Are you sure that jWasm generates the right address format for the external procedures (without prefix 66h and as normal segment:offset)? Could you provide the listing file, please?

Gunther
Get your facts first, and then you can distort them.

jj2007

  • Member
  • *****
  • Posts: 7559
  • Assembler is fun ;-)
    • MasmBasic
Re: Strange jWasm
« Reply #9 on: December 08, 2014, 03:30:31 AM »
What I'm doing here is to call an internal PB procedure from assembly language. The OBJ file must be linked into the PB EXE; that's the compiler's job. No external linker is needed.

No PB.exe on this machine, sorry...

nidud

  • Member
  • *****
  • Posts: 1371
    • https://github.com/nidud/asmc
Re: Strange jWasm
« Reply #10 on: December 08, 2014, 03:37:23 AM »
Gunther, this is wrong:
Code: [Select]
.486p
If you need to use .386 instructions, use:
Code: [Select]
.code
.386
or in this case
Code: [Select]
code16  segment para public use16
        assume  cs:code16, ds:DATA
.486p

removing this generate this code
Code: [Select]
0000000E  9A00000000 call    Get$Alloc


Gunther

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Re: Strange jWasm
« Reply #11 on: December 08, 2014, 05:11:23 AM »
Hi nidud,

yes, I've figured out it in the mean time. It works now fine, see attached file WORKAROUND.ZIP.

Gunther
Get your facts first, and then you can distort them.