Call a foreign-language function: Difference between revisions
Content added Content deleted
(→{{header|X86-64 Assembly}}: (N)asm calls Wren calls C. o.O) |
m (→NASM: Original stuff was acting weird, so.. simplified it.) |
||
Line 3,156: | Line 3,156: | ||
;; Just stored all the arguments on the stack just in case... |
;; Just stored all the arguments on the stack just in case... |
||
⚫ | |||
;; Honestly, if we ignore the module comparison this could be done like |
|||
⚫ | |||
⚫ | |||
mov rbp, rsp |
|||
lea rax, C_strdup |
|||
;; lea rax, C_strdup |
|||
;; pop rsp |
|||
;; ret |
|||
bindfunc: |
|||
⚫ | |||
mov rbp, rsp |
|||
sub rsp, (8*6) ;; make some space on the stack to store our arguments. |
|||
mov [rsp+32], rdi ;; WrenVM *vm - not used, Saved for consistancy. |
|||
mov [rsp+24], rsi ;; const char *module |
|||
mov [rsp+16], rdx ;; const char *className - not used, to lazy. |
|||
mov [rsp+8], rcx ;; bool isStatic - not used, to lazy. |
|||
mov [rsp+0], r8 ;; const char *signature - not used, still to lazy. |
|||
mov rdi, [rsp+24] |
|||
call strlen |
|||
cmp rax, 0 |
|||
jle _bf_fail |
|||
mov ecx, eax |
|||
lea rsi, mod |
|||
mov rdi, [rsp+24] |
|||
call strcmp |
|||
cmp eax, 0 |
|||
jne _bf_fail |
|||
lea rax, C_strdup |
|||
jmp _bf_exit |
|||
_bf_fail: |
|||
mov rax, 1 |
|||
_bf_exit: |
|||
add rsp, (8*6) |
|||
pop rbp |
|||
ret |
|||
;; strlen(rdi) - str1 - returns in eax |
|||
strlen: |
|||
push rbp |
|||
mov rbp, rsp |
|||
mov rax,-1 |
|||
_1: |
|||
inc eax |
|||
cmp byte [rdi+rax], 0 |
|||
jne _1 |
|||
pop rbp |
|||
ret |
|||
;;strcmp(rdi, rsi, ecx) str1, str2, maxlen |
|||
strcmp: |
|||
push rbp |
|||
mov rbp, rsp |
|||
repe cmpsb |
|||
jne _false |
|||
mov rax, 0 |
|||
jmp _true |
|||
_false: |
|||
mov rax, 1 |
|||
_true: |
|||
pop rbp |
pop rbp |
||
ret |
ret |