What's wrong in this ?
Posted: Wed Jul 23, 2003 11:00 pm
I do not get any compile or link error but when it comes to execution - The program does print 'Hello World' but then it dumps a stack trace on the screen.
Stack Trace with output 'Hello World':
Hello WorldExiting due to signal SIGSEGV
General Protection Fault at eip=0000160a
eax=00000dff ebx=000001c1 ecx=00000000 edx=0000033f esi=0000160e edi=0000d762
ebp=0008d718 esp=0008d718 program=F:\OS\SOURCE\PRINT\CALLPR~1.EXE
cs: sel=01a7 base=01c10000 limit=0009ffff
ds: sel=01af base=01c10000 limit=0009ffff
es: sel=01af base=01c10000 limit=0009ffff
fs: sel=017f base=00005c10 limit=0000ffff
gs: sel=01bf base=00000000 limit=0010ffff
ss: sel=01af base=01c10000 limit=0009ffff
App stack: [0008d760..0000d760] Exceptn stack: [0000d6c0..0000b780]
Call frame traceback EIPs:
0x0000160a
0x0000162e
0x00002e88
----------------------------------------------------------------------
Source Code:
//C Code to call print defined in ASM
#include<stdio.h>
int main()
{
char *s = "Hello World";
print(s);
}
//ASM code to print
global _print
SEGMENT .text
[BITS 32]
_print:
push ebp
mov ebp, esp
mov esi,[ebp+8]
.continue
lodsb
mov ah,0x0E
or al,al
jz .end
int 0x10
jmp .continue
.end
Stack Trace with output 'Hello World':
Hello WorldExiting due to signal SIGSEGV
General Protection Fault at eip=0000160a
eax=00000dff ebx=000001c1 ecx=00000000 edx=0000033f esi=0000160e edi=0000d762
ebp=0008d718 esp=0008d718 program=F:\OS\SOURCE\PRINT\CALLPR~1.EXE
cs: sel=01a7 base=01c10000 limit=0009ffff
ds: sel=01af base=01c10000 limit=0009ffff
es: sel=01af base=01c10000 limit=0009ffff
fs: sel=017f base=00005c10 limit=0000ffff
gs: sel=01bf base=00000000 limit=0010ffff
ss: sel=01af base=01c10000 limit=0009ffff
App stack: [0008d760..0000d760] Exceptn stack: [0000d6c0..0000b780]
Call frame traceback EIPs:
0x0000160a
0x0000162e
0x00002e88
----------------------------------------------------------------------
Source Code:
//C Code to call print defined in ASM
#include<stdio.h>
int main()
{
char *s = "Hello World";
print(s);
}
//ASM code to print
global _print
SEGMENT .text
[BITS 32]
_print:
push ebp
mov ebp, esp
mov esi,[ebp+8]
.continue
lodsb
mov ah,0x0E
or al,al
jz .end
int 0x10
jmp .continue
.end