Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
2,807 Views

Assembly code generated by ICL for Windows

Hi,

I am trying to use ICL to generate assembly and then do some processing of assembly and finally generate the binary using the updated assembly.  However, this workflow does not work because the assembly generated by ICL seems not acceptable by ML64.exe

Following is output of compiling a simple Hello World style program:

main() {  printf ("test\n"); }

Commands and outputs below:

$ icl /S test.c
Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.2.187 Build 20170213
Copyright (C) 1985-2017 Intel Corporation.  All rights reserved.

test.c

$ icl test.asm
Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.2.187 Build 20170213
Copyright (C) 1985-2017 Intel Corporation.  All rights reserved.

test.asm
 Assembling: test.asm
test.asm(18) : error A2008:syntax error : .1
test.asm(27) : error A2008:syntax error : .5
test.asm(35) : error A2008:syntax error : .2
test.asm(42) : error A2008:syntax error : .3
test.asm(50) : error A2008:syntax error : .main
test.asm(57) : error A2008:syntax error : .main
test.asm(58) : error A2006:undefined symbol : .B1
test.asm(59) : error A2006:undefined symbol : .unwind

Would this be fixable?

Thanks.

david

0 Kudos
27 Replies
Highlighted
2,807 Views

Show the contents of test.asm around line 18.

Can you issue the masm command directly?

Jim Dempsey

0 Kudos
Highlighted
Employee
2,807 Views

 

I don't think this works with Microsoft either (you'd need to use the /Fa option since Microsoft doesn't support /S).

These options actually create a listing file that contains assembly -  not a file that can be parsed by the assembler directly.

 

0 Kudos
Highlighted
2,807 Views

Thanks for the suggestion.  I tried /Fa and it did not work nether (same errors).

15         PUBLIC main
16 ; --- main()
17 main    PROC
18 .B1.1::                         ; Preds .B1.0
19                                 ; Execution count [1.00e+000]

I think the problem is the dotted label.  If I run ML64.exe directly, I got the same errors:

 ml64 test.asm
 Assembling: test.asm
test.asm(18) : error A2008:syntax error : .1
test.asm(27) : error A2008:syntax error : .5
test.asm(35) : error A2008:syntax error : .2
test.asm(42) : error A2008:syntax error : .3
test.asm(50) : error A2008:syntax error : .main
test.asm(57) : error A2008:syntax error : .main
test.asm(58) : error A2006:undefined symbol : .B1
test.asm(59) : error A2006:undefined symbol : .unwind
Microsoft (R) Macro Assembler (x64) Version 12.00.31101.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Thanks for the help.

david

0 Kudos
Highlighted
2,807 Views

It appears to be the "." in .B1.1, .unwind.main.B1_B2 and elsewhere.

For Intel guru: Is there an option to "icl foo.asm" to compile/assemble the .asm with .'s in the symbol names?

Jim Dempsey

0 Kudos
Highlighted
Valued Contributor II
2,807 Views

>>...I don't think this works with Microsoft either (you'd need to use the /Fa option since Microsoft doesn't support /S)... I agree with that and 'icl test.asm' is not going to work. I share 6 examples of using a Macro Assembler by Microsoft ( 32-bit ML and 64-bit ML64 ) and I hope it would help.
0 Kudos
Highlighted
Valued Contributor II
2,807 Views

[ Example 1 ]

;;/////////////////////////////////////////////////////////////////////////////
;; Hello32.asm - 'Hello, World!' 32-bit Test Application
;;
;; Release
;;  ml.exe Hello32.asm     /link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user32.lib /entry:Start /release /out:Hello32.exe
;; Debug
;;  ml.exe Hello32.asm /Zi /link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user32.lib /entry:Start          /out:Hello32D.exe

.586P
.MODEL FLAT, STDCALL

;; include kernel32.inc
;; include user32.inc

 includelib kernel32.lib
 includelib user32.lib

.DATA

 caption db '32-bit Platform', 0
 msg  db 'Hello, World!', 0

.STACK

