Anonymous user
Use another language to call a function: Difference between revisions
Use another language to call a function (view source)
Revision as of 05:51, 27 October 2021
, 2 years ago→UASM 2.52: reworked the UASM example, added NASM
(It is what it is -_-) |
(→UASM 2.52: reworked the UASM example, added NASM) |
||
Line 2,128:
<lang asm>
option casemap:none
strlen proto :qword
strncpy proto :qword, :qword, :dword
Query proto :qword, :qword
Line 2,136 ⟶ 2,140:
.code
Query proc Data:qword, len:qword
local d:qword, l:qword, s:dword
mov
mov
ja _err▼
invoke strncpy, d, addr szstr, s
mov ecx, r10d▼
mov
mov
rep movsb▼
mov rax,
ret
▲ mov dword ptr [rax], r10d
.endif
▲ mov eax, 1
ret
Query endp▼
</lang>
===NASM===
<lang asm>
section .data
szmsg db "Here I am",0
section .text
global Query
mov rbp, rsp
mov rsi, rdi
mov rcx, -1
_1:
inc rcx
cmp byte [rsi+rcx], 0
jne _1
mov rax, rcx
pop rbp
ret
▲Query endp
Query:
push rbp
mov rbp, rsp
;;mov r9, rcx ;;Arg 1, windows
;;mov r8, rdx ;;Arg 2, windows
mov r9, rdi ;;Arg 1, Linux
mov r8, rsi ;;Arg 2, Linux
lea rdi, szmsg
call strlen
cmp rax, r8
jg _err
mov r10d, eax
mov rdi, r9
lea rsi, szmsg
▲ rep movsb
mov rax, r8
mov dword [rax], r10d
jmp _exit
mov rax, 0
_exit:
pop rbp
ret
</lang>
|