我正在尝试在程序集中构建一个链表(不要问为什么),链表必须在我构建的堆栈中。我在 ubuntu 上使用带有 intel 80x86 的 nasm 这是链接列表:
size_i:
struc node
data: resb 1
next: resb 4
endstruc
size_of_struct: equ $-size_i
这是堆栈:
create_stack:
push STKSZ*4
call malloc
add esp,4 ;correct the push
mov dword[my_stack],eax
ret
现在,我们从用户那里读取一个数字,每个字节都被寻址到列表中的不同节点。这就是我尝试创建新列表的方式:
create_new_list:
push size_of_struct
call malloc ;now eax has pointer to location
add esp,4 ;correct the push
mov edx,0
mov dl,byte[ebx] ;dl is the data of current number (current digit)
mov byte[eax+data],dl ;set the data
mov dword[eax+next],0 ;set next to be null
;BUILD THE FIRST NODE IN EAX
push edx
push ecx
push eax
mov eax,0
mov ecx,dword[my_stack]
mov dword[curr_stack_pointer],ecx
mov ecx,0
mov cl,byte[counter]
mov al,4
mul cl
add dword[curr_stack_pointer],eax
;DWORD[CURR_STACK_POINTER] HAS THE POINTER TO HEAD OF LIST
pop eax
mov ecx,dword[curr_stack_pointer]
mov [ecx],eax ;THIS IS THE PROBLEMATIC LINE. HERE I AM TRYING TO
;MOV THE ADDRESS INSIDE EAX TO THE LOCATION OF ECX
;THIS WAY I WILL HAVE IN THE CURRENT ARRAY BLOCK THE ADDRESS
;OF THE HEAD OF THE LIST. BUT IT IS NOT WORKING, I GET A
;SEGMENTATION ERROR
pop ecx
pop edx
ret
我怎样才能做到这一点?谢谢!