Department Software Engineering of Embedded Systems Prof. Dr. Sabine
Glesner www.pes.tu-berlin.de Secretariat TEL 12-4 Ernst-Reuter-Platz 7 10587 Berlin Exercise to the Lecture Analysis and Optimisation of Embedded Systems SS 2014 Prof. Dr. Sabine Glesner Dipl.-Inf. Sebastian Schlesinger Exercise 1 Distribution: April 25, 2014 Discussion: April 30, 2014 Introduction The process for performing the exercise is in principle as follows: The exercise sheets are distributed together with the lecture (usually on Monday; distribution day) and uploaded to the ISIS2 website. In the exercise (usually on Friday = discussion day) after the subsequent lecture, this exercise sheet is presented (so you have generally approx. two weeks between receiving the exercise sheet and presenting the results). Please prepare yourself for the exercise. Generally, the solution of each problem will be presented by students. There will be two distinguished exercise sheets. If you wish to perform an exam, you must handle both exercise sheets successfully. Details will be provided in time. If a problem requires additional knowledge not provided in the lecture, it is shown in a supplemental background section directly after the problem. Problem 1: Loop Semantics a) Consider the following programme: f o r i =1 s t ep k to n do pr i nt i ; od 1 Let k = 1. How would you translate this loop in Assembler? The output shall be realised by assigning i to a specic memory address. Is your implementation also correct for n = maxint? Is your implementation also correct if k is assigned dynamically? b) Consider the following programme: whi l e c ondi t i on do i :=i +1; a:=a i ; b: =( x1 x2 ) / ( x1 + x2 ) ; od Can b be removed from the loop and put outside of the loop? Replace condition with i < 100 and (x 1 + x 2 ) = 0 and rethink your answer. Dene a transformed programme with the same semantics that calculates b only once. c) Consider the following programme: c l a s s Test i s main i s r : FLT r : =0. 7100000. 0+0. 3; r :=r 1000000. 0; r : =( r 300000. 0)/10000000000. 0; i f r =7.0 then << OK e l s e << No, r /=7. r = ; <<r end end end TEST The output of the programme is No, r/=7. r=7. How could this happen? Background: Assembler 2 You are going to need some basic knowledge in Assembler syntax and semantics in order to solve this problem. Please nd some essentials below. If you require more assistance, look for the keyword in the internet. Assembler statements which you potentially require are ADD <register/address>,<register/address/value> adds the second to the rst argument (value or value at the given address or register) and stores the result in the rst MOV <register/address>,<register/address/value> puts the second argument into the address or register of the rst argument INC <register/address> increments (adds 1) CMP <register/address>,<register/address/value> compares the arguments. The result can be used in the subsequent line by JLE or JGE JMP <label> unconditionally jumps to the label (labels are dened at the be- ginning of a line, e.g. L1: MOV AX, BX JLE <label> jumps to the label if the rst argument was less or equal than the second argument JGE <label> jumps to the label if the rst argument was greater or equal than the second argument. Use registers AX, BX, CX, ... or values as arguments in the context of this problem. Problem 2: Reading Assignment: Y2K Problem [Reps97] describes an approach to test and debug programmes by comparing path spectra which are generated during programme execution. The approach and its advantages are illustrated with the Y2K problem. Please read the article carefully and answer the following questions: What is meant by the term Y2K problem? Why was it so dicult to resolve the problem? Describe how path proling can be utilised to obtain the Y2K error. Identify the shortest prex of the path [a, c, e, f] for the post-2000 run given in the article. What other uses of path proling for the Y2K problem can be helpful? What are the disadvantages of Edge Proling in comparison to Path Proling? 3 Consider now the following modied programme: a : bi r t h ye ar :=read ( ) ha s c o l l e g e de g r e e :=read ( ) age := c ur r e nt ye ar ()bi r t h ye ar i f age < 15 then b : . . . e l s e c : . . . i f ha s c o l l e g e de g r e e=t r ue then d : . . . e l s e e : . . . f i i f pur chases > 3 then f : . . . e l s e g : . . . f i f i Dene the control ow graph analogously to gure 2. Set up a table in which all paths of the modied programme from start to target together with the path numbers are listed. Identify the shortest prex of path [a, b, d, g] for the pre-2000 run. Utilise the Ball- Larus scheme for numbering paths. The authors describe other application elds for their approach. Name them and describe them briey. Literature [Reps97] Reps, T.; Ball, T.; Das, M.; Larus, J. The Use of Program Proling for Software Maintenance with Applications to the Year 2000 Problem. In ESEC 97/FSE- 5: Proceedings of the 6th european conference held jointly with the 5th ACM SIGSOFT international symposium on Foundations of software engineering, Springer New York Inc., 1997, p. 432-449. - ISBN 3-540-63531-9. 1 1 http://portal.acm.org/citation.cfm?id=267925 4