Author Topic: JWASM question.  (Read 426 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4922
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
JWASM question.
« on: August 17, 2017, 02:30:30 AM »
Since at least some of the guys using UASM used to use Japheth's JWASM, I have a question. Making a simple object module is easy enough to do but I have not succeeded in getting the "-bin" option to work in 64 bit. It works fine in 32 bit so the questions is, is it only for 16 and 32 bit ?

I can get the raw binary output I am after with MASM but its a lot more messing around that what JWASM is capable of doing in 32 bit.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Vortex

  • Member
  • *****
  • Posts: 1723
Re: JWASM question.
« Reply #1 on: August 17, 2017, 04:30:32 AM »
A quick test with the -bin option :

Code: [Select]
option casemap:none
option win64:3
 
.code

StringLen PROC lpszText:QWORD

    mov     r8,1
    xor     rax,rax
    sub     rax,r8
@@:
    add     rax,r8
    movzx   rdx,BYTE PTR [rcx+rax]
    test    rdx,rdx
    jnz     @b
    ret

StringLen ENDP

END

Code: [Select]
uasm64.exe -bin StringLen.asm
UASM v2.38, Aug  4 2017, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.

StringLen.asm(4) : Error A2096: Model is not declared
StringLen.asm(6) : Error A2082: Must be in segment block
StringLen.asm(8) : Error A2082: Must be in segment block
StringLen.asm(9) : Error A2082: Must be in segment block
StringLen.asm(10) : Error A2082: Must be in segment block
StringLen.asm(11) : Error A2082: Must be in segment block
StringLen.asm(12) : Error A2082: Must be in segment block
StringLen.asm(13) : Error A2082: Must be in segment block
StringLen.asm(14) : Error A2082: Must be in segment block
StringLen.asm(15) : Error A2082: Must be in segment block
StringLen.asm(16) : Error A2082: Must be in segment block
StringLen.asm(18) : Error A2142: Unmatched block nesting: StringLen
StringLen.asm: 20 lines, 1 passes, 15 ms, 0 warnings, 12 errors

nidud

  • Member
  • *****
  • Posts: 1408
    • https://github.com/nidud/asmc
Re: JWASM question.
« Reply #2 on: August 17, 2017, 04:59:18 AM »
Code: [Select]
.x64
.model  flat, fastcall

.code
option casemap:none
option win64:3

.code

StringLen PROC lpszText:QWORD

    mov     r8,1
    xor     rax,rax
    sub     rax,r8
@@:
    add     rax,r8
    movzx   rdx,BYTE PTR [rcx+rax]
    test    rdx,rdx
    jnz     @b
    ret

StringLen ENDP

END
uasm -bin file.asm

Vortex

  • Member
  • *****
  • Posts: 1723
Re: JWASM question.
« Reply #3 on: August 17, 2017, 05:07:08 AM »
Hi nidud,

Thanks for your help. It works as expected :

Code: [Select]
\tdm-gcc-32\bin\objdump -M intel -b binary -D -m i386:x86-64 StringLen.BIN

StringLen.BIN:     file format binary

Disassembly of section .data:

00000000 <.data>:
   0:   48 83 ec 08             sub    rsp,0x8
   4:   49 c7 c0 01 00 00 00    mov    r8,0x1
   b:   48 33 c0                xor    rax,rax
   e:   49 2b c0                sub    rax,r8
  11:   49 03 c0                add    rax,r8
  14:   48 0f b6 14 08          movzx  rdx,BYTE PTR [rax+rcx*1]
  19:   48 85 d2                test   rdx,rdx
  1c:   75 f3                   jne    0x11
  1e:   48 83 c4 08             add    rsp,0x8
  22:   c3                      ret

nidud

  • Member
  • *****
  • Posts: 1408
    • https://github.com/nidud/asmc
Re: JWASM question.
« Reply #4 on: August 17, 2017, 05:36:14 AM »
Different defaults and configurations:

ml64
Code: [Select]
        push    rbp                                     ; 0000 _ 55
        mov     rbp, rsp                                ; 0001 _ 48: 8B. EC
        mov     r8, 1                                   ; 0004 _ 49: C7. C0, 00000001
        xor     rax, rax                                ; 000B _ 48: 33. C0
        sub     rax, r8                                 ; 000E _ 49: 2B. C0
?_001:  add     rax, r8                                 ; 0011 _ 49: 03. C0
        movzx   rdx, byte ptr [rax+rcx]                 ; 0014 _ 48: 0F B6. 14 08
        test    rdx, rdx                                ; 0019 _ 48: 85. D2
        jnz     ?_001                                   ; 001C _ 75, F3
        leave                                           ; 001E _ C9
        ret                                             ; 001F _ C3

asmc
Code: [Select]
   0:   55                      push   rbp
   1:   48 8b ec                mov    rbp,rsp
   4:   49 c7 c0 01 00 00 00    mov    r8,0x1
   b:   48 33 c0                xor    rax,rax
   e:   49 2b c0                sub    rax,r8
  11:   49 03 c0                add    rax,r8
  14:   48 0f b6 14 08          movzx  rdx,BYTE PTR [rax+rcx*1]
  19:   48 85 d2                test   rdx,rdx
  1c:   75 f3                   jne    0x11
  1e:   c9                      leave
  1f: c3 ret

uasm
Code: [Select]
   0:   48 83 ec 08             sub    rsp,0x8
   4:   49 c7 c0 01 00 00 00    mov    r8,0x1
   b:   48 33 c0                xor    rax,rax
   e:   49 2b c0                sub    rax,r8
  11:   49 03 c0                add    rax,r8
  14:   48 0f b6 14 08          movzx  rdx,BYTE PTR [rax+rcx*1]
  19:   48 85 d2                test   rdx,rdx
  1c:   75 f3                   jne    0x11
  1e:   48 83 c4 08             add    rsp,0x8
  22: c3 ret

option win64:3
asmc
Code: [Select]
   0:   48 89 4c 24 08          mov    QWORD PTR [rsp+0x8],rcx
   5:   55                      push   rbp
   6:   48 8b ec                mov    rbp,rsp
   9:   48 83 ec 20             sub    rsp,0x20
   d:   49 c7 c0 01 00 00 00    mov    r8,0x1
  14:   48 33 c0                xor    rax,rax
  17:   49 2b c0                sub    rax,r8
  1a:   49 03 c0                add    rax,r8
  1d:   48 0f b6 14 08          movzx  rdx,BYTE PTR [rax+rcx*1]
  22:   48 85 d2                test   rdx,rdx
  25:   75 f3                   jne    0x1a
  27:   48 83 c4 20             add    rsp,0x20
  2b:   c9                      leave
  2c:   c3                      ret

uasm
Code: [Select]
   0:   48 83 ec 08             sub    rsp,0x8
   4:   49 c7 c0 01 00 00 00    mov    r8,0x1
   b:   48 33 c0                xor    rax,rax
   e:   49 2b c0                sub    rax,r8
  11:   49 03 c0                add    rax,r8
  14:   48 0f b6 14 08          movzx  rdx,BYTE PTR [rax+rcx*1]
  19:   48 85 d2                test   rdx,rdx
  1c:   75 f3                   jne    0x11
  1e:   48 83 c4 08             add    rsp,0x8
  22: c3 ret

asmc
option win64:rsp noauto
Code: [Select]
   0:   49 c7 c0 01 00 00 00    mov    r8,0x1
   7:   48 33 c0                xor    rax,rax
   a:   49 2b c0                sub    rax,r8
   d:   49 03 c0                add    rax,r8
  10:   48 0f b6 14 08          movzx  rdx,BYTE PTR [rax+rcx*1]
  15:   48 85 d2                test   rdx,rdx
  18:   75 f3                   jne    0xd
  1a: c3 ret

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4922
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: JWASM question.
« Reply #5 on: August 17, 2017, 09:58:10 AM »
Thanks nidud,

.x64
.model  flat, fastcall

.code
option casemap:none
option win64:3

Works just fine.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

 NOSTACKFRAME

 slen proc

    db 72,139,193,72,131,232,1,72,131,192,1,76,15,182,16,77
    db 133,210,116,39,72,131,192,1,76,15,182,16,77,133,210,116
    db 26,72,131,192,1,76,15,182,16,77,133,210,116,13,72,131
    db 192,1,76,15,182,16,77,133,210,117,204,72,43,193,195

 slen endp

 STACKFRAME

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

aw27

  • Member
  • ****
  • Posts: 851
  • Let's Make ASM Great Again!
Re: JWASM question.
« Reply #6 on: August 17, 2017, 05:39:05 PM »
Quote
option win64:3
asmc
Code: [Select]
   0:   48 89 4c 24 08          mov    QWORD PTR [rsp+0x8],rcx
...
9:   48 83 ec 20             sub    rsp,0x20

Actually UASM does save the register to the parameter  (mov    QWORD PTR [rsp+0x8],rcx) only if the value is used, otherwise not. Also, UASM does not create shadow space (sub    rsp,0x20) if the function is a leaf.

May be you should think about that nidud (if you want want and have time, of course).

No need to thank me for this info, habran.

habran

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: JWASM question.
« Reply #7 on: August 17, 2017, 06:07:20 PM »
OK, aw27 Thank you ;)
Cod-Father

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4922
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: JWASM question.
« Reply #8 on: August 17, 2017, 06:17:01 PM »
Japheth's JWASM 2.11s did the job fine, utility is finished and works correctly.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

