Copy a string: Difference between revisions

no edit summary
No edit summary
Line 2,298:
ret
</lang>
 
=={{header|X86-64 Assembly}}==
===UASM 2.54===
<lang asm>
option casemap:none
option literals:on
 
printf proto :dword, :VARARG
exit proto :dword
 
.data
s db "Goodbye, World!",0
 
.data?
d db 20 dup (?)
dp dq ?
tb dd ?
 
.code
main proc
lea rsi, s ;; Put the address of var S into the source index(RSI)
xor rcx, rcx ;; Zero out RCX
_getsize:
inc rcx ;; Advanced the index by 1
cmp byte ptr [rsi+rcx],0 ;; check the current byte for terminating 0
jne _getsize ;; nope, jump back and check again
 
mov tb, ecx ;; tb = Total bytes
lea rsi, s ;; Copy the address of s into the source index(rsi)
lea rdi, d ;; Copy the address of d into the destination index(rdi)
rep movsb ;; Copy bytes from ESI to EDI until RCX is 0
lea rax, s ;; Get the address of S
mov dp, rax ;; Copy it from RAX to dp
mov rbx,rdi ;;preserve registers, cause over writes due to ABI calls T_T
invoke printf, CSTR("-> s (0x%x) = %s",10), rsi, addr s
invoke printf, CSTR("-> d (0x%x) = %s",10), rbx, addr d
invoke printf, CSTR("-> dp (0x%x) = %s",10), addr dp, dp
invoke printf, CSTR("-> bytes copied: %i",10), tb
xor rsi, rsi
call exit
ret
main endp
 
end
</lang>
Output
<pre>
-> s (0x40303f) = Goodbye, World!
-> d (0x40309f) = Goodbye, World!
-> dp (0x4030a4) = Goodbye, World!
-> bytes copied: 15
</pre>
 
=={{header|XPL0}}==