Problem 3 40 Points The program given below implements a del
Solution
a) To conver the given code to a subroutine we need to take care of ######## things,
1. We need to save the return address before going to the subroutine which is done by JSR.
2. Since we need to pass the time in seconds as a parameter, we save it in A register and use the value of A in the subroutine. Then multiply it by 10 inside the subroutine and then loop through the code so that we will get the required delay.
One loop of code = 0.1 sec
For 1 sec we need to loop 10 times the code, so we need to multiply by 10.
The code is now,
DELAY: org $2200
ASL \" Multiply Accumulator by 2,Shift left\"
STA TMP \"TEMP = 2*Accumulator\"
ASL \"Multiply Acc by 2 again\"
ASL \"Multiply Acc again by 2, so acc contains 8*initial value\"
CLC \"Clear carry\"
ADC TMP \"Acc = 2*Initial value + 8*Initial value\"
HERE: DEC \"Decrement accumulator\"
LDY #12 \"Stores number 12 in Y register\"
Loop2: LDX #40000 \"Stores number 40000 in X register\"
Loop1: NOP
DEX \"Decrement X register\"
BNE Loop1 \"Go to Loop1 if X is not equal to zero\"
DEY \"Decrement Y register\"
BNE Loop2 \"Go to Loop2 if Y is not equal to zero\"
END: SWI \"Software Interrupt\"
RTS \"Return from Subroutine\"
b).The maximum delay that our subroutine could implement is
(Max value that can be stored in Accumulator * 0.1) seconds.
Because We are looping through the code depending on the accumulator value so we can loop maximum to the number that can be stored in accumulator.
c). To implement 13.2 seconds delay, we need to modify our subroutine to add a memory location which contains the integer part of seconds as a value. Then loop through the given code as many times as the value in that memory location. So because of decrementing accumulator we get 13 seconds delay and from that value in memory we get 0.2 seconds delay.
example: store 13 in accumulator and store 2 in the memory location.
d). To make the loop implement delays in multiple of 0.5 seconds instead of multiplying the values by 10, we need to multiply the Accumulator by 5( store ACC in TEMP then ASL accumulator 2 times then add TEMP to ACC, the result in accumulator will be 5*initial value) so for 1 in Acc the code implements 0.5 seconds delay.