nidud

  • Member
  • *****
  • Posts: 1408
    • https://github.com/nidud/asmc
Re: JWASM question.
« Reply #9 on: August 18, 2017, 12:01:36 AM »
Actually UASM does save the register to the parameter  (mov    QWORD PTR [rsp+0x8],rcx) only if the value is used, otherwise not.

True, but Asmc is a Masm compatible assemblers not a compiler. It also keep compatibility with JWasm with regards to flags used. The default behavior will for this reason emulate MASM if no flags are used.

Quote
Also, UASM does not create shadow space (sub rsp,0x20) if the function is a leaf.

Yes, compilers apply optimizations and produce assembler code based on the high level language used. Assemblers are more logical and predictable in that respect.

Quote
May be you should think about that nidud (if you want want and have time, of course).

The aim of Asmc is to create a rule-based high level language based on C notation by enhancing the HLL section without compromising compatibility with Masm. The latter means the default behavior will be the same.

Code: [Select]
foo proc a:dword
    mov eax,a
    ret
foo endp

StringLen PROC lpszText:QWORD

    xor     ecx,ecx
    call    foo

Masm
Code: [Select]
   0:   55                      push   rbp
   1:   48 8b ec                mov    rbp,rsp
   4:   c9                      leave
   5:   c3                      ret
   6:   55                      push   rbp
   7:   48 8b ec                mov    rbp,rsp
   a:   33 c9                   xor    ecx,ecx
   c:   e8 ef ff ff ff          call   0x0
  11:   49 c7 c0 01 00 00 00    mov    r8,0x1
  18:   48 33 c0                xor    rax,rax
  1b:   49 2b c0                sub    rax,r8
  1e:   49 03 c0                add    rax,r8
  21:   48 0f b6 14 08          movzx  rdx,BYTE PTR [rax+rcx*1]
  26:   48 85 d2                test   rdx,rdx
  29:   75 f3                   jne    0x1e
  2b:   c9                      leave
  2c: c3 ret

