emreesir 0 Newbie Poster

Hello everybody,
I am using both c and assembly (assembly is with nasm and op:Linux)

in C:

typedef struct linkednode *linkednode_ptr;
typedef struct linkednode{
	int freq;
	char symbol;
	linkednode_ptr node;	
};
linkednode_ptr get_linkednode(char symbol, int freq)
{
	linkednode_ptr r = (linkednode_ptr)malloc(sizeof(struct linkednode));
	r->node=NULL;
	r->symbol=symbol;
	r->freq=freq;
	return r;
}

in c, I use struct and only doing allocate memory for new node
in asm

head DW 0                                ;head of list
SECTION .bss	
pNode:	resd 1			        ; previous node
nNode: resd 1                               ; next node
cNode: resd 1                               ; current node

segment .text
push dword[freq]
	push dword [symbol]
	
		
	call get_linkednode
	

	mov [cNode],eax
	mov eax,0
	mov [pNode],eax
	mov eax,[head]
	mov [nNode],eax

	FIN:
		mov esi,[pNode]
		cmp esi,0
		jnz NOTHEAD
		mov eax,[cNode]
		mov [head],eax
		mov esi,[cNode]
		mov eax,[nNode]
		mov dword [esi+8],eax ; I think this line make segmentesion

this code for add a new node to head but gives segmentesion, do u have any idea ??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.