2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,4 +1,9 @@
|
|||
{{omit from|bc}}
|
||||
|
||||
This task is about copying a string.
|
||||
|
||||
|
||||
;Task:
|
||||
Where it is relevant, distinguish between copying the contents of a string
|
||||
versus making an additional reference to an existing string.
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
"Hello, world\n" dup cp
|
||||
str2ar dup 'Y' str2ar 0 paste ar2str
|
||||
<<
|
||||
<<
|
||||
babel> "Hello, world\n" dup cp dup 0 "Y" 0 1 move8
|
||||
babel> << <<
|
||||
Yello, world
|
||||
Hello, world
|
||||
|
|
|
|||
3
Task/Copy-a-string/Elena/copy-a-string.elena
Normal file
3
Task/Copy-a-string/Elena/copy-a-string.elena
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#var src := "Hello".
|
||||
#var dst := src. // copying the reference
|
||||
#var copy := src clone. // copying the content
|
||||
2
Task/Copy-a-string/Kotlin/copy-a-string.kotlin
Normal file
2
Task/Copy-a-string/Kotlin/copy-a-string.kotlin
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
val h = "Hello"
|
||||
val c = "" + h
|
||||
53
Task/Copy-a-string/MIPS-Assembly/copy-a-string.mips
Normal file
53
Task/Copy-a-string/MIPS-Assembly/copy-a-string.mips
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
.data
|
||||
ex_msg_og: .asciiz "Original string:\n"
|
||||
ex_msg_cpy: .asciiz "\nCopied string:\n"
|
||||
string: .asciiz "Nice string you got there!\n"
|
||||
|
||||
.text
|
||||
main:
|
||||
la $v1,string #load addr of string into $v0
|
||||
la $t1,($v1) #copy addr into $t0 for later access
|
||||
lb $a1,($v1) #load byte from string addr
|
||||
strlen_loop:
|
||||
beqz $a1,alloc_mem
|
||||
addi $a0,$a0,1 #increment strlen_counter
|
||||
addi $v1,$v1,1 #increment ptr
|
||||
lb $a1,($v1) #load the byte
|
||||
j strlen_loop
|
||||
|
||||
alloc_mem:
|
||||
li $v0,9 #alloc memory, $a0 is arg for how many bytes to allocate
|
||||
#result is stored in $v0
|
||||
syscall
|
||||
la $t0,($v0) #$v0 is static, $t0 is the moving ptr
|
||||
la $v1,($t1) #get a copy we can increment
|
||||
copy_str:
|
||||
lb $a1,($t1) #copy first byte from source
|
||||
|
||||
strcopy_loop:
|
||||
beqz $a1,exit_procedure #check if current byte is NULL
|
||||
sb $a1,($t0) #store the byte at the target pointer
|
||||
addi $t0,$t0,1 #increment source ptr
|
||||
addi $t1,$t1,1 #decrement source ptr
|
||||
lb $a1,($t1) #load next byte from source ptr
|
||||
j strcopy_loop
|
||||
|
||||
|
||||
exit_procedure:
|
||||
la $a1,($v0) #store our string at $v0 so it doesn't get overwritten
|
||||
li $v0,4 #set syscall to PRINT
|
||||
|
||||
la $a0,ex_msg_og #PRINT("original string:")
|
||||
syscall
|
||||
|
||||
la $a0,($v1) #PRINT(original string)
|
||||
syscall
|
||||
|
||||
la $a0,ex_msg_cpy #PRINT("copied string:")
|
||||
syscall
|
||||
|
||||
la $a0,($a1) #PRINT(strcopy)
|
||||
syscall
|
||||
|
||||
li $v0,10 #EXIT(0)
|
||||
syscall
|
||||
8
Task/Copy-a-string/Rust/copy-a-string-1.rust
Normal file
8
Task/Copy-a-string/Rust/copy-a-string-1.rust
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fn main() {
|
||||
let s1 = "A String";
|
||||
let mut s2 = s1;
|
||||
|
||||
s2 = "Another String";
|
||||
|
||||
println!("s1 = {}, s2 = {}", s1, s2);
|
||||
}
|
||||
1
Task/Copy-a-string/Rust/copy-a-string-2.rust
Normal file
1
Task/Copy-a-string/Rust/copy-a-string-2.rust
Normal file
|
|
@ -0,0 +1 @@
|
|||
s1 = A String, s2 = Another String
|
||||
Loading…
Add table
Add a link
Reference in a new issue