Hi,
I'm using Turbo C 2.01 and im stuck with this problem.
I've reduced it to the following. My code in Turbo C is this:
void f(char *);
char h[] = "hello";
void main() {
f(h);
}
void f(char *s) {
int n = 0;
while (s[n] != 0) {
/*do something*/
n++;
}
}
It's just a function that takes a string as an argument and merely loops till it finds the terminating NULL character.
I compile it like this (the file is named c.c):
tcc -mt c.c
tlink C.OBJ
and then i do exe2bin C.EXE to get the raw binary image.
The disassembly for either the .bin or .exe (they are the same, but it's easier to work with the .bin because it doesn't have the "turbo c junk code") is the following:
0000 mov ax, 000E
0003 push ax
0004 call 0009
0007 pop cx
0008 ret
0009 push bp
000A mov bp, sp
000C push si
000D xor si, si
000F jmp 0012
0011 inc si
0012 mov bx, [bp+04]
0015 cmp byte ptr [bx+si], 00
0018 jne 0011
001A pop si
001B pop bp
001C ret
001E 'hello\0' ;you get me :)
So, the problem is the first line!
mov ax, 000E
It doesn't point to the string, which is located in 001E, so if i change that byte with a hexadecimal editor the program works just fine.
My question is: why does Turbo C commit this error? Am i doing something wrong?
Thanks