// MIT License
//
// Copyright (c) 2021 FPGAcademy.org
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

DEPTH 4096
// Stack and shift examples adapted from FPGAcademy.org, MIT.
stack_example:  mvt   sp, #0x10      // sp = 0x1000 = 4096
        mv    r4, =0x0F0F
        push  r4
        bl    SUBR
        pop   r4
        b     check_stack

SUBR:   sub   r4, r4
        mv    pc, lr

check_stack:
        mv r1,=0x0F0F
        cmp r4,r1
        bne fail
        mv r2,=0x0FFF
        ld r1,[r2]
        cmp r4,r1
        bne fail
        mv r1,=0x1000
        cmp sp,r1
        bne fail
shift_example:  mv    r0, #4
        mv    r4, =0x0F0F
        lsl   r4, #1        // lsl with Op2 = #D
        lsr   r4, #1        // lsr with Op2 = #D
        lsl   r4, r0        // lsl with Op2 = rY
        asr   r4, #1        // asr with Op2 = #D
        ror   r4, r0        // ror with Op2 = rY
        b     check_shift

check_shift:
        mv r1,=0x8F87
        cmp r4,r1
        bne fail
        mv r0,=0x8001
        lsl r0,#1
        bcc fail
        lsl r0,#1
        bcs fail
        cmp r0,#4
        bne fail
        mv r3,#85
        b report
fail:   mv r3,#15
report: mvt r2,#0x10
        st r3,[r2]
hold:   b hold
