RosettaCodeData/Task/Singly-linked-list-Element-insertion/X86-Assembly/singly-linked-list-element-insertion.x86
2023-07-01 13:44:08 -04:00

29 lines
553 B
Text

; x86_64 Linux NASM
; Linked_List_Insert.asm
%ifndef INSERT
%define INSERT
%include "Linked_List_Definition.asm" ; see LL def task
%include "Heap_Alloc.asm" ; see memory allocation task
section .text
; rdi - link to insert after
; rsi - value that the new link will hold
Insert_After:
push rdi
push rsi
mov rdi, linkSize
call alloc
cmp rax, 0
je Memory_Allocation_Failure_Exception
pop rdi
mov dword [rax + value], edi
pop rdi
mov rsi, qword [rdi + next]
mov qword [rax + next], rsi
mov qword [rdi + next], rax
ret
%endif