.CODE

 extern  ExitProcess@4  : PROC
 extern  MessageBoxA@16  : PROC

 public  Start

Start:
 push 0     ; uType = MB_OK
 push offset caption  ; LPCSTR lpCaption
 push offset msg   ; LPCSTR lpText
 push 0     ; hWnd = HWND_DESKTOP
 call MessageBoxA@16

 push eax     ; uExitCode = MessageBox( ... )
 call ExitProcess@4

END

 

0 Kudos
Highlighted
Valued Contributor II
2,807 Views

[ Example 2 ]

;;/////////////////////////////////////////////////////////////////////////////
;; Hello64.asm - 'Hello, World!' 64-bit Test Application
;;
;; Release
;;  ml64.exe Hello64.asm     /link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user32.lib /entry:Start /release /out:Hello64.exe
;; Debug
;;  ml64.exe Hello64.asm /Zi /link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user32.lib /entry:Start          /out:Hello64D.exe

.DATA

 caption db '64-bit Platform', 0
 msg     db 'Hello, World!', 0

.CODE

 extrn MessageBoxA : PROC
 extrn ExitProcess : PROC

 public  Start

Start PROC

 sub  rsp, 28h 

 mov  rcx, 0    ; hWnd = HWND_DESKTOP
 lea  rdx, msg   ; LPCSTR lpText
 lea  r8,  caption  ; LPCSTR lpCaption
 mov  r9d, 0    ; uType = MB_OK
 call MessageBoxA

 add  rsp, 28h

 mov  ecx, eax   ; uExitCode = MessageBox( ... )
 call ExitProcess

Start ENDP

END

 

0 Kudos
Highlighted
Valued Contributor II
2,807 Views

[ Example 3 ]

;;/////////////////////////////////////////////////////////////////////////////
;; HelloWorld32.asm - 'Hello, World!' 32-bit Test Application
;;
;; Release
;;  ml.exe HelloWorld32.asm     /link /subsystem:console /defaultlib:kernel32.lib /entry:Start /release /out:HelloWorld32.exe
;; Debug
;;  ml.exe HelloWorld32.asm /Zi /link /subsystem:console /defaultlib:kernel32.lib /entry:Start          /out:HelloWorld32D.exe

.586P
.MODEL FLAT, STDCALL

.DATA

 handle dword   0h
 msg  db      'Hello, World!', 10, 0
 written dword   0h

.STACK

.CODE

 extern  GetStdHandle@4  : PROC
 extern  WriteConsoleA@20 : PROC
 extern  ExitProcess@4  : PROC

 public  Start

Start:
 push -11
 call GetStdHandle@4          ;; handle = GetStdHandle( -11 )
 mov  handle, eax

 push 0
 push offset written
 push 14
 push offset msg
 push handle
 call WriteConsoleA@20         ;; WriteConsole( handle, &msg[0], 14, &written, 0 )

 push 0
 call ExitProcess@4          ;; ExitProcess( 0 )

END

 

0 Kudos
Highlighted
Valued Contributor II
2,807 Views

[ Example 4 ]

;;/////////////////////////////////////////////////////////////////////////////
;; HelloWorld64.asm - 'Hello, World!' 64-bit Test Application
;;
;; Release
;;  ml64.exe HelloWorld64.asm     /link /subsystem:console /defaultlib:kernel32.lib /entry:Start /release /out:HelloWorld64.exe
;; Debug
;;  ml64.exe HelloWorld64.asm /Zi /link /subsystem:console /defaultlib:kernel32.lib /entry:Start          /out:HelloWorld64D.exe

.DATA

 handle qword 0h
 msg  db  'Hello, World!', 10, 0
 written qword 0h

.CODE

 extern ExitProcess   : PROC
 extern GetStdHandle  : PROC
 extern WriteConsoleA : PROC

 public Start

Start PROC

