flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > lcc-3.6 with fasm backend!!

Author
Thread Post new topic Reply to topic
Tarkin



Joined: 27 Aug 2010
Posts: 22
Tarkin 05 Apr 2011, 19:31
Very Happy

Hello all,
I have successfully modified the nasm patch to lcc (version 3.6) to use fasm as a backend Exclamation
My environment is 32-bit GNU/Linux (Centos 5).

The modified lcc correctly pre-processes, assembles, and links simple C sources,
though GNU/Linux header files give it some headaches.

I am currently testing its suitablilty for operating systems development.
If all goes well, I will try to integrate vlink support,
and/or bootstrap a Linux ANSI standard library.

Comments and questions welcome!
Post 05 Apr 2011, 19:31
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 05 Apr 2011, 19:58
Did you do a comparison of produced executable against one from "normal" lcc (whatever backend asm it uses, I suppose gas)? The "real-world" comparison of assembly-time instruction size optimization might be interesting (supposing original backend doesn't do this).
Post 05 Apr 2011, 19:58
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tarkin



Joined: 27 Aug 2010
Posts: 22
Tarkin 06 Apr 2011, 01:30
vid wrote:
Did you do a comparison of produced executable against one from "normal" lcc (whatever backend asm it uses, I suppose gas)? The "real-world" comparison of assembly-time instruction size optimization might be interesting (supposing original backend doesn't do this).


Not yet. The patch came from nasm, which was fortunate- the nasm and fasm syntaxes were so close, the changes were minimal.

I will preform some comparisons and post the results in a couple of days or so.
Post 06 Apr 2011, 01:30
View user's profile Send private message Reply with quote
Tarkin



Joined: 27 Aug 2010
Posts: 22
Tarkin 08 Apr 2011, 03:17
Ok, I had to switch versions to lcc-4.2
The 3.6 version did NOT have a linux target,
and I found it much easier to upgrade the
nasm (and then fasm) machine descriptions-
I can on-the-fly translate from AT&T to Intel, but
not the other way around...

Along the way, I discovered that the Linux include files
provided by lcc-4.2 include stdarg.h, which compile
printf(...) - which will be very much needed for debuggery!
So, hic sunt dracones:

hello.c:
Code:
/* hello.c */
#include <stdarg.h>
int main(int argc, char *argv[]){
  printf("Hello, World!\n");
  printf("argc     = %d\n",argc);
  printf("argv[0] = %s\n\n",argv[0]);
}

    



stevo@andLinux:/opt/lcc-gas/build/test$ objdump -S -d -Mintel hello
Code:
hello:     file format elf32-i386


Disassembly of section .init:

0804828c <_init>:
 804828c:     55                      push   ebp
 804828d:     89 e5                   mov    ebp,esp
 804828f: 53                      push   ebx
 8048290:     83 ec 04                sub    esp,0x4
 8048293: e8 00 00 00 00          call   8048298 <_init+0xc>
 8048298:       5b                      pop    ebx
 8048299:     81 c3 24 13 00 00       add    ebx,0x1324
 804829f:      8b 93 fc ff ff ff       mov    edx,DWORD PTR [ebx-0x4]
 80482a5: 85 d2                   test   edx,edx
 80482a7: 74 05                   je     80482ae <_init+0x22>
 80482a9:      e8 1e 00 00 00          call   80482cc <__gmon_start__@plt>
 80482ae:      e8 dd 00 00 00          call   8048390 <frame_dummy>
 80482b3:     e8 c8 01 00 00          call   8048480 <__do_global_ctors_aux>
 80482b8:   58                      pop    eax
 80482b9:     5b                      pop    ebx
 80482ba:     c9                      leave  
 80482bb:        c3                      ret    

Disassembly of section .plt:

080482bc <__gmon_start__@plt-0x10>:
 80482bc:   ff 35 c0 95 04 08       push   DWORD PTR ds:0x80495c0
 80482c2:      ff 25 c4 95 04 08       jmp    DWORD PTR ds:0x80495c4
 80482c8:      00 00                   add    BYTE PTR [eax],al
    ...

080482cc <__gmon_start__@plt>:
 80482cc:    ff 25 c8 95 04 08       jmp    DWORD PTR ds:0x80495c8
 80482d2:      68 00 00 00 00          push   0x0
 80482d7:     e9 e0 ff ff ff          jmp    80482bc <_init+0x30>

080482dc <__libc_start_main@plt>:
 80482dc:   ff 25 cc 95 04 08       jmp    DWORD PTR ds:0x80495cc
 80482e2:      68 08 00 00 00          push   0x8
 80482e7:     e9 d0 ff ff ff          jmp    80482bc <_init+0x30>

080482ec <printf@plt>:
 80482ec:      ff 25 d0 95 04 08       jmp    DWORD PTR ds:0x80495d0
 80482f2:      68 10 00 00 00          push   0x10
 80482f7:    e9 c0 ff ff ff          jmp    80482bc <_init+0x30>

Disassembly of section .text:

08048300 <_start>:
 8048300: 31 ed                   xor    ebp,ebp
 8048302: 5e                      pop    esi
 8048303:     89 e1                   mov    ecx,esp
 8048305: 83 e4 f0                and    esp,0xfffffff0
 8048308:  50                      push   eax
 8048309:     54                      push   esp
 804830a:     52                      push   edx
 804830b:     68 10 84 04 08          push   0x8048410
 8048310:       68 20 84 04 08          push   0x8048420
 8048315:       51                      push   ecx
 8048316:     56                      push   esi
 8048317:     68 c0 83 04 08          push   0x80483c0
 804831c:       e8 bb ff ff ff          call   80482dc <__libc_start_main@plt>
 8048321:   f4                      hlt    
 8048322:        90                      nop    
 8048323:        90                      nop    
 8048324:        90                      nop    
 8048325:        90                      nop    
 8048326:        90                      nop    
 8048327:        90                      nop    
 8048328:        90                      nop    
 8048329:        90                      nop    
 804832a:        90                      nop    
 804832b:        90                      nop    
 804832c:        90                      nop    
 804832d:        90                      nop    
 804832e:        90                      nop    
 804832f:        90                      nop

08048330 <__do_global_dtors_aux>:
 8048330: 55                      push   ebp
 8048331:     89 e5                   mov    ebp,esp
 8048333: 53                      push   ebx
 8048334:     83 ec 04                sub    esp,0x4
 8048337: 80 3d 08 96 04 08 00    cmp    BYTE PTR ds:0x8049608,0x0
 804833e:   75 40                   jne    8048380 <__do_global_dtors_aux+0x50>
 8048340:      8b 15 0c 96 04 08       mov    edx,DWORD PTR ds:0x804960c
 8048346:  b8 e0 94 04 08          mov    eax,0x80494e0
 804834b:   2d dc 94 04 08          sub    eax,0x80494dc
 8048350:   c1 f8 02                sar    eax,0x2
 8048353: 8d 58 ff                lea    ebx,[eax-0x1]
 8048356:   39 da                   cmp    edx,ebx
 8048358: 73 1f                   jae    8048379 <__do_global_dtors_aux+0x49>
 804835a:      8d b6 00 00 00 00       lea    esi,[esi+0x0]
 8048360:   8d 42 01                lea    eax,[edx+0x1]
 8048363:   a3 0c 96 04 08          mov    ds:0x804960c,eax
 8048368:    ff 14 85 dc 94 04 08    call   DWORD PTR [eax*4+0x80494dc]
 804836f:     8b 15 0c 96 04 08       mov    edx,DWORD PTR ds:0x804960c
 8048375:  39 da                   cmp    edx,ebx
 8048377: 72 e7                   jb     8048360 <__do_global_dtors_aux+0x30>
 8048379:      c6 05 08 96 04 08 01    mov    BYTE PTR ds:0x8049608,0x1
 8048380:   83 c4 04                add    esp,0x4
 8048383: 5b                      pop    ebx
 8048384:     5d                      pop    ebp
 8048385:     c3                      ret    
 8048386:        8d 76 00                lea    esi,[esi+0x0]
 8048389:   8d bc 27 00 00 00 00    lea    edi,[edi+eiz*1+0x0]

08048390 <frame_dummy>:
 8048390:    55                      push   ebp
 8048391:     89 e5                   mov    ebp,esp
 8048393: 83 ec 08                sub    esp,0x8
 8048396: a1 e4 94 04 08          mov    eax,ds:0x80494e4
 804839b:    85 c0                   test   eax,eax
 804839d: 74 12                   je     80483b1 <frame_dummy+0x21>
 804839f:        b8 00 00 00 00          mov    eax,0x0
 80483a4: 85 c0                   test   eax,eax
 80483a6: 74 09                   je     80483b1 <frame_dummy+0x21>
 80483a8:        c7 04 24 e4 94 04 08    mov    DWORD PTR [esp],0x80494e4
 80483af:       ff d0                   call   eax
 80483b1:     c9                      leave  
 80483b2:        c3                      ret    
 80483b3:        90                      nop    
 80483b4:        90                      nop    
 80483b5:        90                      nop    
 80483b6:        90                      nop    
 80483b7:        90                      nop    
 80483b8:        90                      nop    
 80483b9:        90                      nop    
 80483ba:        90                      nop    
 80483bb:        90                      nop    
 80483bc:        90                      nop    
 80483bd:        90                      nop    
 80483be:        90                      nop    
 80483bf:        90                      nop    

080483c0 <main>:
 80483c0:      55                      push   ebp
 80483c1:     53                      push   ebx
 80483c2:     56                      push   esi
 80483c3:     57                      push   edi
 80483c4:     89 e5                   mov    ebp,esp
 80483c6: 68 f9 95 04 08          push   0x80495f9
 80483cb:       e8 1c ff ff ff          call   80482ec <printf@plt>
 80483d0:      83 c4 04                add    esp,0x4
 80483d3: ff 75 14                push   DWORD PTR [ebp+0x14]
 80483d6:    68 eb 95 04 08          push   0x80495eb
 80483db:       e8 0c ff ff ff          call   80482ec <printf@plt>
 80483e0:      83 c4 08                add    esp,0x8
 80483e3: 8b 7d 18                mov    edi,DWORD PTR [ebp+0x18]
 80483e6:        ff 34 3d 00 00 00 00    push   DWORD PTR [edi*1+0x0]
 80483ed:   68 dc 95 04 08          push   0x80495dc
 80483f2:       e8 f5 fe ff ff          call   80482ec <printf@plt>
 80483f7:      83 c4 08                add    esp,0x8
 80483fa: b8 00 00 00 00          mov    eax,0x0
 80483ff: 89 ec                   mov    esp,ebp
 8048401: 5f                      pop    edi
 8048402:     5e                      pop    esi
 8048403:     5b                      pop    ebx
 8048404:     5d                      pop    ebp
 8048405:     c3                      ret    
 8048406:        90                      nop    
 8048407:        90                      nop    
 8048408:        90                      nop    
 8048409:        90                      nop    
 804840a:        90                      nop    
 804840b:        90                      nop    
 804840c:        90                      nop    
 804840d:        90                      nop    
 804840e:        90                      nop    
 804840f:        90                      nop    

08048410 <__libc_csu_fini>:
 8048410:   55                      push   ebp
 8048411:     89 e5                   mov    ebp,esp
 8048413: 5d                      pop    ebp
 8048414:     c3                      ret    
 8048415:        8d 74 26 00             lea    esi,[esi+eiz*1+0x0]
 8048419:     8d bc 27 00 00 00 00    lea    edi,[edi+eiz*1+0x0]

08048420 <__libc_csu_init>:
 8048420:        55                      push   ebp
 8048421:     89 e5                   mov    ebp,esp
 8048423: 57                      push   edi
 8048424:     56                      push   esi
 8048425:     53                      push   ebx
 8048426:     e8 4f 00 00 00          call   804847a <__i686.get_pc_thunk.bx>
 804842b:  81 c3 91 11 00 00       add    ebx,0x1191
 8048431:      83 ec 0c                sub    esp,0xc
 8048434: e8 53 fe ff ff          call   804828c <_init>
 8048439:   8d bb 18 ff ff ff       lea    edi,[ebx-0xe8]
 804843f:  8d 83 18 ff ff ff       lea    eax,[ebx-0xe8]
 8048445:  29 c7                   sub    edi,eax
 8048447: c1 ff 02                sar    edi,0x2
 804844a: 85 ff                   test   edi,edi
 804844c: 74 24                   je     8048472 <__libc_csu_init+0x52>
 804844e:    31 f6                   xor    esi,esi
 8048450: 8b 45 10                mov    eax,DWORD PTR [ebp+0x10]
 8048453:        89 44 24 08             mov    DWORD PTR [esp+0x8],eax
 8048457: 8b 45 0c                mov    eax,DWORD PTR [ebp+0xc]
 804845a: 89 44 24 04             mov    DWORD PTR [esp+0x4],eax
 804845e: 8b 45 08                mov    eax,DWORD PTR [ebp+0x8]
 8048461: 89 04 24                mov    DWORD PTR [esp],eax
 8048464:     ff 94 b3 18 ff ff ff    call   DWORD PTR [ebx+esi*4-0xe8]
 804846b:      83 c6 01                add    esi,0x1
 804846e: 39 fe                   cmp    esi,edi
 8048470: 72 de                   jb     8048450 <__libc_csu_init+0x30>
 8048472:    83 c4 0c                add    esp,0xc
 8048475: 5b                      pop    ebx
 8048476:     5e                      pop    esi
 8048477:     5f                      pop    edi
 8048478:     5d                      pop    ebp
 8048479:     c3                      ret    

0804847a <__i686.get_pc_thunk.bx>:
 804847a:    8b 1c 24                mov    ebx,DWORD PTR [esp]
 804847d:     c3                      ret    
 804847e:        90                      nop    
 804847f:        90                      nop    

08048480 <__do_global_ctors_aux>:
 8048480:     55                      push   ebp
 8048481:     89 e5                   mov    ebp,esp
 8048483: 53                      push   ebx
 8048484:     83 ec 04                sub    esp,0x4
 8048487: a1 d4 94 04 08          mov    eax,ds:0x80494d4
 804848c:    83 f8 ff                cmp    eax,0xffffffff
 804848f:  74 13                   je     80484a4 <__do_global_ctors_aux+0x24>
 8048491:      bb d4 94 04 08          mov    ebx,0x80494d4
 8048496:   66 90                   xchg   ax,ax
 8048498:   83 eb 04                sub    ebx,0x4
 804849b: ff d0                   call   eax
 804849d:     8b 03                   mov    eax,DWORD PTR [ebx]
 804849f:     83 f8 ff                cmp    eax,0xffffffff
 80484a2:  75 f4                   jne    8048498 <__do_global_ctors_aux+0x18>
 80484a4:      83 c4 04                add    esp,0x4
 80484a7: 5b                      pop    ebx
 80484a8:     5d                      pop    ebp
 80484a9:     c3                      ret    
 80484aa:        90                      nop    
 80484ab:        90                      nop    

Disassembly of section .fini:

080484ac <_fini>:
 80484ac:    55                      push   ebp
 80484ad:     89 e5                   mov    ebp,esp
 80484af: 53                      push   ebx
 80484b0:     83 ec 04                sub    esp,0x4
 80484b3: e8 00 00 00 00          call   80484b8 <_fini+0xc>
 80484b8:       5b                      pop    ebx
 80484b9:     81 c3 04 11 00 00       add    ebx,0x1104
 80484bf:      e8 6c fe ff ff          call   8048330 <__do_global_dtors_aux>
 80484c4:   59                      pop    ecx
 80484c5:     5b                      pop    ebx
 80484c6:     c9                      leave  
 80484c7:        c3                      ret    

    


The objdump 's of the nasm and fasm versions will be separate posts.


Last edited by Tarkin on 08 Apr 2011, 03:36; edited 1 time in total
Post 08 Apr 2011, 03:17
View user's profile Send private message Reply with quote
Tarkin



Joined: 27 Aug 2010
Posts: 22
Tarkin 08 Apr 2011, 03:27
Okay, here is the output of the NASM backend

stevo@andLinux:/opt/lcc-nasm/build/test$ objdump -S -d -Mintel hello

Code:

hello:     file format elf32-i386


Disassembly of section .init:

08048258 <_init>:
 8048258:    55                      push   ebp
 8048259:     89 e5                   mov    ebp,esp
 804825b: 53                      push   ebx
 804825c:     83 ec 04                sub    esp,0x4
 804825f: e8 00 00 00 00          call   8048264 <_init+0xc>
 8048264:       5b                      pop    ebx
 8048265:     81 c3 20 13 00 00       add    ebx,0x1320
 804826b:      8b 93 fc ff ff ff       mov    edx,DWORD PTR [ebx-0x4]
 8048271: 85 d2                   test   edx,edx
 8048273: 74 05                   je     804827a <_init+0x22>
 8048275:      e8 1e 00 00 00          call   8048298 <__gmon_start__@plt>
 804827a:      e8 e1 00 00 00          call   8048360 <frame_dummy>
 804827f:     e8 cc 01 00 00          call   8048450 <__do_global_ctors_aux>
 8048284:   58                      pop    eax
 8048285:     5b                      pop    ebx
 8048286:     c9                      leave  
 8048287:        c3                      ret    

Disassembly of section .plt:

08048288 <__gmon_start__@plt-0x10>:
 8048288:   ff 35 88 95 04 08       push   DWORD PTR ds:0x8049588
 804828e:      ff 25 8c 95 04 08       jmp    DWORD PTR ds:0x804958c
 8048294:      00 00                   add    BYTE PTR [eax],al
    ...

08048298 <__gmon_start__@plt>:
 8048298:    ff 25 90 95 04 08       jmp    DWORD PTR ds:0x8049590
 804829e:      68 00 00 00 00          push   0x0
 80482a3:     e9 e0 ff ff ff          jmp    8048288 <_init+0x30>

080482a8 <__libc_start_main@plt>:
 80482a8:   ff 25 94 95 04 08       jmp    DWORD PTR ds:0x8049594
 80482ae:      68 08 00 00 00          push   0x8
 80482b3:     e9 d0 ff ff ff          jmp    8048288 <_init+0x30>

080482b8 <printf@plt>:
 80482b8:      ff 25 98 95 04 08       jmp    DWORD PTR ds:0x8049598
 80482be:      68 10 00 00 00          push   0x10
 80482c3:    e9 c0 ff ff ff          jmp    8048288 <_init+0x30>

Disassembly of section .text:

080482d0 <_start>:
 80482d0: 31 ed                   xor    ebp,ebp
 80482d2: 5e                      pop    esi
 80482d3:     89 e1                   mov    ecx,esp
 80482d5: 83 e4 f0                and    esp,0xfffffff0
 80482d8:  50                      push   eax
 80482d9:     54                      push   esp
 80482da:     52                      push   edx
 80482db:     68 e0 83 04 08          push   0x80483e0
 80482e0:       68 f0 83 04 08          push   0x80483f0
 80482e5:       51                      push   ecx
 80482e6:     56                      push   esi
 80482e7:     68 90 83 04 08          push   0x8048390
 80482ec:       e8 b7 ff ff ff          call   80482a8 <__libc_start_main@plt>
 80482f1:   f4                      hlt    
 80482f2:        90                      nop    
 80482f3:        90                      nop    
 80482f4:        90                      nop    
 80482f5:        90                      nop    
 80482f6:        90                      nop    
 80482f7:        90                      nop    
 80482f8:        90                      nop    
 80482f9:        90                      nop    
 80482fa:        90                      nop    
 80482fb:        90                      nop    
 80482fc:        90                      nop    
 80482fd:        90                      nop    
 80482fe:        90                      nop    
 80482ff:        90                      nop    

08048300 <__do_global_dtors_aux>:
 8048300:     55                      push   ebp
 8048301:     89 e5                   mov    ebp,esp
 8048303: 53                      push   ebx
 8048304:     83 ec 04                sub    esp,0x4
 8048307: 80 3d d0 95 04 08 00    cmp    BYTE PTR ds:0x80495d0,0x0
 804830e:   75 40                   jne    8048350 <__do_global_dtors_aux+0x50>
 8048310:      8b 15 d4 95 04 08       mov    edx,DWORD PTR ds:0x80495d4
 8048316:  b8 b0 94 04 08          mov    eax,0x80494b0
 804831b:   2d ac 94 04 08          sub    eax,0x80494ac
 8048320:   c1 f8 02                sar    eax,0x2
 8048323: 8d 58 ff                lea    ebx,[eax-0x1]
 8048326:   39 da                   cmp    edx,ebx
 8048328: 73 1f                   jae    8048349 <__do_global_dtors_aux+0x49>
 804832a:      8d b6 00 00 00 00       lea    esi,[esi+0x0]
 8048330:   8d 42 01                lea    eax,[edx+0x1]
 8048333:   a3 d4 95 04 08          mov    ds:0x80495d4,eax
 8048338:    ff 14 85 ac 94 04 08    call   DWORD PTR [eax*4+0x80494ac]
 804833f:     8b 15 d4 95 04 08       mov    edx,DWORD PTR ds:0x80495d4
 8048345:  39 da                   cmp    edx,ebx
 8048347: 72 e7                   jb     8048330 <__do_global_dtors_aux+0x30>
 8048349:      c6 05 d0 95 04 08 01    mov    BYTE PTR ds:0x80495d0,0x1
 8048350:   83 c4 04                add    esp,0x4
 8048353: 5b                      pop    ebx
 8048354:     5d                      pop    ebp
 8048355:     c3                      ret    
 8048356:        8d 76 00                lea    esi,[esi+0x0]
 8048359:   8d bc 27 00 00 00 00    lea    edi,[edi+eiz*1+0x0]

08048360 <frame_dummy>:
 8048360:    55                      push   ebp
 8048361:     89 e5                   mov    ebp,esp
 8048363: 83 ec 08                sub    esp,0x8
 8048366: a1 b4 94 04 08          mov    eax,ds:0x80494b4
 804836b:    85 c0                   test   eax,eax
 804836d: 74 12                   je     8048381 <frame_dummy+0x21>
 804836f:        b8 00 00 00 00          mov    eax,0x0
 8048374: 85 c0                   test   eax,eax
 8048376: 74 09                   je     8048381 <frame_dummy+0x21>
 8048378:        c7 04 24 b4 94 04 08    mov    DWORD PTR [esp],0x80494b4
 804837f:       ff d0                   call   eax
 8048381:     c9                      leave  
 8048382:        c3                      ret    
 8048383:        90                      nop    
 8048384:        90                      nop    
 8048385:        90                      nop    
 8048386:        90                      nop    
 8048387:        90                      nop    
 8048388:        90                      nop    
 8048389:        90                      nop    
 804838a:        90                      nop    
 804838b:        90                      nop    
 804838c:        90                      nop    
 804838d:        90                      nop    
 804838e:        90                      nop    
 804838f:        90                      nop    

08048390 <main>:
 8048390:      53                      push   ebx
 8048391:     56                      push   esi
 8048392:     57                      push   edi
 8048393:     55                      push   ebp
 8048394:     89 e5                   mov    ebp,esp
 8048396: 68 c1 95 04 08          push   0x80495c1
 804839b:       e8 18 ff ff ff          call   80482b8 <printf@plt>
 80483a0:      81 c4 04 00 00 00       add    esp,0x4
 80483a6: ff 75 14                push   DWORD PTR [ebp+0x14]
 80483a9:    68 b3 95 04 08          push   0x80495b3
 80483ae:       e8 05 ff ff ff          call   80482b8 <printf@plt>
 80483b3:      81 c4 08 00 00 00       add    esp,0x8
 80483b9: 8b 7d 18                mov    edi,DWORD PTR [ebp+0x18]
 80483bc:        ff 37                   push   DWORD PTR [edi]
 80483be: 68 a4 95 04 08          push   0x80495a4
 80483c3:       e8 f0 fe ff ff          call   80482b8 <printf@plt>
 80483c8:      81 c4 08 00 00 00       add    esp,0x8
 80483ce: bf 00 00 00 00          mov    edi,0x0

080483d3 <L1>:
 80483d3: 89 ec                   mov    esp,ebp
 80483d5: 5d                      pop    ebp
 80483d6:     5f                      pop    edi
 80483d7:     5e                      pop    esi
 80483d8:     5b                      pop    ebx
 80483d9:     c3                      ret    
 80483da:        90                      nop    
 80483db:        90                      nop    
 80483dc:        90                      nop    
 80483dd:        90                      nop    
 80483de:        90                      nop    
 80483df:        90                      nop    

080483e0 <__libc_csu_fini>:
 80483e0:   55                      push   ebp
 80483e1:     89 e5                   mov    ebp,esp
 80483e3: 5d                      pop    ebp
 80483e4:     c3                      ret    
 80483e5:        8d 74 26 00             lea    esi,[esi+eiz*1+0x0]
 80483e9:     8d bc 27 00 00 00 00    lea    edi,[edi+eiz*1+0x0]

080483f0 <__libc_csu_init>:
 80483f0:        55                      push   ebp
 80483f1:     89 e5                   mov    ebp,esp
 80483f3: 57                      push   edi
 80483f4:     56                      push   esi
 80483f5:     53                      push   ebx
 80483f6:     e8 4f 00 00 00          call   804844a <__i686.get_pc_thunk.bx>
 80483fb:  81 c3 89 11 00 00       add    ebx,0x1189
 8048401:      83 ec 0c                sub    esp,0xc
 8048404: e8 4f fe ff ff          call   8048258 <_init>
 8048409:   8d bb 20 ff ff ff       lea    edi,[ebx-0xe0]
 804840f:  8d 83 20 ff ff ff       lea    eax,[ebx-0xe0]
 8048415:  29 c7                   sub    edi,eax
 8048417: c1 ff 02                sar    edi,0x2
 804841a: 85 ff                   test   edi,edi
 804841c: 74 24                   je     8048442 <__libc_csu_init+0x52>
 804841e:    31 f6                   xor    esi,esi
 8048420: 8b 45 10                mov    eax,DWORD PTR [ebp+0x10]
 8048423:        89 44 24 08             mov    DWORD PTR [esp+0x8],eax
 8048427: 8b 45 0c                mov    eax,DWORD PTR [ebp+0xc]
 804842a: 89 44 24 04             mov    DWORD PTR [esp+0x4],eax
 804842e: 8b 45 08                mov    eax,DWORD PTR [ebp+0x8]
 8048431: 89 04 24                mov    DWORD PTR [esp],eax
 8048434:     ff 94 b3 20 ff ff ff    call   DWORD PTR [ebx+esi*4-0xe0]
 804843b:      83 c6 01                add    esi,0x1
 804843e: 39 fe                   cmp    esi,edi
 8048440: 72 de                   jb     8048420 <__libc_csu_init+0x30>
 8048442:    83 c4 0c                add    esp,0xc
 8048445: 5b                      pop    ebx
 8048446:     5e                      pop    esi
 8048447:     5f                      pop    edi
 8048448:     5d                      pop    ebp
 8048449:     c3                      ret    

0804844a <__i686.get_pc_thunk.bx>:
 804844a:    8b 1c 24                mov    ebx,DWORD PTR [esp]
 804844d:     c3                      ret    
 804844e:        90                      nop    
 804844f:        90                      nop    

08048450 <__do_global_ctors_aux>:
 8048450:     55                      push   ebp
 8048451:     89 e5                   mov    ebp,esp
 8048453: 53                      push   ebx
 8048454:     83 ec 04                sub    esp,0x4
 8048457: a1 a4 94 04 08          mov    eax,ds:0x80494a4
 804845c:    83 f8 ff                cmp    eax,0xffffffff
 804845f:  74 13                   je     8048474 <__do_global_ctors_aux+0x24>
 8048461:      bb a4 94 04 08          mov    ebx,0x80494a4
 8048466:   66 90                   xchg   ax,ax
 8048468:   83 eb 04                sub    ebx,0x4
 804846b: ff d0                   call   eax
 804846d:     8b 03                   mov    eax,DWORD PTR [ebx]
 804846f:     83 f8 ff                cmp    eax,0xffffffff
 8048472:  75 f4                   jne    8048468 <__do_global_ctors_aux+0x18>
 8048474:      83 c4 04                add    esp,0x4
 8048477: 5b                      pop    ebx
 8048478:     5d                      pop    ebp
 8048479:     c3                      ret    
 804847a:        90                      nop    
 804847b:        90                      nop    

Disassembly of section .fini:

0804847c <_fini>:
 804847c:    55                      push   ebp
 804847d:     89 e5                   mov    ebp,esp
 804847f: 53                      push   ebx
 8048480:     83 ec 04                sub    esp,0x4
 8048483: e8 00 00 00 00          call   8048488 <_fini+0xc>
 8048488:       5b                      pop    ebx
 8048489:     81 c3 fc 10 00 00       add    ebx,0x10fc
 804848f:      e8 6c fe ff ff          call   8048300 <__do_global_dtors_aux>
 8048494:   59                      pop    ecx
 8048495:     5b                      pop    ebx
 8048496:     c9                      leave  
 8048497:        c3                      ret    
    
Post 08 Apr 2011, 03:27
View user's profile Send private message Reply with quote
Tarkin



Joined: 27 Aug 2010
Posts: 22
Tarkin 08 Apr 2011, 03:35
Okay, here is the output of the FASM backend:

stevo@andLinux:/opt/lcc-fasm/build/test$ objdump -S -d -Mintel hello
Code:

hello:     file format elf32-i386


Disassembly of section .init:

08048258 <_init>:
 8048258:       55                      push   ebp
 8048259:     89 e5                   mov    ebp,esp
 804825b: 53                      push   ebx
 804825c:     83 ec 04                sub    esp,0x4
 804825f: e8 00 00 00 00          call   8048264 <_init+0xc>
 8048264:       5b                      pop    ebx
 8048265:     81 c3 10 13 00 00       add    ebx,0x1310
 804826b:      8b 93 fc ff ff ff       mov    edx,DWORD PTR [ebx-0x4]
 8048271: 85 d2                   test   edx,edx
 8048273: 74 05                   je     804827a <_init+0x22>
 8048275:      e8 1e 00 00 00          call   8048298 <__gmon_start__@plt>
 804827a:      e8 e1 00 00 00          call   8048360 <frame_dummy>
 804827f:     e8 bc 01 00 00          call   8048440 <__do_global_ctors_aux>
 8048284:   58                      pop    eax
 8048285:     5b                      pop    ebx
 8048286:     c9                      leave  
 8048287:        c3                      ret    

Disassembly of section .plt:

08048288 <__gmon_start__@plt-0x10>:
 8048288:   ff 35 78 95 04 08       push   DWORD PTR ds:0x8049578
 804828e:      ff 25 7c 95 04 08       jmp    DWORD PTR ds:0x804957c
 8048294:      00 00                   add    BYTE PTR [eax],al
    ...

08048298 <__gmon_start__@plt>:
 8048298:    ff 25 80 95 04 08       jmp    DWORD PTR ds:0x8049580
 804829e:      68 00 00 00 00          push   0x0
 80482a3:     e9 e0 ff ff ff          jmp    8048288 <_init+0x30>

080482a8 <__libc_start_main@plt>:
 80482a8:   ff 25 84 95 04 08       jmp    DWORD PTR ds:0x8049584
 80482ae:      68 08 00 00 00          push   0x8
 80482b3:     e9 d0 ff ff ff          jmp    8048288 <_init+0x30>

080482b8 <printf@plt>:
 80482b8:      ff 25 88 95 04 08       jmp    DWORD PTR ds:0x8049588
 80482be:      68 10 00 00 00          push   0x10
 80482c3:    e9 c0 ff ff ff          jmp    8048288 <_init+0x30>

Disassembly of section .text:

080482d0 <_start>:
 80482d0: 31 ed                   xor    ebp,ebp
 80482d2: 5e                      pop    esi
 80482d3:     89 e1                   mov    ecx,esp
 80482d5: 83 e4 f0                and    esp,0xfffffff0
 80482d8:  50                      push   eax
 80482d9:     54                      push   esp
 80482da:     52                      push   edx
 80482db:     68 d0 83 04 08          push   0x80483d0
 80482e0:       68 e0 83 04 08          push   0x80483e0
 80482e5:       51                      push   ecx
 80482e6:     56                      push   esi
 80482e7:     68 84 83 04 08          push   0x8048384
 80482ec:       e8 b7 ff ff ff          call   80482a8 <__libc_start_main@plt>
 80482f1:   f4                      hlt    
 80482f2:        90                      nop    
 80482f3:        90                      nop    
 80482f4:        90                      nop    
 80482f5:        90                      nop    
 80482f6:        90                      nop    
 80482f7:        90                      nop    
 80482f8:        90                      nop    
 80482f9:        90                      nop    
 80482fa:        90                      nop    
 80482fb:        90                      nop    
 80482fc:        90                      nop    
 80482fd:        90                      nop    
 80482fe:        90                      nop    
 80482ff:        90                      nop    

08048300 <__do_global_dtors_aux>:
 8048300:     55                      push   ebp
 8048301:     89 e5                   mov    ebp,esp
 8048303: 53                      push   ebx
 8048304:     83 ec 04                sub    esp,0x4
 8048307: 80 3d c4 95 04 08 00    cmp    BYTE PTR ds:0x80495c4,0x0
 804830e:   75 40                   jne    8048350 <__do_global_dtors_aux+0x50>
 8048310:      8b 15 c8 95 04 08       mov    edx,DWORD PTR ds:0x80495c8
 8048316:  b8 a0 94 04 08          mov    eax,0x80494a0
 804831b:   2d 9c 94 04 08          sub    eax,0x804949c
 8048320:   c1 f8 02                sar    eax,0x2
 8048323: 8d 58 ff                lea    ebx,[eax-0x1]
 8048326:   39 da                   cmp    edx,ebx
 8048328: 73 1f                   jae    8048349 <__do_global_dtors_aux+0x49>
 804832a:      8d b6 00 00 00 00       lea    esi,[esi+0x0]
 8048330:   8d 42 01                lea    eax,[edx+0x1]
 8048333:   a3 c8 95 04 08          mov    ds:0x80495c8,eax
 8048338:    ff 14 85 9c 94 04 08    call   DWORD PTR [eax*4+0x804949c]
 804833f:     8b 15 c8 95 04 08       mov    edx,DWORD PTR ds:0x80495c8
 8048345:  39 da                   cmp    edx,ebx
 8048347: 72 e7                   jb     8048330 <__do_global_dtors_aux+0x30>
 8048349:      c6 05 c4 95 04 08 01    mov    BYTE PTR ds:0x80495c4,0x1
 8048350:   83 c4 04                add    esp,0x4
 8048353: 5b                      pop    ebx
 8048354:     5d                      pop    ebp
 8048355:     c3                      ret    
 8048356:        8d 76 00                lea    esi,[esi+0x0]
 8048359:   8d bc 27 00 00 00 00    lea    edi,[edi+eiz*1+0x0]

08048360 <frame_dummy>:
 8048360:    55                      push   ebp
 8048361:     89 e5                   mov    ebp,esp
 8048363: 83 ec 08                sub    esp,0x8
 8048366: a1 a4 94 04 08          mov    eax,ds:0x80494a4
 804836b:    85 c0                   test   eax,eax
 804836d: 74 12                   je     8048381 <frame_dummy+0x21>
 804836f:        b8 00 00 00 00          mov    eax,0x0
 8048374: 85 c0                   test   eax,eax
 8048376: 74 09                   je     8048381 <frame_dummy+0x21>
 8048378:        c7 04 24 a4 94 04 08    mov    DWORD PTR [esp],0x80494a4
 804837f:       ff d0                   call   eax
 8048381:     c9                      leave  
 8048382:        c3                      ret    
 8048383:        90                      nop    

08048384 <main>:
 8048384:      53                      push   ebx
 8048385:     56                      push   esi
 8048386:     57                      push   edi
 8048387:     55                      push   ebp
 8048388:     89 e5                   mov    ebp,esp
 804838a: 68 b4 95 04 08          push   0x80495b4
 804838f:       e8 24 ff ff ff          call   80482b8 <printf@plt>
 8048394:      83 c4 04                add    esp,0x4
 8048397: ff 75 14                push   DWORD PTR [ebp+0x14]
 804839a:    68 a6 95 04 08          push   0x80495a6
 804839f:       e8 14 ff ff ff          call   80482b8 <printf@plt>
 80483a4:      83 c4 08                add    esp,0x8
 80483a7: 8b 7d 18                mov    edi,DWORD PTR [ebp+0x18]
 80483aa:        ff 37                   push   DWORD PTR [edi]
 80483ac: 68 94 95 04 08          push   0x8049594
 80483b1:       e8 02 ff ff ff          call   80482b8 <printf@plt>
 80483b6:      83 c4 08                add    esp,0x8
 80483b9: bf 00 00 00 00          mov    edi,0x0
 80483be: 89 ec                   mov    esp,ebp
 80483c0: 5d                      pop    ebp
 80483c1:     5f                      pop    edi
 80483c2:     5e                      pop    esi
 80483c3:     5b                      pop    ebx
 80483c4:     c3                      ret    
 80483c5:        90                      nop    
 80483c6:        90                      nop    
 80483c7:        90                      nop    
 80483c8:        90                      nop    
 80483c9:        90                      nop    
 80483ca:        90                      nop    
 80483cb:        90                      nop    
 80483cc:        90                      nop    
 80483cd:        90                      nop    
 80483ce:        90                      nop    
 80483cf:        90                      nop    

080483d0 <__libc_csu_fini>:
 80483d0:   55                      push   ebp
 80483d1:     89 e5                   mov    ebp,esp
 80483d3: 5d                      pop    ebp
 80483d4:     c3                      ret    
 80483d5:        8d 74 26 00             lea    esi,[esi+eiz*1+0x0]
 80483d9:     8d bc 27 00 00 00 00    lea    edi,[edi+eiz*1+0x0]

080483e0 <__libc_csu_init>:
 80483e0:        55                      push   ebp
 80483e1:     89 e5                   mov    ebp,esp
 80483e3: 57                      push   edi
 80483e4:     56                      push   esi
 80483e5:     53                      push   ebx
 80483e6:     e8 4f 00 00 00          call   804843a <__i686.get_pc_thunk.bx>
 80483eb:  81 c3 89 11 00 00       add    ebx,0x1189
 80483f1:      83 ec 0c                sub    esp,0xc
 80483f4: e8 5f fe ff ff          call   8048258 <_init>
 80483f9:   8d bb 20 ff ff ff       lea    edi,[ebx-0xe0]
 80483ff:  8d 83 20 ff ff ff       lea    eax,[ebx-0xe0]
 8048405:  29 c7                   sub    edi,eax
 8048407: c1 ff 02                sar    edi,0x2
 804840a: 85 ff                   test   edi,edi
 804840c: 74 24                   je     8048432 <__libc_csu_init+0x52>
 804840e:    31 f6                   xor    esi,esi
 8048410: 8b 45 10                mov    eax,DWORD PTR [ebp+0x10]
 8048413:        89 44 24 08             mov    DWORD PTR [esp+0x8],eax
 8048417: 8b 45 0c                mov    eax,DWORD PTR [ebp+0xc]
 804841a: 89 44 24 04             mov    DWORD PTR [esp+0x4],eax
 804841e: 8b 45 08                mov    eax,DWORD PTR [ebp+0x8]
 8048421: 89 04 24                mov    DWORD PTR [esp],eax
 8048424:     ff 94 b3 20 ff ff ff    call   DWORD PTR [ebx+esi*4-0xe0]
 804842b:      83 c6 01                add    esi,0x1
 804842e: 39 fe                   cmp    esi,edi
 8048430: 72 de                   jb     8048410 <__libc_csu_init+0x30>
 8048432:    83 c4 0c                add    esp,0xc
 8048435: 5b                      pop    ebx
 8048436:     5e                      pop    esi
 8048437:     5f                      pop    edi
 8048438:     5d                      pop    ebp
 8048439:     c3                      ret    

0804843a <__i686.get_pc_thunk.bx>:
 804843a:    8b 1c 24                mov    ebx,DWORD PTR [esp]
 804843d:     c3                      ret    
 804843e:        90                      nop    
 804843f:        90                      nop    

08048440 <__do_global_ctors_aux>:
 8048440:     55                      push   ebp
 8048441:     89 e5                   mov    ebp,esp
 8048443: 53                      push   ebx
 8048444:     83 ec 04                sub    esp,0x4
 8048447: a1 94 94 04 08          mov    eax,ds:0x8049494
 804844c:    83 f8 ff                cmp    eax,0xffffffff
 804844f:  74 13                   je     8048464 <__do_global_ctors_aux+0x24>
 8048451:      bb 94 94 04 08          mov    ebx,0x8049494
 8048456:   66 90                   xchg   ax,ax
 8048458:   83 eb 04                sub    ebx,0x4
 804845b: ff d0                   call   eax
 804845d:     8b 03                   mov    eax,DWORD PTR [ebx]
 804845f:     83 f8 ff                cmp    eax,0xffffffff
 8048462:  75 f4                   jne    8048458 <__do_global_ctors_aux+0x18>
 8048464:      83 c4 04                add    esp,0x4
 8048467: 5b                      pop    ebx
 8048468:     5d                      pop    ebp
 8048469:     c3                      ret    
 804846a:        90                      nop    
 804846b:        90                      nop    

Disassembly of section .fini:

0804846c <_fini>:
 804846c:    55                      push   ebp
 804846d:     89 e5                   mov    ebp,esp
 804846f: 53                      push   ebx
 8048470:     83 ec 04                sub    esp,0x4
 8048473: e8 00 00 00 00          call   8048478 <_fini+0xc>
 8048478:       5b                      pop    ebx
 8048479:     81 c3 fc 10 00 00       add    ebx,0x10fc
 804847f:      e8 7c fe ff ff          call   8048300 <__do_global_dtors_aux>
 8048484:   59                      pop    ecx
 8048485:     5b                      pop    ebx
 8048486:     c9                      leave  
 8048487:        c3                      ret    
    
Post 08 Apr 2011, 03:35
View user's profile Send private message Reply with quote
Tarkin



Joined: 27 Aug 2010
Posts: 22
Tarkin 08 Apr 2011, 03:44
...and finally, a comparison of the generated file sizes:
Code:
stevo@andLinux:/opt$ ls -l lcc-gas/build/test/hello lcc-gas/build/test/hello.s lcc-gas/build/test/hello.o
-rwxr-xr-x 1 stevo stevo 6500 Apr  7 20:55 lcc-gas/build/test/hello
-rw-r--r-- 1 stevo stevo  812 Apr  7 20:55 lcc-gas/build/test/hello.o
-rw-r--r-- 1 stevo stevo  950 Apr  7 20:54 lcc-gas/build/test/hello.s
stevo@andLinux:/opt$ ls -l lcc-nasm/build/test/hello lcc-nasm/build/test/hello.s lcc-nasm/build/test/hello.o
-rwxr-xr-x 1 stevo stevo 6560 Apr  7 21:21 lcc-nasm/build/test/hello
-rw-r--r-- 1 stevo stevo  960 Apr  7 21:21 lcc-nasm/build/test/hello.o
-rw-r--r-- 1 stevo stevo  638 Apr  7 21:21 lcc-nasm/build/test/hello.s
stevo@andLinux:/opt$ ls -l lcc-fasm/build/test/hello lcc-fasm/build/test/hello.s lcc-fasm/build/test/hello.o
-rwxr-xr-x 1 stevo stevo 6391 Apr  7 21:36 lcc-fasm/build/test/hello
-rw-r--r-- 1 stevo stevo  700 Apr  7 21:36 lcc-fasm/build/test/hello.o
-rw-r--r-- 1 stevo stevo  619 Apr  7 21:36 lcc-fasm/build/test/hello.s
    
Post 08 Apr 2011, 03:44
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 08 Apr 2011, 03:48
I may be wrong, but I think vid was suggesting you compare them in terms of speed. (That's what Fasm is known for. Well... that, and just being all around awesome.) I would expect two assemblers to make the same(or really close) executable, considering that all they do is a direct translation from asm to binary.
Post 08 Apr 2011, 03:48
View user's profile Send private message Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 843
Location: Jakarta, Indonesia
TmX 08 Apr 2011, 03:51
Interesting. Is the modified patch available yet?
Post 08 Apr 2011, 03:51
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4121
Location: vpcmpistri
bitRAKE 08 Apr 2011, 05:14
NASM doesn't appear to be optimizing this:
Code:
80483a0:       81 c4 04 00 00 00       add    esp,0x4    
Strange since it is optimizing a similar SUB instruction.

File sizes seem to indicate other differences.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 08 Apr 2011, 05:14
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 08 Apr 2011, 05:40
bitRAKE, note that actually it was capable of giving shorter encoding for that very same instruction too, but it seems that if "add esp, x" is preceded by a call, then it uses the long form for no apparent reason... (maybe the object files should be analyzed in case that for some odd reason the immediate is relocatable???)

Example of shorter form:
Code:
 8048474:       83 c4 04                add    esp,0x4     
Post 08 Apr 2011, 05:40
View user's profile Send private message Reply with quote
Tarkin



Joined: 27 Aug 2010
Posts: 22
Tarkin 09 Apr 2011, 09:35
TmX wrote:
Interesting. Is the modified patch available yet?


I probably will release it as some sort of package.
All of the files involved are either Public Domain (lcc),
or LGPL, or effective PD (fasm).

I removed the alpha, mips, and sparc archectictures, as well as
support for everything but elf on linux.

Also....
I had to switch back to the 3.6 release. This effectivley kills any chance for
comparison, because the stock 3.6 release lacked linux & gas support.
Why? I compiled a non-trivial (well, mostly non-trival Razz ) source-
a bastardized C-with-FASM OS tutorial....and the 4.2 version was
generating wierd little snippets of code

here is the c file:
Code:
/* vim: set ft=c : set ts=2 :
 * kernel.c - SGM - MAR-17-2011
 */

#include "multiboot.h"
#include "kernel.h"

typedef struct KCURSOR {
  unsigned char row;
  unsigned char col;
  unsigned char rowmax;
  unsigned char colmax;
  unsigned char att;
  unsigned char pad1;
  void *base;
  void *postion;
  unsigned short max;
  unsigned short pad2;
} CURSOR;

extern void kvidinit(CURSOR *);
extern void kcls(void);
extern void ksetxy(unsigned char row,unsigned char col, unsigned char att);
extern void kout(char *string);
extern void kinit(void);

unsigned int kmain(mbptr,magic)
  multiboot_info_t *mbptr;
  unsigned int magic;
{
  unsigned int i;
  CURSOR cursor;
multiboot_info_t mbinfo;

  /* initialize video */
  kvidinit(&cursor);
  kcls();

  if ( magic != MULTIBOOT_BOOTLOADER_MAGIC ) {
    // Something went awry. Print an error message and halt,
    // but do *not* rely on the multiboot data structure.
    ksetxy(10,27,0x04);
    kout("FAIL: BAD MULTIBOOT MAGIC");
    return magic;
  }

  mbinfo.flags             = mbptr->flags;
  mbinfo.mem_lower         = mbptr->mem_lower;
  mbinfo.mem_upper         = mbptr->mem_upper;
  mbinfo.boot_device       = mbptr->boot_device;
  mbinfo.cmdline           = mbptr->cmdline;
  mbinfo.mods_count        = mbptr->mods_count;
  mbinfo.mods_addr         = mbptr->mods_addr;
  mbinfo.u                 = mbptr->u; // aout_syms OR elf_sec
  mbinfo.mmap_length       = mbptr->mmap_length;
  mbinfo.mmap_addr         = mbptr->mmap_addr;
  mbinfo.drives_length     = mbptr->drives_length;
  mbinfo.drives_addr       = mbptr->drives_addr;
  mbinfo.config_table      = mbptr->config_table;
  mbinfo.boot_loader_name  = mbptr->boot_loader_name;
  mbinfo.apm_table         = mbptr->apm_table;
  mbinfo.vbe_control_info  = mbptr->vbe_control_info;
  mbinfo.vbe_mode_info     = mbptr->vbe_mode_info;
  mbinfo.vbe_mode          = mbptr->vbe_mode;
  mbinfo.vbe_interface_seg = mbptr->vbe_interface_seg;
  mbinfo.vbe_interface_off = mbptr->vbe_interface_off;
  mbinfo.vbe_interface_len = mbptr->vbe_interface_len;

  ksetxy(11,33,0x02);
  kout("Neurosis v0.0");
  ksetxy(12,24,0x02);
  kout("Copyright (C) 2011-2013 SGMTech");

  /* initialize kernel exection environment */
  kinit();

  for (i = 0; i < 0xFFFFFFFF; i++) {
    i++;
    i--;
  }
  return (inb(PIC1_DATA));
}


static void outb(unsigned short port, unsigned char val) {
  //asm("out %0,%1"
  //    : : "a"(val), "Nd"(port));
}

static unsigned char inb(unsigned short port) {
  unsigned char ret = 0;
  //asm("inb %1, %0"
  //    : "a="(ret) : "Nd"(port));
  return ret;
}

static void io_wait(void) {
  //inb((unsigned short)0xF0);
  //inb((unsigned short)0xF0);
  //asm( "jmp 1f\n\t"
  //               "1: jmp 1f"
  //               "2:");
}

void IRQ_set_mask(unsigned char IRQline) {
  unsigned short port;
  unsigned char value;

  if(IRQline < 8) {
    port = PIC1_DATA;
  } else {
    port = PIC2_DATA;
    IRQline -= 8;
  }
  value = inb(port) | (1 << IRQline);
  outb(port, value);
}

void IRQ_clear_mask(unsigned char IRQline) {
  unsigned short port;
  unsigned char value;

  if(IRQline < 8) {
    port = PIC1_DATA;
  } else {
    port = PIC2_DATA;
    IRQline -= 8;
  }
  value = inb(port) & ~(1 << IRQline);
  outb(port, value);
}

void enablePIC(unsigned char master_mask, unsigned char slave_mask) {
  outb(PIC1_DATA,master_mask);
  outb(PIC2_DATA,slave_mask);
  io_wait();
  //asm volatile("sti");
}

void disablePIC(void) {
  //asm volatile ("cli");
  outb(PIC1_DATA,0xFF);
  outb(PIC2_DATA,0xFF);
}

/* EOF */
    



and the resultant assembly:
Code:
.globl kmain
.text
.align 16
.type kmain,@function
kmain:
pushl %ebp
pushl %ebx
pushl %esi
pushl %edi
movl %esp,%ebp
subl $112,%esp
leal -112(%ebp),%edi
pushl %edi
call kvidinit
addl $4,%esp
call kcls
movl 24(%ebp),%edi
cmpl $0x2badb002,%edi
je .LC3
pushl $4
pushl $27
pushl $10
call ksetxy
addl $12,%esp
pushl $.LC5
call kout
addl $4,%esp
movl 24(%ebp),%eax
jmp .LC2
.LC3:
movl 20(%ebp),%edi    ; <- structure stuff?
movl (,%edi),%esi
movl %esi,-92(%ebp)
movl 4(%edi),%edi
movl %edi,-88(%ebp)
movl 20(%ebp),%edi
movl 8(%edi),%edi
movl %edi,-84(%ebp)
movl 20(%ebp),%edi
movl 12(%edi),%edi
movl %edi,-80(%ebp)
movl 20(%ebp),%edi
movl 16(%edi),%edi
movl %edi,-76(%ebp)
movl 20(%ebp),%edi
movl 20(%edi),%edi
movl %edi,-72(%ebp)
movl 20(%ebp),%edi
movl 24(%edi),%edi
movl %edi,-68(%ebp)
leal -64(%ebp),%edi
movl 20(%ebp),%esi
leal 28(%esi),%esi
movl $16,%ecx
rep
movsb
movl 20(%ebp),%edi
movl 44(%edi),%edi
movl %edi,-48(%ebp)
movl 20(%ebp),%edi
movl 48(%edi),%edi
movl %edi,-44(%ebp)
movl 20(%ebp),%edi
movl 52(%edi),%edi
movl %edi,-40(%ebp)
movl 20(%ebp),%edi
movl 56(%edi),%edi
movl %edi,-36(%ebp)
movl 20(%ebp),%edi
movl 60(%edi),%edi
movl %edi,-32(%ebp)
movl 20(%ebp),%edi
movl 64(%edi),%edi
movl %edi,-28(%ebp)
movl 20(%ebp),%edi
movl 68(%edi),%edi
movl %edi,-24(%ebp)
movl 20(%ebp),%edi
movl 72(%edi),%edi
movl %edi,-20(%ebp)
movl 20(%ebp),%edi
movl 76(%edi),%edi
movl %edi,-16(%ebp)
movl 20(%ebp),%edi
movw 80(%edi),%di
movw %di,-12(%ebp)
movl 20(%ebp),%edi
movw 82(%edi),%di
movw %di,-10(%ebp)
movl 20(%ebp),%edi
movw 84(%edi),%di
movw %di,-8(%ebp)
movl 20(%ebp),%edi
movw 86(%edi),%di
movw %di,-6(%ebp)
pushl $2
pushl $33
pushl $11
call ksetxy
addl $12,%esp
pushl $.LC26
call kout
addl $4,%esp
pushl $2
pushl $24
pushl $12
call ksetxy
addl $12,%esp
pushl $.LC27
call kout
addl $4,%esp
call kinit
movl $0,-4(%ebp)
jmp .LC31
.LC28:
addl $1,-4(%ebp)
subl $1,-4(%ebp)
.LC29:
addl $1,-4(%ebp)
.LC31:
cmpl $0xffffffff,-4(%ebp)
jb  .LC28
pushl $33
call inb
addl $4,%esp
movl %eax,%edi
movl %edi,%ebx
movzbl %bl,%edi
movl %edi,%eax
.LC2:
movl %ebp,%esp
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
.Lf32:
.size kmain,.Lf32-kmain
.align 16
.type outb,@function
outb:
pushl %ebp
pushl %ebx
pushl %esi
pushl %edi
movl %esp,%ebp
movl 20(%ebp),%edi
movw %di,20(%ebp)
movl 24(%ebp),%edi
movl %edi,%ebx
movb %bl,24(%ebp)
.LC33:
movl %ebp,%esp
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
.Lf34:
.size outb,.Lf34-outb
.align 16
.type inb,@function
inb:
pushl %ebp
pushl %ebx
pushl %esi
pushl %edi
movl %esp,%ebp
subl $4,%esp
movl 20(%ebp),%edi   ; <- WTF
movw %di,20(%ebp)   ; <- Does this do?
movb $0,-4(%ebp)
movb -4(%ebp),%bl
movzbl %bl,%eax
.LC35:
movl %ebp,%esp
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
.Lf36:
.size inb,.Lf36-inb
.align 16
.type io_wait,@function
io_wait:
pushl %ebp
pushl %ebx
pushl %esi
pushl %edi
movl %esp,%ebp
.LC37:
movl %ebp,%esp
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
.Lf38:
.size io_wait,.Lf38-io_wait
.globl IRQ_set_mask
.align 16
.type IRQ_set_mask,@function
IRQ_set_mask:
pushl %ebp
pushl %ebx
pushl %esi
pushl %edi
movl %esp,%ebp
subl $8,%esp
movl 20(%ebp),%edi
movl %edi,%ebx
movb %bl,20(%ebp)
movb 20(%ebp),%bl
movzbl %bl,%edi
cmpl $8,%edi
jge .LC40
movw $33,-4(%ebp)
jmp .LC41
.LC40:
movw $161,-4(%ebp)
movb 20(%ebp),%bl
movzbl %bl,%edi
subl $8,%edi
movl %edi,%ebx
movb %bl,20(%ebp)
.LC41:
movw -4(%ebp),%di       ; <-WTF
movzwl %di,%edi          ; <-is this
pushl %edi                   ; <- doing?!?!
call inb
addl $4,%esp
movl %eax,%edi
movl %edi,%ebx
movzbl %bl,%edi
mov $1,%esi
movb 20(%ebp),%bl
movzbl %bl,%ecx
movl %esi,%eax
sall %cl,%eax
orl %eax,%edi
movl %edi,%ebx
movb %bl,-8(%ebp)
movb -8(%ebp),%bl
movzbl %bl,%edi
pushl %edi
movw -4(%ebp),%di
movzwl %di,%edi
pushl %edi
call outb
addl $8,%esp
.LC39:
movl %ebp,%esp
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
.Lf42:
.size IRQ_set_mask,.Lf42-IRQ_set_mask
.globl IRQ_clear_mask
.align 16
.type IRQ_clear_mask,@function
IRQ_clear_mask:
pushl %ebp
pushl %ebx
pushl %esi
pushl %edi
movl %esp,%ebp
subl $8,%esp
movl 20(%ebp),%edi
movl %edi,%ebx
movb %bl,20(%ebp)
movb 20(%ebp),%bl
movzbl %bl,%edi
cmpl $8,%edi
jge .LC44
movw $33,-4(%ebp)
jmp .LC45
.LC44:
movw $161,-4(%ebp)
movb 20(%ebp),%bl
movzbl %bl,%edi
subl $8,%edi
movl %edi,%ebx
movb %bl,20(%ebp)
.LC45:
movw -4(%ebp),%di
movzwl %di,%edi
pushl %edi
call inb
addl $4,%esp
movl %eax,%edi
movl %edi,%ebx
movzbl %bl,%edi
mov $1,%esi
movb 20(%ebp),%bl
movzbl %bl,%ecx
movl %esi,%eax
sall %cl,%eax
movl %eax,%esi
notl %esi
andl %esi,%edi
movl %edi,%ebx
movb %bl,-8(%ebp)
movb -8(%ebp),%bl
movzbl %bl,%edi
pushl %edi
movw -4(%ebp),%di
movzwl %di,%edi
pushl %edi
call outb
addl $8,%esp
.LC43:
movl %ebp,%esp
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
.Lf46:
.size IRQ_clear_mask,.Lf46-IRQ_clear_mask
.globl enablePIC
.align 16
.type enablePIC,@function
enablePIC:
pushl %ebp
pushl %ebx
pushl %esi
pushl %edi
movl %esp,%ebp
movl 20(%ebp),%edi
movl %edi,%ebx
movb %bl,20(%ebp)
movl 24(%ebp),%edi
movl %edi,%ebx
movb %bl,24(%ebp)
movb 20(%ebp),%bl
movzbl %bl,%edi
pushl %edi
pushl $33
call outb
addl $8,%esp
movb 24(%ebp),%bl
movzbl %bl,%edi
pushl %edi
pushl $161
call outb
addl $8,%esp
call io_wait
.LC47:
movl %ebp,%esp
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
.Lf48:
.size enablePIC,.Lf48-enablePIC
.globl disablePIC
.align 16
.type disablePIC,@function
disablePIC:
pushl %ebp
pushl %ebx
pushl %esi
pushl %edi
movl %esp,%ebp
pushl $255
pushl $33
call outb
addl $8,%esp
pushl $255
pushl $161
call outb
addl $8,%esp
.LC49:
movl %ebp,%esp
popl %edi
popl %esi
popl %ebx
popl %ebp
ret
.Lf50:
.size disablePIC,.Lf50-disablePIC
.data
.align 1
.LC27:
.byte 67
.byte 111
.byte 112
.byte 121
.byte 114
.byte 105
.byte 103
.byte 104
.byte 116
.byte 32
.byte 40
.byte 67
.byte 41
.byte 32
.byte 50
.byte 48
.byte 49
.byte 49
.byte 45
.byte 50
.byte 48
.byte 49
.byte 51
.byte 32
.byte 83
.byte 71
.byte 77
.byte 84
.byte 101
.byte 99
.byte 104
.byte 0
.align 1
.LC26:
.byte 78
.byte 101
.byte 117
.byte 114
.byte 111
.byte 115
.byte 105
.byte 115
.byte 32
.byte 118
.byte 48
.byte 46
.byte 48
.byte 0
.align 1
.LC5:
.byte 70
.byte 65
.byte 73
.byte 76
.byte 58
.byte 32
.byte 66
.byte 65
.byte 68
.byte 32
.byte 77
.byte 85
.byte 76
.byte 84
.byte 73
.byte 66
.byte 79
.byte 79
.byte 84
.byte 32
.byte 77
.byte 65
.byte 71
.byte 73
.byte 67
.byte 0
.text
.ident "LCC: 4.1"
    


The 4.2 versions, modified to use fasm, had similiar little quirks,
and NO INLINE ASM SUPPORT Mad Even this gas version won't
do it.

So, I've switched back to using the lcc-3.6 codebase, appyling modifications
scoured from the 'net to provide inline assembly, and converting the NASM
machine description to use FASM syntax (which is trivial).

Once it's cleaned up, and with better installation text, I'll post a link.

TTFN,
Tarkin
Post 09 Apr 2011, 09:35
View user's profile Send private message Reply with quote
Tarkin



Joined: 27 Aug 2010
Posts: 22
Tarkin 09 Apr 2011, 09:50
Tyler wrote:
I may be wrong, but I think vid was suggesting you compare them in terms of speed. (That's what Fasm is known for. Well... that, and just being all around awesome.) I would expect two assemblers to make the same(or really close) executable, considering that all they do is a direct translation from asm to binary.


Wait, execution speed or assembly speed, or both?

I'll second the awesome part - I simply am ignorant of the speed gains-
but my primary goals were:
-replace gcc & as
-with an Intel-syntax assembler
-that is'nt reliant on gcc or VC/++

I am playing around with OS development, and trying to manage
and debug macro-created procedures (ala proc.inc) was becoming
cumbersome.

I mentioned before the (also awesome!) vlink linker- which I am
using to link the various elf's into a multiboot-compliant executable.
I realized I had the ideal assembler and the ideal linker, why
not scrounge up a compiler and complete the set?

Will it ever beat the GNU toolchain? I doubt it. gcc and binutils are
under intense, iterative development and have been for what-
decades- now?

Will the lcc/fasm/vlink toolchain produce performant code?
Only time will tell.

TTFN,
Tarkin
Post 09 Apr 2011, 09:50
View user's profile Send private message Reply with quote
Tarkin



Joined: 27 Aug 2010
Posts: 22
Tarkin 20 Apr 2011, 20:48
Sorry for the delay, got caught up in making SableVM build on Debian/PARISC...

In any event, I have attached the prototype release.
Caveats:
Please do not try and build it 'out-of-the-box': a few files need to be customized.
Only for Linux on x86 (and 32 bit at that; untested and probably won't work on x86-64)
read the READMEs ; README.FASM contains the build instructions.


Description: lcc-3.6 modified for use with fasm as backend/assembler
Download
Filename: lcc-fasm-3.6.tar.gz
Filesize: 233.59 KB
Downloaded: 975 Time(s)

Post 20 Apr 2011, 20:48
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 21 Apr 2011, 00:14
Can you please separately upload all three of those .o files, for easy comparison?
Post 21 Apr 2011, 00:14
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tarkin



Joined: 27 Aug 2010
Posts: 22
Tarkin 23 Apr 2011, 00:16
Here is the object file produced from lcc-4.2 w/ GNU as backend


Description: lcc v4.2 GNU/Linux
GNU assembler 2.17.50.0.6-14.el5 20061020
(sorry for zip, can't attach .o/.obj)

Download
Filename: lcc-gas-hello.zip
Filesize: 633 Bytes
Downloaded: 771 Time(s)

Post 23 Apr 2011, 00:16
View user's profile Send private message Reply with quote
Tarkin



Joined: 27 Aug 2010
Posts: 22
Tarkin 23 Apr 2011, 00:26
Here is the object file produced from lcc-4.2 w/ NASM backend


Description: lcc-4.2 w/NASM on GNU/Linux
NASM version 0.98.39 compiled on Jan 6 2007
(sorry for zip, can't attach .o/.obj)

Download
Filename: lcc-nasm-hello.zip
Filesize: 692 Bytes
Downloaded: 805 Time(s)

Post 23 Apr 2011, 00:26
View user's profile Send private message Reply with quote
Tarkin



Joined: 27 Aug 2010
Posts: 22
Tarkin 23 Apr 2011, 00:29
Here is the object file produced from lcc-4.2 w/ FASM backend


Description: lcc-4.2 GNU/Linux
flat assembler version 1.69.31
(sorry about the zip, can't attach .o/.obj)

Download
Filename: lcc-fasm-hello.zip
Filesize: 586 Bytes
Downloaded: 834 Time(s)

Post 23 Apr 2011, 00:29
View user's profile Send private message Reply with quote
Tarkin



Joined: 27 Aug 2010
Posts: 22
Tarkin 23 Apr 2011, 01:07
And, for comparison, here is hello.o from lcc-3.6 w/ fasm.

Also, here are the specs for the build machine:
(uname -a)
Linux sgmtech5 2.6.18-238.5.1.el5 #1 SMP Fri Apr 1 18:42:32 EDT 2011 i686 i686 i386 GNU/Linux

(gcc -v)
gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)

(dmesg | grep CPU)
Initializing CPU#0
CPU 0 irqstacks, hard=c076c000 soft=c074c000
CPU: After generic identify, caps: bfebfbff 00000000 00000000 00000000 00004400 00000000 00000000
CPU: After vendor identify, caps: bfebfbff 00000000 00000000 00000000 00004400 00000000 00000000
CPU: Trace cache: 12K uops, L1 D cache: 8K
CPU: L2 cache: 512K
CPU: Hyper-Threading is disabled
CPU: After all inits, caps: bfebf3ff 00000000 00000000 00000080 00004400 00000000 00000000
Intel machine check reporting enabled on CPU#0.
CPU0: Intel P4/Xeon Extended MCE MSRs (12) available
CPU0: Thermal monitoring enabled
CPU0: Intel(R) Pentium(R) 4 CPU 2.80GHz stepping 09
Brought up 1 CPUs
microcode: CPU0 updated from revision 0x17 to 0x2e, date = 08112004

TTFN,
Tarkin


Description: lcc v 3.6 w/ fasm
fasm-1.69.31

Download
Filename: lcc-3.6-fasm-hello.zip
Filesize: 426 Bytes
Downloaded: 801 Time(s)

Post 23 Apr 2011, 01:07
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.