flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > [SOLVED] How to produce .OBJ file for Pelles C

Author
Thread Post new topic Reply to topic
wht36



Joined: 18 Sep 2005
Posts: 106
wht36
Inspired by Vortex tiny C startup library I am trying to do something similar but using FASM. However, when I tried to convert his source to FASM format, I seemed to hit a dead end. Here is Vortex's code
Code:
.386
.model flat,stdcall
option casemap:none

ExitProcess       PROTO :DWORD
GetCommandLineA     PROTO 
GetCommandLine        equ <GetCommandLineA>

main         PROTO C :DWORD,:DWORD

GPTR = 40h

.data?
hMem db 512 dup(?)

.code
mainCRTStartup:

 push    esi
 push    edi
 push    ebx
 mov     esi,OFFSET hMem
     lea     edi,[esi+256]
       invoke  GetCommandLine
      lea     edx,[eax-1]
 xor     eax,eax
     mov     ch,32
       mov     bl,9
scan:
   inc     edx
 mov     cl,byte PTR [edx]
   or      cl,cl
       jz      finish
      cmp     cl,32
       je      scan
        cmp     cl,9
        je      scan
        inc     eax
 mov     dword PTR [esi],edi
 add     esi,4
restart:
       mov     cl,byte PTR [edx]
   or      cl,cl
       jz      finish
      cmp     cl,ch
       je      end_of_line
 cmp     cl,bl
       je      end_of_line
 cmp     cl,34
       jne     @f
  xor     ch,32
       xor     bl,9
        jmp     next_char
@@:    
    mov     byte PTR [edi],cl
   inc     edi
next_char:
       inc     edx
 jmp     restart
end_of_line:
 mov     byte PTR [edi],0
    inc     edi
 jmp     scan    
finish:
     pop     ebx
 pop     edi
 pop     esi
 invoke  main,eax,ADDR hMem
  invoke  ExitProcess,eax

END mainCRTStartup    

*Edit* Here's my code and it's working!
Code:
format MS COFF

public mainCRTStartup as '__mainCRTStartup'
extrn '__imp__GetCommandLineA@0' as GetCommandLine:dword
extrn '__imp__ExitProcess@4' as ExitProcess:dword
extrn '_main' as main:dword


section '.text' code readable executable
mainCRTStartup:

 push    esi
 push    edi
 push    ebx
 mov     esi,hMem
    lea     edi,[esi+256]
       call    [GetCommandLine]
    lea     edx,[eax-1]
 xor     eax,eax
     mov     ch,32
       mov     bl,9
scan:
   inc     edx
 mov     cl,[edx]
    or      cl,cl
       jz      finish
      cmp     cl,32
       je      scan
        cmp     cl,9
        je      scan
        inc     eax
 mov     [esi],edi
   add     esi,4
restart:
       mov     cl,[edx]
    or      cl,cl
       jz      finish
      cmp     cl,ch
       je      end_of_line
 cmp     cl,bl
       je      end_of_line
 cmp     cl,34
       jne     @f
  xor     ch,32
       xor     bl,9
        jmp     next_char
@@:    
    mov     [edi],cl
    inc     edi
next_char:
       inc     edx
 jmp     restart
end_of_line:
 mov     byte [edi],0
        inc     edi
 jmp     scan    
finish:
     pop     ebx
 pop     edi
 pop     esi
 push    hMem
        push    eax
 call    main
        push    eax
 call    [ExitProcess]

section '.bss' readable writeable
hMem db 512 dup(?)    
The code assembles fine into obj and links okay with Pelles C.

Notes: Pelles C will merge .text & .bss sections. It doesn't seem to recognize section data directive (so take the "data" word out). It seems to want 2 underscores for the public function, and main is called without [].


Description: Test file (both console_vortex and console_wht works)
Download
Filename: crt_test.zip
Filesize: 3.47 KB
Downloaded: 426 Time(s)

Post 01 Jul 2011, 08:29
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Image
Version: 6.00.4
Post 01 Jul 2011, 18:01
View user's profile Send private message Reply with quote
wht36



Joined: 18 Sep 2005
Posts: 106
wht36
Er... the version of Pelles C I used is v6.50 release 4. Not sure if it will work, but try opening main.c and then put in console_wht.obj kernel32.lib msvcrt.lib in the Project options>Library and object files entry. And choose console for the subsystem and X86 for the Machine.
Post 03 Jul 2011, 04:52
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.