;; int  3

 sub  rsp, 38h


 mov  ecx, -11
 call GetStdHandle          ;; handle = GetStdHandle( -11 )
 mov  qword ptr handle, rax


 mov  qword ptr [rsp+20h], 0
 lea  r9, qword ptr written
 mov  r8d, 14
 lea  rdx, qword ptr msg
 mov  rcx, qword ptr handle
 call WriteConsoleA          ;; WriteConsole( handle, &msg[0], 14, &written, 0 )


;; xor  ecx, ecx
 mov  ecx, 1
 call ExitProcess           ;; ExitProcess( <return code > )

Start ENDP

END

 

0 Kudos
Highlighted
Valued Contributor II
2,807 Views

[ Example 5 ]

;;/////////////////////////////////////////////////////////////////////////////
;; Powers32.asm
;;
;; Displays powers of 2 from 2^0 to 2^31, one per line, to standard output.
;; ml.exe Powers32.asm /c"
;; link.exe Powers32.obj libc.lib /version:6.1
;; By default, the linker uses "/subsystem:console /entry:mainCRTStartup".
;; The function "mainCRTStartup" is inside libc.lib.  It does some
;; initialization, calls a function "_main" (which will end up in powers.obj)
;; then does more work and finally calls ExitProcess.

        .586P
        .model  flat

        extern  _printf : near
        public  _main

        .data
  format  byte    '%d', 10, 0

        .code
_main:
        push    esi                     ; save registers
        push    edi

        mov     esi, 1                  ; current value
        mov     edi, 31                 ; counter
        
L1:
        push    esi                     ; push value to print
        push    offset format           ; push address of format string
        call    _printf
        add     esp, 8                  ; pop off parameters passed to printf
        add     esi, esi                ; double value
        dec     edi                     ; keep counting
        jnz     L1

        pop     edi
        pop     esi
        ret

        end

 

0 Kudos
Highlighted
Valued Contributor II
2,807 Views

[ Example 6 ]

;;/////////////////////////////////////////////////////////////////////////////
;; Powers64.asm
;; Displays powers of 2 from 2^0 to 2^31, one per line, to standard output.
;; ml64.exe Powers64.asm /c"
;; link.exe Powers64.obj libc.lib /version:6.1
;; ml64.exe Powers64.asm /link C:\PlatformSDK\Lib\AMD64\libc.lib C:\PlatformSDK\Lib\AMD64\bufferoverflowu.lib /subsystem:console /defaultlib:kernel32.lib /entry:main
;; ml64.exe Powers64.asm /link C:\PlatformSDK\Lib\AMD64\libcmt.lib C:\PlatformSDK\Lib\AMD64\bufferoverflowu.lib /entry:main

        extern  printf : proc

        public  main

.DATA
  format  byte    '%d', 10, 0

.CODE

main    PROC

  sub  rsp, 28h

        push    rsi                     ; callee-save registers
        push    rdi

        mov     esi, 1                  ; current value
        mov     edi, 31                 ; counter
        
L1:
        push    rsi                     ; push value to print
  lea     rax, byte ptr format
        push    rax                     ; push address of format string
        call    printf
        add     esp, 8                  ; pop off parameters passed to printf
        add     esi, esi                ; double value
        dec     edi                     ; keep counting
        jnz     L1

        pop     rdi
        pop     rsi

  add  rsp, 28h

        ret

main    ENDP

end

 

0 Kudos
Highlighted
2,807 Views

Hi Sergey,

Thanks for the examples.  Could you tell me the right ICL flags to generate assembly like you attached.  I can see they don't have label prefixed with dots.

Thanks.

david

0 Kudos
Highlighted
Valued Contributor II
2,807 Views

>>...Could you tell me the right ICL flags to generate assembly like you attached... Sources for all these 6 examples are Not generated by Intel C++ compiler. I've implemented these small tests as a spin off of some task related to usage of MASM ( 32-bit and 64-bit ).
0 Kudos
Highlighted
2,807 Views

Sergey Kostrov wrote:

>>...Could you tell me the right ICL flags to generate assembly like you attached...

Sources for all these 6 examples are Not generated by Intel C++ compiler. I've implemented these small tests as a spin off of some task related to usage of MASM ( 32-bit and 64-bit ).

