Draw the stack memory map for each of the following program. How many times does each program jump back to the label REPEAT?
STARTÂ Â ORG $1000
MOVEA.L #$2000,A7
MOVE.L #11,(A7)
MOVE.L #3,D0
REPEAT
MOVE.L D0,-(A7)
CMP.L #2,D0
DBPL D0,REPEAT
STOP #$2700
END START
Solution
STARTÂ Â ORG $1000 //orgin of program is 1000
MOVEA.L #$2000,A7 // Stack pointer is 2000
MOVE.L #11,(A7) // move 11 (hex B) to stack
MOVE.L #3,D0 // move 3 to D0
REPEAT
MOVE.L D0,-(A7) // Decrement stack pointer and move D0
CMP.L #2,D0 // compare D0 with 2
DBPL D0,REPEAT // If result of compare is positive decrement D0 and branch to repeat
STOP #$2700 // Stop after loading 2700 to base register
END START
Hence
Stack
As it is clear the loop will run 3 times.
since first time 3 will become 2 (3-2 positive) second time ( 2-2 positive ; 0 is positive) 1-2 is negative loop will exit.
.