| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Passing a var. |
* David Nugent writes to Rowan Crowe, on Friday September 06 1996
at 02:43:
RC>> Some optimise better, some might do graphics
RC>> faster (ahem, ok, I know we're talking about portable
RC>> code), some may do file I/O better.
DN> .. but none of these are "compiler" issues. They are
features of the
DN> runtime library supplied along with it.
Okay, apart from the optimisation factor, how about we say "Not all
compiler packages are equal"? :)
Consider this snippet of 'raw' C code:
/*
** return 0 a_ording to
** st
*/
strcmp(s, t) char *s, *t; {
while(*s == *t) {
if(*s == 0) return (0);
++s; ++t;
}
return (*s - *t);
}
; strcmp(s, t) char *s, *t; {
_STRCMP:
push bp
mov bp,sp
; while(*s == *t) {
_2:
lea bx,[bp+6]
mov ax,[bx]
mov bx,ax
mov al,[bx]
cbw
push ax
lea bx,[bp+4]
mov ax,[bx]
mov bx,ax
mov al,[bx]
cbw
pop bx
call __EQ
or ax,ax
jnz short LL1
jmp _3
LL1:
; if(*s == 0) return (0);
lea bx,[bp+6]
mov ax,[bx]
mov bx,ax
mov al,[bx]
cbw
or ax,ax
jz short LL2
jmp _4
LL2:
xor ax,ax
pop bp
ret
; ++s; ++t;
_4:
lea bx,[bp+6]
mov ax,[bx]
inc ax
mov [bx],ax
lea bx,[bp+4]
mov ax,[bx]
inc ax
mov [bx],ax
; }
jmp _2
_3:
; return (*s - *t);
lea bx,[bp+6]
mov ax,[bx]
mov bx,ax
mov al,[bx]
cbw
push ax
lea bx,[bp+6]
mov ax,[bx]
mov bx,ax
mov al,[bx]
cbw
pop bx
xchg ax,bx
sub ax,bx
pop bp
ret
; }
; strcmp(s, t) char *s, *t; {
;
assume cs:_TEXT
_strcmp proc near
push bp
mov bp,sp
push si
push di
mov si,word ptr [bp+4]
mov di,word ptr [bp+6]
jmp short {at}1{at}142
{at}1{at}58:
;
; while(*s == *t) {
; if(*s == 0) return (0);
;
cmp byte ptr [si],0
jne short {at}1{at}114
xor ax,ax
pop di
pop si
pop bp
ret
{at}1{at}114:
;
; ++s; ++t;
;
inc si
inc di
{at}1{at}142:
mov al,byte ptr [si]
cmp al,byte ptr [di]
je short {at}1{at}58
;
; }
; return (*s - *t);
;
cbw
push ax
mov al,byte ptr [di]
cbw
mov dx,ax
pop ax
sub ax,dx
;
; }
;
pop di
pop si
pop bp
ret
_strcmp endp
Now, I don't claim to know much about C, in fact I know very little. I find
analysing the ASM output of compilers more interesting. :-) But it's quite
easy to see that there is a significant difference in the code that is
generated.
Can anyone guess which 2 compilers produced the above? The second should be
pretty obvious. The first is an ageing shareware C compiler which comes
with source code (with some slight modifications by myself).
Cheers.
---
* Origin: It's not so new now, but here 'tis anyway ---> (3:635/728.1)SEEN-BY: 50/99 620/243 623/630 632/349 635/503 544 727 728 670/218 711/401 SEEN-BY: 711/409 410 413 430 808 809 932 934 712/515 713/888 714/906 800/1 @PATH: 635/728 727 544 50/99 711/808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.