Asmc
Code: [Select]
   0:   55                      push   rbp
   1:   48 8b ec                mov    rbp,rsp
   4:   c9                      leave
   5:   c3                      ret
   6:   55                      push   rbp
   7:   48 8b ec                mov    rbp,rsp
   a:   33 c9                   xor    ecx,ecx
   c:   e8 ef ff ff ff          call   0x0
  11:   49 c7 c0 01 00 00 00    mov    r8,0x1
  18:   48 33 c0                xor    rax,rax
  1b:   49 2b c0                sub    rax,r8
  1e:   49 03 c0                add    rax,r8
  21:   48 0f b6 14 08          movzx  rdx,BYTE PTR [rax+rcx*1]
  26:   48 85 d2                test   rdx,rdx
  29:   75 f3                   jne    0x1e
  2b:   c9                      leave
  2c: c3 ret

Uasm
Code: [Select]
   0:   48 83 ec 08             sub    rsp,0x8
   4:   48 83 c4 08             add    rsp,0x8
   8:   c3                      ret
   9:   48 83 ec 08             sub    rsp,0x8
   d:   33 c9                   xor    ecx,ecx
   f:   e8 ec ff ff ff          call   0x0
  14:   49 c7 c0 01 00 00 00    mov    r8,0x1
  1b:   48 33 c0                xor    rax,rax
  1e:   49 2b c0                sub    rax,r8
  21:   49 03 c0                add    rax,r8
  24:   48 0f b6 14 08          movzx  rdx,BYTE PTR [rax+rcx*1]
  29:   48 85 d2                test   rdx,rdx
  2c:   75 f3                   jne    0x21
  2e:   48 83 c4 08             add    rsp,0x8
  32: c3 ret

My (conservative) thinking is then to preserve this predictability and thus limit the extensions to this logic, so the priorities differ and hence also the result.

However, given my thinking I regard my contribution to the development of Uasm is better preserved by healthy competition rather than being directly involved.

aw27

  • Member
  • ****
  • Posts: 851
  • Let's Make ASM Great Again!
Re: JWASM question.
« Reply #10 on: August 18, 2017, 03:37:10 AM »
Quote
My (conservative) thinking is then to preserve this predictability and thus limit the extensions to this logic, so the priorities differ and hence also the result.

Very deep thought indeed.  :t