The program initializes the stack pointer to 2000, loads the value 11 into the stack, and loads the value 3 into register D0. It then enters a loop where it decrements D0 and stores it in the stack, compares D0 to 2, and branches back to the start of the loop if D0 is greater than or equal to 2. This loop will repeat 3 times as D0 is initially 3 and decrements by 1 each pass until it is no longer greater than 2.
Draw the stack memory map for each of the following program- How many.docx
1. 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
2. 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.
Memory Address Value
2000 B
1FFF 3
1FFE 2