I see.  Does it mean it is not possible to start from C/C++ source, compile to assembly, and then assemble to binary executable?

Thanks for the advice.

david

0 Kudos
Highlighted
Valued Contributor II
2,807 Views

It should be possible and I just did a very quick verification with Example 2. Even if the assembler codes Not generated from C/C++ sources Intel C++ compiler ( 64-bit version ) compiled it. Here is an output: ... C:\WorkTemp\Aaa>dir Volume in drive C is SYSTEM Volume Serial Number is 9661-21BF Directory of C:\WorkTemp\Aaa 11/05/2017 04:59 PM . 11/05/2017 04:59 PM .. 16/10/2016 01:19 PM 918 Hello64.asm 1 File(s) 918 bytes 2 Dir(s) 191,333,371,904 bytes free C:\WorkTemp\Aaa>icl Hello64.asm Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 13.1.0.149 Build 20130118 Copyright (C) 1985-2013 Intel Corporation. All rights reserved. Hello64.asm Assembling: Hello64.asm Microsoft (R) Incremental Linker Version 9.00.30729.01 Copyright (C) Microsoft Corporation. All rights reserved. -out:Hello64.exe Hello64.obj LINK : fatal error LNK1561: entry point must be defined C:\WorkTemp\Aaa> ... An object file was successfully created but since I didn't include any linker directives the Linker failed ( as expected ).
0 Kudos
Highlighted
2,807 Views

To summarize, I think I need the ICL flags to compile C/C++ source into assembly that is compilable by MASM. 

Thanks for the help.

david

0 Kudos
Highlighted
Valued Contributor II
2,807 Views

>>...I think I need the ICL flags to compile C/C++ source into assembly... Take a look at Output, Debug, PCH section of command line options.
0 Kudos
Highlighted
2,807 Views

Sergey Kostrov wrote:

>>...I think I need the ICL flags to compile C/C++ source into assembly...

Take a look at Output, Debug, PCH section of command line options.

There are several flags mentioned in "Output, Debug, PCH section": "/S", "/FAs", "/FAc", "/FA".  I tried them all but none of them work.

/S, /FA, /FAs - assembly generated with bad labels like ".B1.1"

/FAc - no assembly generated.

Please let me know if I missed any flags there.

Thanks a lot.

david

 

 

0 Kudos
Highlighted
Valued Contributor II
2,807 Views

I address my post to Intel C++ compiler team software engineers. Please take a look at the problem because it is Not possible to compile asm-files generated by Intel C++ compiler. I just did a quick verification and instead of '.' ( dots ) in labels:

...
.B1.1::                         ; Preds .B1.0
        sub       rsp, 40                                       ;4.1
        mov       ecx, 3                                        ;4.1
        call      __intel_new_proc_init                         ;4.1
                                ; LOE rbx rbp rsi rdi r12 r13 r14 r15 xmm6 xmm7 xmm8 xmm9 xmm10 xmm11 xmm12 xmm13 xmm14 xmm15
.B1.12::                        ; Preds .B1.1
        stmxcsr   DWORD PTR [32+rsp]                            ;4.1
        or        DWORD PTR [32+rsp], 32832                     ;4.1
        ldmxcsr   DWORD PTR [32+rsp]                            ;4.1
...

underscore '_' needs to be used:

...
.B1_1::                         ; Preds .B1_0
        sub       rsp, 40                                       ;4.1
        mov       ecx, 3                                        ;4.1
        call      __intel_new_proc_init                         ;4.1
                                ; LOE rbx rbp rsi rdi r12 r13 r14 r15 xmm6 xmm7 xmm8 xmm9 xmm10 xmm11 xmm12 xmm13 xmm14 xmm15
.B1_12::                        ; Preds .B1_1
        stmxcsr   DWORD PTR [32+rsp]                            ;4.1
        or        DWORD PTR [32+rsp], 32832                     ;4.1
        ldmxcsr   DWORD PTR [32+rsp]                            ;4.1
...

or something else that would allow to compile asm-file.

 

0 Kudos