Use another language to call a function: Difference between revisions
Content added Content deleted
(It is what it is -_-) |
(→UASM 2.52: reworked the UASM example, added NASM) |
||
Line 2,128: | Line 2,128: | ||
<lang asm> |
<lang asm> |
||
option casemap:none |
option casemap:none |
||
strlen proto :qword |
|||
strncpy proto :qword, :qword, :dword |
|||
Query proto :qword, :qword |
Query proto :qword, :qword |
||
Line 2,136: | Line 2,140: | ||
.code |
.code |
||
Query proc Data:qword, len:qword |
Query proc Data:qword, len:qword |
||
local d:qword, l:qword, s:dword |
|||
mov |
mov d, Data |
||
mov |
mov l, len |
||
invoke strlen, addr szstr |
|||
.if rax <= l |
|||
⚫ | |||
⚫ | |||
invoke strncpy, d, addr szstr, s |
|||
⚫ | |||
mov |
mov eax, s |
||
mov |
mov rax, l |
||
⚫ | |||
⚫ | |||
mov rax, |
mov rax, 1 |
||
ret |
|||
⚫ | |||
.endif |
|||
⚫ | |||
⚫ | |||
ret |
ret |
||
⚫ | |||
</lang> |
|||
===NASM=== |
|||
<lang asm> |
|||
section .data |
|||
szmsg db "Here I am",0 |
|||
section .text |
|||
global Query |
|||
strlen: |
|||
push rbp |
|||
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 |
ret |
||
⚫ | |||
Query: |
|||
end |
|||
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 |
|||
⚫ | |||
mov rax, r8 |
|||
mov dword [rax], r10d |
|||
jmp _exit |
|||
⚫ | |||
mov rax, 0 |
|||
_exit: |
|||
pop rbp |
|||
ret |
|||
</lang> |
</lang> |
||