006-lea-slot.P1pp (1227B)
1 # tests/p1/lea-slot.P1pp -- exercise libp1pp %lea_slot. 2 # 3 # %lea_slot(rd, slot_expr) rd = address of frame slot at slot_expr. 4 # 5 # Equivalent to %mov(rd, sp) + %addi(rd, rd, slot_expr) — centralizes 6 # the hidden 16-byte frame header that the backend folds into %mov(rd, sp). 7 # 8 # Verification: store via sp-relative %st, read via address from 9 # %lea_slot, expect equality. Then write via address, read via sp, 10 # again expect equality. Two slots so we also verify slot offset != 0. 11 # Output: "AB\n". 12 13 %fn(p1_main, 16, { 14 # ---- A: write @sp+0, read via lea_slot ------------------------------ 15 %li(t0, 0xCAFEBABE) 16 %st(t0, sp, 0) 17 %lea_slot(s0, 0) 18 %ld(t1, s0, 0) 19 %bne(t0, t1, &.fail) 20 %la(a0, &c_a) %li(a1, 1) %call(&print) 21 22 # ---- B: write via lea_slot @offset 8, read via sp+8 ----------------- 23 %lea_slot(s0, 8) 24 %li(t0, 0xDEADBEEF) 25 %st(t0, s0, 0) 26 %ld(t1, sp, 8) 27 %bne(t0, t1, &.fail) 28 %la(a0, &c_b) %li(a1, 1) %call(&print) 29 30 %la(a0, &c_nl) %li(a1, 1) %call(&print) 31 %li(a0, 0) 32 %b(&.done) 33 34 :.fail 35 %la(a0, &c_x) %li(a1, 1) %call(&print) 36 %la(a0, &c_nl) %li(a1, 1) %call(&print) 37 %li(a0, 1) 38 :.done 39 }) 40 41 :c_a "A" 42 :c_b "B" 43 :c_x "X" 44 :c_nl " 45 " 46 47 :ELF_end