vec_push returns inserted index

This commit is contained in:
janis 2025-11-04 16:51:50 +01:00
parent fd8a1f74bf
commit 07dcaf6a64
Signed by: janis
SSH key fingerprint: SHA256:bB1qbbqmDXZNT0KKD5c2Dfjg53JGhj7B3CFcLIzSqq8

View file

@ -161,7 +161,8 @@ vec_get:
;; rdi: pointer to Vec struct ;; rdi: pointer to Vec struct
;; rsi: pointer to data to push ;; rsi: pointer to data to push
;; fn vec_push(vec: *mut Vec, data: &[u8]) ;; returns the index at which the item was pushed (the old length of the vector)
;; fn vec_push(vec: *mut Vec, data: &[u8]) -> usize
vec_push: vec_push:
push rbp push rbp
mov rbp, rsp mov rbp, rsp
@ -186,8 +187,9 @@ vec_push:
mov rdx, [rax + 24] ; item_size mov rdx, [rax + 24] ; item_size
call memcpy call memcpy
; vec.len += 1; ; vec.len += 1;
mov rax, [rsp] ; vec mov rdx, [rsp] ; vec
add qword [rax + 8], 1 mov rax, [rdx + 8]
add qword [rdx + 8], 1
add rsp, 24 add rsp, 24
pop rbp pop rbp
ret ret