008-memcpy-call.P1pp (1104B)
1 # tests/p1/memcpy-call.P1pp -- libp1pp %memcpy_call macro. 2 # 3 # %memcpy_call(dst_reg, src_reg, n_imm) 4 # Convenience wrapper around libp1pp's memcpy: marshals dst/src into 5 # a0/a1, sets a2=n_imm, and invokes %call(&memcpy). dst_reg and 6 # src_reg must not be a0 (the dst move would clobber a different 7 # live input register). 8 # 9 # Verification: copy a 13-byte source buffer into a destination 10 # buffer and byte-compare. Output: "OK\n" on pass. 11 12 %fn(p1_main, 0, { 13 %la(s0, &dst) 14 %la(s1, &src) 15 %memcpy_call(s0, s1, 13) 16 17 # Verify dst[0..13] == src[0..13] 18 %li(t2, 0) 19 %loop_scoped({ 20 %li(t1, 13) 21 %if_eq(t2, t1, { %break }) 22 %la(s0, &dst) 23 %add(s0, s0, t2) 24 %lb(t0, s0, 0) 25 %la(s1, &src) 26 %add(s1, s1, t2) 27 %lb(t1, s1, 0) 28 %bne(t0, t1, &.fail) 29 %addi(t2, t2, 1) 30 }) 31 32 %la(a0, &c_ok) %li(a1, 3) %call(&print) 33 %li(a0, 0) 34 %b(&.done) 35 36 :.fail 37 %la(a0, &c_fail) %li(a1, 5) %call(&print) 38 %li(a0, 1) 39 :.done 40 }) 41 42 :src 43 "Hello, World!" 44 :dst 45 "............." 46 :c_ok 47 "OK 48 " 49 :c_fail 50 "FAIL 51 " 52 53 :ELF_end