For this exercise, make sure you run all commands from the directory:
/path/to/cbat_tools/docs/exercises/03
There is a program at binary/main_1
. The source code is at binary/main_1.c.
You may imagine that this is a program used by a distributor of a particular product. The program takes as its argument the number of units ordered, and returns the price for that many units. There is a function calculate_price
that actually computes the price for the order.
Built in to the calculate_price
function is an algorithm for computing a discount, which can be summarized as follows:
There are some requirements on orders:
Try it out with various different numbers:
$ ./binary/main_1 50 $ ./binary/main_1 52 $ ./binary/main_1 500 $ ./binary/main_1 3400
Some time after the first program was written, an engineer decided to move the logic for smaller orders higher up in the calculate_price
function. Why this was done is now long forgotten. Whatever the case, the modified version of the program lives at binary/main_2
, and the source code lives at binary/main_2.c.
You can try this version of the program too:
$ ./binary/main_2 50 $ ./binary/main_2 52 $ ./binary/main_2 500 $ ./binary/main_2 3400
Your task is to figure out if the modified version of the program is functionally equivalent to the first version. Does the modified version of calculate_price
produce the same output as the original version, given the same arguments?
To answer that, use wp
to complete the following tasks:
RAX
of the function calculate_price
in the older program (binary/main_1
) and the newer program (binary/main_2
). Can binary/main_2
produce different output than main_1
, when given the same argument? (Note: wp
might take a minute or two to complete its analysis on this one.)calculate_price
behave differently than the original version?To see the solution, click here.