Simple puts() function in x64 assembly
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I'm trying to write as simple I/O library in x64 using linux syscalls
section .text
strlen:
xor rdx, rdx
.loop:
cmp [rsi + rdx], 0
je .exit
inc rdx
jmp .loop
.exit:
ret ; value in rdx
puts:
; string passed through rsi
mov rax, 1 ; WRITE syscall
mov rdi, 1 ; fd for stdout
call strlen
syscall
strings io linux assembly x86
add a comment |Â
up vote
2
down vote
favorite
I'm trying to write as simple I/O library in x64 using linux syscalls
section .text
strlen:
xor rdx, rdx
.loop:
cmp [rsi + rdx], 0
je .exit
inc rdx
jmp .loop
.exit:
ret ; value in rdx
puts:
; string passed through rsi
mov rax, 1 ; WRITE syscall
mov rdi, 1 ; fd for stdout
call strlen
syscall
strings io linux assembly x86
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm trying to write as simple I/O library in x64 using linux syscalls
section .text
strlen:
xor rdx, rdx
.loop:
cmp [rsi + rdx], 0
je .exit
inc rdx
jmp .loop
.exit:
ret ; value in rdx
puts:
; string passed through rsi
mov rax, 1 ; WRITE syscall
mov rdi, 1 ; fd for stdout
call strlen
syscall
strings io linux assembly x86
I'm trying to write as simple I/O library in x64 using linux syscalls
section .text
strlen:
xor rdx, rdx
.loop:
cmp [rsi + rdx], 0
je .exit
inc rdx
jmp .loop
.exit:
ret ; value in rdx
puts:
; string passed through rsi
mov rax, 1 ; WRITE syscall
mov rdi, 1 ; fd for stdout
call strlen
syscall
strings io linux assembly x86
strings io linux assembly x86
edited 16 mins ago
asked 4 hours ago
Meme myself and a very creepy
514
514
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
Your loop uses 2 jumps (je
/jmp
) on every iteration! Jumping is expensive, so a solution that needs only 1 jump (jne
) will be more effective.
strlen:
xor rdx, rdx
dec rdx ; This compensates for the INC that is happening first.
.next:
inc rdx
cmp byte [rsi + rdx], 0
jne .next
ret
Do keep things logically together. There's no point in setting RAX
before the call to strlen.
puts:
; string passed through rsi
call strlen ; Result is in RDX
mov rax, 1
syscall
Would it be best to make an generalization of this and cal itfputs
then have puts justmov rdi, 1
and call puts?
â Meme myself and a very creepy
19 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Your loop uses 2 jumps (je
/jmp
) on every iteration! Jumping is expensive, so a solution that needs only 1 jump (jne
) will be more effective.
strlen:
xor rdx, rdx
dec rdx ; This compensates for the INC that is happening first.
.next:
inc rdx
cmp byte [rsi + rdx], 0
jne .next
ret
Do keep things logically together. There's no point in setting RAX
before the call to strlen.
puts:
; string passed through rsi
call strlen ; Result is in RDX
mov rax, 1
syscall
Would it be best to make an generalization of this and cal itfputs
then have puts justmov rdi, 1
and call puts?
â Meme myself and a very creepy
19 mins ago
add a comment |Â
up vote
2
down vote
Your loop uses 2 jumps (je
/jmp
) on every iteration! Jumping is expensive, so a solution that needs only 1 jump (jne
) will be more effective.
strlen:
xor rdx, rdx
dec rdx ; This compensates for the INC that is happening first.
.next:
inc rdx
cmp byte [rsi + rdx], 0
jne .next
ret
Do keep things logically together. There's no point in setting RAX
before the call to strlen.
puts:
; string passed through rsi
call strlen ; Result is in RDX
mov rax, 1
syscall
Would it be best to make an generalization of this and cal itfputs
then have puts justmov rdi, 1
and call puts?
â Meme myself and a very creepy
19 mins ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Your loop uses 2 jumps (je
/jmp
) on every iteration! Jumping is expensive, so a solution that needs only 1 jump (jne
) will be more effective.
strlen:
xor rdx, rdx
dec rdx ; This compensates for the INC that is happening first.
.next:
inc rdx
cmp byte [rsi + rdx], 0
jne .next
ret
Do keep things logically together. There's no point in setting RAX
before the call to strlen.
puts:
; string passed through rsi
call strlen ; Result is in RDX
mov rax, 1
syscall
Your loop uses 2 jumps (je
/jmp
) on every iteration! Jumping is expensive, so a solution that needs only 1 jump (jne
) will be more effective.
strlen:
xor rdx, rdx
dec rdx ; This compensates for the INC that is happening first.
.next:
inc rdx
cmp byte [rsi + rdx], 0
jne .next
ret
Do keep things logically together. There's no point in setting RAX
before the call to strlen.
puts:
; string passed through rsi
call strlen ; Result is in RDX
mov rax, 1
syscall
answered 3 hours ago
Fifoernik
30027
30027
Would it be best to make an generalization of this and cal itfputs
then have puts justmov rdi, 1
and call puts?
â Meme myself and a very creepy
19 mins ago
add a comment |Â
Would it be best to make an generalization of this and cal itfputs
then have puts justmov rdi, 1
and call puts?
â Meme myself and a very creepy
19 mins ago
Would it be best to make an generalization of this and cal it
fputs
then have puts just mov rdi, 1
and call puts?â Meme myself and a very creepy
19 mins ago
Would it be best to make an generalization of this and cal it
fputs
then have puts just mov rdi, 1
and call puts?â Meme myself and a very creepy
19 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f206381%2fsimple-puts-function-in-x64-assembly%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password