    lcw r1 stack    ; setup the stack
    loa r3 r0       ; get input1
    loa r2 r0       ; get input2

    psh r2          ; save input2 on the stack
    lcw r2 add_then_double ; setup call to add_then_double
    cal r2 r2       ; call add_then_double
    pop r0          ; remove input2 from stack

    sto r3 r0       ; print out the result
    hlt

add
    psh r2          ; save the return address
    loa r2 r1 4     ; get the second argument
    add r3 r3 r2    ; add r3 = arg1 + arg2
    pop r2          ; get the return address
    jmp r2          ; return

double
    psh r2          ; save the return address
    add r3 r3 r3    ; double the input2
    pop r2          ; get the return address
    jmp r2          ; return

add_then_double
    psh r2          ; save the return address
    loa r2 r1 4     ; get the second argument

    psh r2          ; setup call for add
    lcw r2 add      ; r3 has input one, push input2 on stack
    cal r2 r2       ; call add
    pop r0          ; remove input2 from stack

    lcw r2 double   ; result of add is in r3
    cal r2 r2       ; call double

    pop r2          ; get the return address
    jmp r2          ; return

    dat 100         ; setup the stack
stack