, Simple loop with exit in file Prog5_2.s ; Date: ; Re ; Author:- ; P 6th May 20
ID: 3725713 • Letter: #
Question
, Simple loop with exit in file Prog5_2.s ; Date: ; Re ; Author:- ; P 6th May 2011 visions:- 7th May 2011, Prog5_1.s modified to exit the loop J.R. Gibson erforms simple addition in a loop to illustrate the branch instruction AREA Add loop, CODE, READONLY EXPORT Reset_Handler code module named Add_Test ; indicate which instruction to run first WARNING- insert ENTRY directive for ADS systems ResetHandler - ; load initial value ; load value added each loop mys tart MOV r3,#0 MOV r1, #1 loop *loop entry point ADDS r3, r3, r7 BCC loop : repeatedly add value (set as 1) : loop for a long time : the next line causes the program to wait for the user to tell the IDE to ; stop the program running stop BAL END stop Program 5.2 A simple program with a loop exit mechanisrmExplanation / Answer
5.1)
ADDS r3,r3,r7
ADDS updates the N, Z, C and V flags according to the result.
hence if the value in r3 is maore than the max positive value which is 2,147,483,647 (or hexadecimal 7FFF,FFFF16) the carry flag is set to 1.
BCC loop stops if the Carry flag is set to 1. hence running time of the loop is 2,147,483,647 * 5 * 10 ^-8 => 107.37sec
5.2)
the ADDS operation takes 1 cycle and the branch operation takes 2 extra cycles i.e 3 cycles .
so the loop takes 4 cycles in total. cycle time = 5/4 *10^-8 = 1.25* 10^-8
5.3)
a) as explained in the first part the r3 is increamented until 2,147,483,647 and the next adds operation sets the carry flag hence it runs 2,147,483,647 times.
b) BPL runs the same number of times as BCC since once it adds something to 2,147,483,647 , negative numbers start coming on.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.