Deals 2021:

Here are the archived deals from 2021. For most recent deals goto DEALS

For deals from 2020, goto DEALS 2020

 

2021:

 


 

12/31/2021: Walgreens 8x10 Free photo - Code ZERO

Look in "photo" under shopping section for details of the offer: photo

 


 

12/25/2021: Walgreens 8x10 Free photo - Code FROSTY8X10

Look in "photo" under shopping section for details of the offer: photo

 


 

12/12/2021: Walgreens 5 Free 4x6 photo - Code 5FREEPRINT 

Look in "photo" under shopping section for details of the offer: photo

 


 

12/03/2021: Walgreens 8x10 Free photo - Code MERRY8X10

Look in "photo" under shopping section for details of the offer: photo

 


 

12/01/2021: Taco bell GC offer - 1 free combo per $25 in store, 10% off for online (expires 25th Dec, 2021):

Look in gift card section for details of the offer: gift cards

https://www.tacobell.com/online-gift-card-promotion-terms-and-conditions

 


 

12/01/2021: Taco Bell Offer: 24 days of free cravings with a purchase of $1+ on app - Valid 30th Nov, 2021 to 23rd Dec, 2021

https://slickdeals.net/f/15466036-taco-bell-rewards-free-mountain-dew-baja-blast-freeze-drink-when-you-make-1-purchase-via-app-valid-12-1-only?src=frontpage

https://www.tacobell.com/

One free purchase every day with $1+ purchase on app. Has to be a reward member, which is free to join. Deals are posted every day, check the link every day. Use the taco bell GC offer along with this.

 


 

11/26/2021: Newegg - 2 X 8gb DDR 4 memory sticks for $47

Look in "electronics" under shopping section for details of the offer: electronics

 


 

11/26/2021: Walgreens 8x10 Free photo - Code THANKFUL8X10

Look in "photo" under shopping section for details of the offer: photo

 


 

11/25/2021: HEB Gift Card Offer (in Texas stores only) - Buy Home Depot, Kohls, Academy, Childrens's Place, Vanilla Visa $100 GC, get $20 HEB GC free for each (expires 30th Nov, 2021):

Look in gift card section for details of the offer: gift cards

 


 

11/22/2021: American Express 20% discount on redeeming points for Gift cards: (valid until Dec 22, 2021)

This is one of the best sign on bonus. See in "credit cards" section: credit cards 

 


 

11/22/2021: Platinum Elite Visa Credit Card from Skyone with $600 sign on bonus (valid until Dec 31, 2021)

This is one of the best sign on bonus. See in "credit cards" section: credit cards

 


 

11/16/2021: Slickdeals $10 cashback on $25+ Macy's online purchase => expires 11/16/2021

Look in "cash back sites" section for details of the offer: cash back sites

 


 

11/14/2021: Walmart - Cordless hair trimmer for $17

https://slickdeals.net/f/15381895-wahl-color-pro-cordless-rechargeable-hair-clipper-trimmer-18-40?page=5#comments

It's cordless, works worldwide (100V-240V), and has lots of good reviews. If you find it cheaper anywhere else within 90 days, you can just return and rebuy. You can get really cheap ones for < $10 on sale once in a while in pharmacy sores, but I don't think you can get these quality ones for $17 anywhere. One haircut and you have recovered your investment !!

 


 

11/14/2021: Walgreens 8x10 Free photo - Code GRATEFUL8X10

Look in "photo" under shopping section for details of the offer: photo

 


 

11/14/2021: Walmart - 256 GB USB 3.0 flash drive for $20

Look in "electronics" under shopping section for details of the offer: electronics

 


 

11/12/2021: Walgreens 5X7 Free photo - Code  IGOTMYSHOT => expires in couple of days

Look in "photo" under shopping section for details of the offer: photo

 


 

11/10/2021: M1 Finance Brokerage Bonus Offer of $500  - expires Dec 31st, 2021

Look in brokerage account bonus section for details of the offer: best brokerage bonus

 


 

11/07/2021: Walgreens Offer - Multiple items for almost free (after Walgreens cash) at Walgreens for week of 11/07/21 to 11/13/21

This deal will have all below items for $5 or so, if you have the coupon "$5 WGC on $20+". This offer is there on many accounts, so look up in your account under coupons. Below are individual deals. You can mix and match to take the total above $20 after applying coupon FAST10 (but before applying any Manufacturer coupons (Man-Q), as the total can be below $20 after Man-Q, and still be elgible for $5 in WGC.

have multiple deals for this week. Some people also have an extra coupon in their account for $5 WGC for spending $20+, or $4 WGC for spending $25+. I'm listing items that will add up to $25 before manufacturer coupons. It has been confirmed that total before Manufacturer coupon count toward the total for reward purpose.

The links below are for each deal separately. Choose the ones you like.

1. Colgate for free: 1 for free after $2 coupon

https://slickdeals.net/f/15382471-walgreens-free-colgate-toothpaste

2. Razor for a $1 after $5 coupon.

https://slickdeals.net/f/15382444-bic-disposable-razors-various-1-walgreens-w-free-shipping

3. 28 oz shampoo + conditioner for $3

https://slickdeals.net/f/15382432-28-oz-tresemme-shampoo-or-conditioner-various-2-for-3-free-store-pickup

4. 2 cereals for $3

https://slickdeals.net/f/15382423-general-mills-cereals-10-8-oz-honey-nut-cheerios-more-2-for-2-76-free-store-pickup-at-walgreens

5. 2 soaps for $1.30

https://slickdeals.net/f/15382399-8-oz-sheamoisture-african-black-soap-2-for-1-28-free-ship-to-store-pickup-at-walgreens

6. 5 of 2L Pepsi bottles for $4 (not really cheap, as you can usually get them for < $1 a bottle on sale)

https://slickdeals.net/f/15379261-2-liter-pepsi-soda-reg-diet-cherry-max-mountain-dew-more-5-for-4-05-free-pickup-w-10-orders

7. 80 count wipes for $1 (these can be used as a filler to meet $20 threshold). The wipes are good for cleaning fans, pantries, bathrooms, etc.

https://slickdeals.net/f/15377746-80-count-wipe-out-antibacterial-wipes-lemon-1-free-ship-to-store-pickup

One possible combo is items 1, 2, 3, 4, 5 and 7 to get to over $20. After coupons price < $10 and you get $5 in WGC. So, effectively you are paying only $5 for all of these, which is as close to free as it can get !!

 


 

11/05/2021: Walgreens 8x10 Free photo - Code FALLSMILES

Look in "photo" under shopping section for details of the offer: photo

 


 

11/04/2021: Taco Bell Offer: Free Taco - Valid 4th Nov, 2021 only

https://www.tacobell.com/

Free locos taco offer is back. It says "A stolen base in the World Series™ won America a FREE Doritos® Locos Tacos. Get yours today online, on the app, or in-store."  As last time, you can just walk in and get your free taco, or order online or via app.

 


 

11/01/2021: Tastyworks Brokerage Bonus Offer of $500  - expiry unknown

Look in brokerage account bonus section for details of the offer: best brokerage bonus

 


 

10/30/2021: Walgreens 8x10 Free photo - Code ONEBIG8X10

Look in "photo" under shopping section for details of the offer: photo

 


 

10/25/2021: Sofi Money account - ($75 via slickdeals or $175 via swagbucks) + $100 for direct deposit => expiry unknown

Look in bank account bonus section for details of the offer: best bank bonus

 


 

10/22/2021: Kabbage (by Amex) $300 Checking Account (Business) Bonus offer (Nationwide) => expires 12/15/2021

Look in bank account bonus section for details of the offer: best bank bonus

 


 

10/21/2021: YMMV: Chase Freedom Credit Card and Debit Card Offer - Cashback on using card at McDonalds, Exxon Mobil and Walgreens (expires in 2-6 days)

First activate the offers on your card by logging into Chase website, and clicking "chase offers" on right side. These special deals are listed as "Flash deals". Just click on them, you should see a green tickmark, meaning the offer is activated. Then buy $20 GC at McDonalds, $40 GC at Walgreens and get $50 of gas at Exxon Mobil. That maximizes your cashback to $4+$8+$10=$22. Most people are getting these offers, so do check in your chase account. Bed Bath and Beyond is useless offer, since you can get their GC at 20% discount any time, and their stuff is over priced by 2X or more compared to other stores.

https://slickdeals.net/f/15348115-ymmv-chase-rewards-20-cashback-flash-deal-at-mcdonald-s-exxon-mobil-walgreens-bed-bath-and-beyond?src=frontpage

 


 

10/15/2021: Topcashback mystery offer every Friday until Thanksgiving - $2.50 cb on $10= purchase => expires 11/29/2021

Look in "cash back sites" section for details of the offer: cash back sites

 


 

10/14/2021: Kroger Gift Card Offer online - Buy any $25 GC for $20 (expires 10/17/2021):

Look in gift card section for details of the offer: gift cards

 


 

10/10/2021: Fifth third Bank $300 Checking Bonus offer (only selected states => Florida, Georgia, Illinois, Indiana, Kentucky, Michigan, North Carolina, Ohio, South Carolina, Tennessee, and West Virginia) => expires 12/31/2021

Look in bank account bonus section for details of the offer: best bank bonus

 


 

09/22/2021: Amazon Warehouse Deals - Extra 40% on selected items (expiry unknown):

https://slickdeals.net/f/15297616-amazon-warehouse-deals-select-used-open-box-items-various-categories-extra-40-off-limited-availability-stock

"40% off on used items" is the highest I've seen. However, amazon warehouse are not discounted that heavily to start with. So, research the price before falling for 40% off. Many of the items that I purchased before have gone up by 20% since last time, so 40% off gives you a litle worse deal than the 20% off from last time.

direct link: On clicking link below, you should see category as "Amazon Warehouse Deals". That shows all items for extra 40%. Now if you search for any item in this category, it will show only those items with extra 40% off. There will be sponsored items at top as well as items outside of this category at the bottom, do not click on those as those will take you out of "warehouse deals with 40% off". If you do so, you have again click the above "warehouse deals" link to get back.

https://www.amazon.com/s?i=warehouse-deals

 


 

09/21/2021: Walgreens 8x10 Free photo - Code 8X10AUTUMN

Look in "photo" under shopping section for details of the offer: photo

 


 

09/19/2021: OfficeDepot / OfficeMax - Free Non Rechargeable AA/AAA batteries after rewards (expires 09/25/2021):

Look in "electronics" under shopping section for details of the offer: electronics

 


 

09/06/2021: OfficeDepot / OfficeMax - Free Non Rechargeable AA/AAA batteries after rewards (expires 09/11/2021)

Look in "electronics" under shopping section for details of the offer: electronics

 


 

 09/06/2021: 2.6Gbps Netgear router for $35 - at Walmart - OOS

Link below: very good price. It has 800Mbps speed on 2.4Ghz and 1.9Mbps speed on 5GHz band. It has 4 1Gbps Ethernet ports. Can't find any router with these specs for $35. Regular price for this is $100. Already out of stock by the time I checked out.

https://slickdeals.net/f/15265885-netgear-nighthawk-refurbished-r7450-ac2600-smart-wifi-router-walmart-com-walmart-com-34-20

 


 

09/05/2021: Walgreens Offer - Multiple items for free (after Walgreens cash) at Walgreens for week of 09/05/21 to 09/11/21 (expires 09/11/2021):

You have multiple deals for this week. Some people also have an extra coupon in their account for $5 WGC for spending $20+, or $4 WGC for spending $25+. I'm listing items that will add up to $25 before manufacturer coupons. It has been confirmed that total before Manufacturer coupon count toward the total for reward purpose.

The links below are for each deal separately. Choose the ones you like.

1. Colgate for free: 2 for $4 + $4 WGC

https://slickdeals.net/f/15261520-walgreens-pick-up-live-sunday-9-5-buy-two-select-colgate-toothpastes-for-3-98-after-4-digital-get-back-4-in-wags-cash

2. Crest products for making $1: 3 dental products for #4 + $5 WGC

https://slickdeals.net/f/15262981-walgreens-pickup-select-crest-dental-care-products-5-walgreens-cash-3-for-4-free-store-pickup

3. 12 count schick razors for $2:

https://slickdeals.net/f/15263254-12-count-schick-xtreme-2-men-s-sensitive-disposable-razors-1-99-more-free-store-pickup-at-walgreens

4. Eye relief: 2 for $1.15

https://slickdeals.net/f/15249052-walgreens-4-oz-bausch-lomb-advanced-eye-relief-eye-wash-2-for-1-15-free-store-pickup

5.  Quart sized or Gallon sized bags for $1 each. You get 50 quart sized or 20 gallon sized. These usually go on sale every month for this price. Add this item if Walgreens is out of stock of other items above.

https://slickdeals.net/f/15262984-walgreens-pick-up-select-complete-home-sandwich-storage-or-freezer-bags-buy-1-get-2-free-93cents-each-wyb-3-starts-sun-9-5?src=frontpage

 

Total for all these will be $27 (excluding item #5 above) before Man Coupons.  $16 in Man Coupon, will take total to ~$11. total WGC cash will be around $9.

If you buy first 4 items above in a single order, you may use the coupon for $5 rewards on $20+ purchase (or $4 WGC on $25+). This coupon is available for almost all accounts, you just need to clip it, in order to apply to this order. Net cost will be about $2 Money maker with the $4 WGC coupon, not bad !!

 


 

09/05/2021: Subway Offer - BOGO (expires 11/05/2021): PROMO: FREESUB

https://slickdeals.net/f/15262693-subway-restaurant-buy-one-footlong-sub-get-one-footlong-sub

This offer is back, right after the previous one expired. It's same as what was offered last few times, and just like previous offers, runs for more than a month. It's buy one, get one free = effectively 2 subway for price of one. Can't beat the price. Need to order online or from app.

 


 

08/29/2021: Krispy Kreme Offer: 2 Free Doughnut per vaccination card for COVID - 08/30/21 (Monday) to 09/05/21 (Sunday)

https://slickdeals.net/f/15241345-new-krispy-kreme-covid-19-vaccine-offer-one-week-only-two-free-donuts-8-30-9-5

Every day of the week, you can get 2 free doughnuts by showing your Covid-19 vaccination card. Pretty easy.

 


 

08/27/2021: Amazon Warehouse Deals - Extra 20% on selected items (expiry unknown):

https://slickdeals.net/f/15244558-20-off-amazon-warehouse-deals?src=frontpage

"20% off on used items" is back. It's coming more frequently than it used to. However, amazon warehouse are not discounted that heavily to start with. So, 20%

direct link: On clicking link below, you should see category as "Amazon Warehouse Deals". That shows all items for extra 20%. Now if you search for any item in this category, it will show only those items with extra 20% off.

https://www.amazon.com/s?i=warehouse-deals

Few good deals:

 


 

08/20/2021: Microcenter - Free 240 GB SSD drive, USB stick or MicroSD card (expiry unknown )

Look in "electronics" under shopping section for details of the offer: electronics

 


 

08/20/2021: Free entry to selected Museuums on Museum Day - September 18, 2021 (saturday) only

https://slickdeals.net/f/15228532-free-museum-day-on-september-18-2021-up-to-2-people-reserve-your-tickets-today?src=frontpage

You have to print the ticket. 1 ticket per email address, which is good for 2 people. If you need more, you need to use other fake email addresses. Valid for Sept 18 only. Tickets to high demand museums get sold out pretty quick, so print your tickets first and think later.

 


 

08/18/2021: Walgreens 6 customized set of 5x7 Free photo - Code FREEHELLO => will expire soon.

Look in "photo" under shopping section for details of the offer: photo

 


 

08/15/2021: OfficeDepot / OfficeMax - Free Non Rechargeable AA/AAA batteries + select school supplies after rewards (expires 08/21/2021):=> OK offer

Look in "electronics" under shopping section for details of the offer: electronics

 


 

08/15/2021: Walgreens 8x10 Free photo - Code BIGGER8X10

Look in "photo" under shopping section for details of the offer: photo

 


 

08/06/2021: Exxon Mobil Oil Rebate: $5 to $15 per 5 quart oil, Limit 2 per household. Available at walmart for various prices => Runs from 6 months from 04/01/2021 to 09/30/2021

Look in "gasoline/oil deals" under Auto section for details of the offer: gasoline/oil deals

 


 

08/01/2021: OfficeDepot / OfficeMax - Free Non Rechargeable AA/AAA batteries after rewards (expires 08/07/2021):=> OK offer

Look in "electronics" under shopping section for details of the offer: electronics

 


 

08/01/2021: Amazon Warehouse Deals - Extra 20% on selected items (expiry unknown):

https://slickdeals.net/f/15194164-amazon-warehouse-20-discount-off-select-items

direct link: On clicking link below, you should see category as "Amazon Warehouse Deals". That shows all items for extra 20%. Now if you search for any item in this category, it will show only those items with extra 20% off.

https://www.amazon.com/s?i=warehouse-deals

I don't usually put link to generic sale, but this one deserves it's own thread. You can usually buy "like new" or "used good" items for about half off on Amazon warehouse. With extra 20% off select items, you can get even better deal. Few ex:

 


 

07/27/2021: Mochi Offer - Free box of bubbies mochi ice cream (expiry unknown):

https://slickdeals.net/f/15180019-free-box-of-bubbies-mochi-after-rebate-first-1000-us-only

rebate link:

https://bubbiesicecream.com/rebate

Free Box of Bubblies Mochi icecream. It's available at HEB grocery store, Whole Foods in Texas. It should be available at a lot of local grocery stores. People are successfully getting their mail in rebate amount credited. Requires paypal info. Doesn't look like their is limit of 1st 1000 buyers. Get it while you can !!

 


 

07/25/2021: Walgreens 8x10 Free photo - Code JULY8X10

Look in "photo" under shopping section for details of the offer: photo

 


 

07/25/2021: Walgreens Offer - Get 2 colgate toothpaste, crest toothpaste, mouthwash, toothbrush for free after walgreens rewards (expires 07/31/2021):

https://slickdeals.net/f/15182950-walgreens-store-pick-up-two-colgate-select-tp-s-pay-4-after-digtials-get-4-wags-cash-also-two-select-16-9-oz-colgate-mouthwash-pay-4-ac-get-4-wags-cash

Again, free toothaste, mouthwash and toothbrush (after wags rewards). Can roll in rewards too.

 


 

07/022/2021: Taco Bell Offer: Free Taco - Valid 22nd July, 2021 only

https://www.doctorofcredit.com/taco-bell-free-doritos-los-tacos-when-a-team-wins-after-trailing-at-halftime-in-nba-finals/

Direct link: https://www.tacobell.com/nba-comebacks/

Free locos taco offer is back. It says flaming hot, but you can substitute it with anyhting. It was only on app/online for 21st July, but is in store too on 22nd July. As last time, you can just walk in and get your free taco, or order online or via app.


 

07/18/2021: OfficeDepot / OfficeMax - Free Non Rechargeable AA/AAA batteries after rewards (expires 07/24/2021):

Look in "electronics" under shopping section for details of the offer: electronics

 


 

07/14/2021: Whole Foods - Free Mochi Ice cream at Whole Foods via printable coupon (expires 08/31/2021):

https://slickdeals.net/f/15163306-bubbies-mochi-ice-cream-via-printable-coupon-free-redeem-at-whole-foods-market?src=frontpage

Just answer simple simple questions, provide fake email, phone number and done !!

 


 

07/12/2021: OfficeDepot / OfficeMax - Free Non Rechargeable AA/AAA batteries after rewards (expires 07/17/2021):

Look in "electronics" under shopping section for details of the offer: electronics

 


 

EXPIRED: 07/12/2021: Subway Offer - BOGO (expires 09/03/2021): PROMO: FREEFOOTLONG

https://slickdeals.net/f/15158998-subway-buy-1-footlong-get-1-free?src=frontpage

This offer is back, same as what was offered last few times, and just like previous offers, runs for more than a month. It's buy one, get one free = effectively 2 subway for price of one. Can't beat the price. See below for details. Need to order online or from app.

 


 

EXPIRED: 07/04/2021: Walgreens Offer - Multiple items for free (after Walgreens cash) at Walgreens for week of 07/04/21 to 07/10/21 (expires 07/10/2021):

You have multiple deals for this week: The link below combines all the deals to get to $20 in total so that you can get $5 extra in Walgreens Cash. Even if you don't have $5 on $20+ coupon in your account, it's still a good deal for getting 7 items for $5 or so.

https://slickdeals.net/f/15142411-select-mywalgreens-members-4x-colgate-toothpaste-2x-blue-diamond-almonds-1x-soap-10-05-11-20-walgreens-cash-w-free-store-pickup?src=frontpage

If you buy all 7 items above in a single order, you may use the coupon for $5 rewards on $20+ purchase. This coupon is available for almost all accounts, you just need to clip it, in order to apply to this order. Net cost will be about $0 for all the items if you include $10 walgreens cash reward.

NOTE: Even though the total is below $20 after coupons, the $5 reward is still triggered, based on the comments by SUCHaDEAL.

 


 

07/04/2021: Chipotle Offer: BOGO on 07/06/21 only for in store order from 3PM to close. - expires 07/06/21

https://slickdeals.net/f/15141373-chipotle-restaurants-buy-one-entree-get-one-free-bogo-free-valid-tuesday-july-6-from-3pm-to-close?src=frontpage

In store only. Chipotle BOGO offers are rare, so putting up here. Just say "Friends BOGO" to the cashier to redeem the offer. Use Chipotle GC to pay, which you can usually accumulate at 20% off.

 


 

07/01/2021: BestBuy - Non Rechargeable 36 pack AA/AAA batteries for $6 (expires 07/01/2021 => valid only for 1 day):

Look in "electronics" under shopping section for details of the offer: electronics

 


 

06/30/2021: Walgreens Offer - Multiple deals at Walgreens for week of 06/27/21 to 07/03/21 (expires 07/03/2021):

You have multiple deals for this week:

1. Ladies Pads for $1 after $5 coupon.

https://slickdeals.net/f/15128293-26-count-poise-active-collection-incontinence-liners-w-wings-0-99-free-store-pickup-at-walgreens

2. BIC Flex5 razor for $1 after $5 rebate

https://slickdeals.net/f/15131875-bic-men-s-flex-5-hybrid-disposable-razor-handle-w-3-cartridges-2-for-0-34-0-17-each-after-5-rebate-free-pickup-at-walgreens-more

3. Three Pringles for $2.70 => Use code SUMMER10 to knock 10% off

https://slickdeals.net/f/15129919-pringles-chips-canisters-4-5-6oz-three-for-2-70-after-digital-and-promo-code-90c-ea-great-price-free-walgreens-store-pick-up

4. Three dozen cans of Coke/Pepsi for $9 => Use code SUMMER10 to knock 10% off

5. Tide detergent for $3 after $2 coupon => this coupon regularly available on walgreens

If you buy all 5 items above in a single order, you may use the coupon for $5 rewards on $20+ purchase. This coupon is available for almost all accounts, you just need to clip it, in order to apply to this order. Net cost will be about $10 for all the items if you include $5 reward + $5 MIR.

 


 

06/20/2021: ebay Offer - Used Cordless trimmer/Edger + blower for $42  (expiry unkown):

https://www.ebay.com/itm/353260279682

This is the cheapest cordless trimmer/edger you could find anywhere. A blower along with one battery+charger is included as well. The original price is $60, but there is extra 30% off for this merchant, which is applied at checkout. That brings the price down to $42. There was 10% cashback ongoing on topcashback.com, but as of 06/24, it's down to 1.5% (for purchases on ebay in home/garden category). New units sell on homedepot for $120 or more. It's used, but description says it's almost new. Will find out soon.

UPDATE 07/04/21: The cordless trimmer/edger and blower works well so far. Will need to wait for a year or more to see if the battery still holds up.

 


 

06/20/2021: CVS app Offer - Get free weekly gift on CVS app  (expires 07/31/2021):

https://www.doctorofcredit.com/cvs-extracare-app-free-weekly-gift-6-20-7-31/

You get free weekly item. For the week of 06/20, it's nail clipper. Here's the list of free item for every week:

https://slickdeals.net/f/15106156-cvs-extracare-members-gold-emblem-bagged-candy-free-valid-through-july-3

With 6 weeks in the offer, you get around 6 free items. Most of these items are worth about $1 each, so you are looking at max of $6 in free stuff. Personally I wouldn't do it, since it's like getting $6 for downloading the CVS app, and going to CVS every week. You can get $5 for downloading any app any day. Worth it only if you were already planning to go to CVS or have CVS within walking distance. Else gas will cost you more than these freebies - not a deal cry

 


 

EXPIRED: 06/20/2021: Walgreens Offer - Get 2 colgate toothpaste for free after walgreens rewards (expires 06/26/2021):

https://slickdeals.net/f/15104125-walgreens-store-pick-up-6-20-to-6-26-select-colgate-toothpaste-buy-two-for-3-after-digital-coupon-get-back-3-in-wags-cash-net-free

You have $3 coupon, bringing the price to $3. With this coupon, you get 2 toothpaste for $3 and then $3 rewards, making it kind of free.

 


 

EXPIRED: 06/16/2021: HEB Gift Card Offer (in Texas stores only) - Buy Lowes $100 GC, Home Depot $100 GC or Academy $100 GC, get $15 HEB GC free (expires 06/22/2021):

Look in gift card section for details of the offer: gift cards

 


 

EXPIRED: 06/13/2021: Monifi $250 Checking Bonus offer => expires 06/30/2021

Look in bank account bonus section for details of the offer: best bank bonus

UPDATE: 06/20/2021: Multiple users reporting getting email for $100 now instead of $250.

 


 

EXPIRED: 06/06/2021: Walgreens Offer - Get BIC razor for $1 after coupon (expires 12th June, 2021 - will run out of stock fast !!):

https://slickdeals.net/f/15074926-bic-disposable-razors-packs-various-1-w-store-pickup

Any of the razors is a good choice here. One with 4 or 5 extra razors is a really good deal, as each razor costs 20 cents or so. My deal for razors is usually around 10 to 20 cents. There are no rewards involved, so that's even better.

 


 

06/06/2021: Hancock Whitney Bank $300 Checking Bonus offer (only valid in selected states). => expires 06/30/2021

Look in bank account bonus section for details of the offer: best bank bonus

 


 

EXPIRED: 06/02/2021: HEB Gift Card Offer (in Texas stores only) - Buy Lowes $100 GC or Home Depot $100 GC, get $20 HEB GC free (expires 8th May, 2021):

Look in gift card section for details of the offer: gift cards

 


 

EXPIRED: 05/31/2021: Walgreens Offer - Get two 8oz bags of Cashews for $2 (expiry unknown - will run out of stock fast !!):

https://slickdeals.net/f/15062599-walgreens-8oz-cashew-halves-pieces-two-for-1-88-buy-one-get-one-free-with-in-store-pick-up-ymmv

Walgreens is killing the competition out there with their insane deals every week. This deal has no competition. You get about 450g of cashews (halves and pieces and not the whole cashews) for $1.88, implying a price of $4.2/kg. It's the cheapest you can get cashews anywhere in the world => whole cashew prices are currently $10/kg. cheapest variety of cashews are stll going to cost atleast $68/kg buying diretly from wholesale market. So, you are getting at least 50% off. These have a sell by date of June/July 2022, so hey are good for a year. Check the "sell by date" before you pick up your order. Don't order too many, as your order will get cancelled (as walgreens doesn't carry too many of any item). BTW, cashews pieces taste same as whole cashews, To be sure, I just tried both of them !!

 


 

05/31/2021: Comerica Bank $200 and $500 offer (only valid in TX and MI). => expiry unknown

Look in bank account bonus section for details of the offer: best bank bonus

 


 

EXPIRED: 05/09/2021: Walgreens Gift Card Offer - Buy Kohls 50 GC or Burlington $50 GC, get $10 Walgreens GC free (expires 15th May, 2021 - will run out of stock fast !!):

Look in gift card section for details of the offer: gift cards

 


 

EXPIRED: 05/09/2021: Walgreens Offer - Get two 6 oz Colgate toothpaste + three dozen Coke cans + 2 Stayfree Pads for $18 + get $9 in rewards (expires 15th May, 2021 - will run out of stock fast !!):

https://slickdeals.net/f/15017146-walgreens-offer-2-count-colgate-toothpaste-2-count-of-carfree-pads-pantiliner-box-3-count-of-1-dozen-coke-cans-for-18-9-in-rewards

There are multiple offers at walgreens in this week's ad. Above is one possibility. You get everything above for around $9, coke cans by themselves are worth arund $9.

 


 

EXPIRED: 05/05/2021: Chipotle Offer: BOGO with quiz, online or mobile orders only - expires unknown

https://slickdeals.net/f/14994862-chipotle-burrito-bowl-salad-or-tacos-bogo-free-w-quiz-online-mobile-orders-only

chipotole doesn't have BOGO offers very often, so whenever there's one, just get it. They are giving out only 50K codes per day. The distribution of these free codes start at 11am CST. Usually they go out in 30 minutes or so, so be ready each day at 11am sharp to grab your codes. Answers for quiz questions are in link above.

 


 

EXPIRED: 05/04/2021: Taco Bell Offer: Free Taco - Valid 4th May, 2021 only

https://www.doctorofcredit.com/taco-bell-free-crunchy-taco/

Free crunchy taco offer is back (this time it's taco not nacho). It says beef taco, but you can substitute it with beans to make it vegetarian. At least the online site allows to do it. As always, you can just walk in and get your free taco, or order online or via app.

 


 

EXPIRED: 05/01/2021: UMB checking account $300 offer (only valid in select states). => expires May 22, 2021

Look in bank account bonus section for details of the offer: best bank bonus

 


 

EXPIRED: 04/26/2021: Walgreens Offer - Get 5.7 oz Crest toothpaste for 50 cents (expiry unknown - will run out of stock fast !!):

https://slickdeals.net/f/14992504-crest-toothpaste-5-7oz-various-0-49-free-store-pickup

There's a coupon for $2, bringing the price to 50 cents. Limit 1 though. If you have offer for $5 in walgreens rewards for spending $20+, use this with almonds offer (see below) + cashew's BOGO offer.

 


 

EXPIRED: 04/26/2021: Walgreens Offer - Get 2 colgate toothpaste for free after walgreens rewards (expiry unknown - will run out of stock fast !!):

https://slickdeals.net/f/14978858-walgreens-w-in-store-pick-up-two-tubes-select-colgate-total-toothpastes-4-99-after-digital-q-get-five-dollars-wags-cash-back

You have $3 coupon, bringing the price to $5. With this coupon, you get 2 toothpaste for $5 and then $5 rewards, making it kind of free. Don't place online order as Walgreens allows individual stores to cancel online orders based on limits set by manager of that store. So, most of the orders modify your order or cancel your order. Best to go in store and pick these up, as price is valid in store too. If you have an email for $5 rewards on spending $20+, you can combine toothpaste purchase with Almonds purchase below, and get everything for free.

 


 

04/26/2021: Walgreens Offer - Buy 36 ounes of Almond for $4 (expiry unknown - will run out of stock fast !!):

https://slickdeals.net/f/14978882-blueLowes-diamond-almonds-six-six-ounce-cans-for-13-77-with-free-store-pick-up-walgreens-then-get-10-rebate-net-3-77-for-six-cans

With this offer, you get 36 ounces of Almonds for about $4, after applying for $10 rebate, and using BOGO offer on walgreens website. Maximum rebate allowed per consumer is  $50, so with people in same household you can do a maximum of $100 in rebate. Costco sells 3 lb bag of Kirkland almonds for $12 or $4/pound. Here you get 36 oz for $4, coming out to $2/lb. This is the cheapest you can get almonds for. Don't place online order as Walgreens allows individual stores to cancel online orders based on limits set by manager of that store. So, most of the orders modify your order or cancel your order. Best to go in store and pick these up, as price is valid in store too.

UPDATE 04/28/2021: Just went to pick these in store, and prices are $.99 instead of $4.59. So, place the order online to save $2.40 for 6 boxes.

UPDATE: 05/01/2021: offer still valid, however stores cancelling or modifying orders by limiting you to 2 or 4 of each type of almonds

 


 

EXPIRED: 04/21/2021: Lowes Offer - Buy $200 in Visa GC, get $15 Lowes GC (expires 04/28/2021):

https://www.doctorofcredit.com/lowes-buy-200-visa-giftcard-get-15-lowes-egiftcard-bonus-4-22-4-28/

Similar offer has been offered in the past, but this time it's lucrative, because you can use chase Freedom credit card to get 5% cashback. Chase credit cards have 5% cashback on their freedom cardit cards for "home store" purchases.  You can get as many of these as you want, however bonus is limited to 2 per email account. So, effectively for $206 ($200 GC + $6 activation fee), you get $20 in chase points + $15 Lowes eGC, which nets you at least 10% cashback, depending on how much cash redemption value you assign to Lowes GC. NOTE: To get $15 Lowes eGC, you have to go to another website to reddem the offer, after making the purchase in store. Check the link for details.

 


 

EXPIRED: 04/16/2021: Krispy Kreme Offer: Free Doughnut - multiple expiry dates

https://www.doctorofcredit.com/krispy-kreme-free-coffee-doughnut-for-anyone-on-mondays-from-3-29-thru-5-24/

There are 3 offer here:

  • Free coffee and Doughnut -  mondays only - expiry 05/24/2021
  • Free doughnut everyday with proof of covid vaccination - valid every day in 2021 - expiry 12/31/2021
  • Buy 1 dozen doughnuts at full pricem and get another one dozen for $1 - this is a more common offer that's offered multiple times a year. expiry 05/23/2021

Really nice offer to get free doughnuts.

 


 

EXPIRED: 04/14/2021: Subway Offer - BOGO (expires 06/11/2021): PROMO: FREESUB

https://slickdeals.net/f/14956013-subway-bogo-free-footlong

This offer is back, same as what was offered last few times. It cam right on the day the last offer was supposed to expire. It's buy one, get one free = effectively 2 subway for price of one. Can't beat the price. See below for details. Need to order online or from app. There's another offer on subway website, don't use that, as it's only 50% off of second sub (i.e it's not 100% off as in this deal).

 


 

EXPIRED: 04/01/2021: BBVA checking+savings account $250 offer (only valid in select states) => expires Apr 30, 2021:

Look in bank account bonus section for details of the offer: best bank bonus

 


 

EXPIRED: 04/01/2021: Scotts Fertilizer Offer at Sam's club - (expires on 04/22/2021):

https://slickdeals.net/f/14961110-scott-s-turf-builder-weed-feed-sams-club-40lbs-34-98-covering-14k-sq-ft

This sam's club offer beats all the other offers out there for scott's weed and feed fertilizer. It's 40lbs bag is priced at $35, while the cheapest you can get a 42b bag with all the rebates, coupons, cashback etc is about $38 per bag at Ace hardware. So, this iffer at Sam's is much better, you just need to have a membership at Sam's. There are always multiple offers for Sam's, wher you can a yearly membehsip at Sam's for free (i.e Amex/Discover offers that pay you back whatever you pay in membership fees, groupon offers, etc). Also, you can use walmart GC here, so good time to liquidate those.

 


 

04/01/2021: Scotts Fertilizer Offer - (expires at different times from 04/2021 to 08/2021):

https://slickdeals.net/f/14936450-scotts-4-step-5000-sq-ft-lawn-seeding-program-14-35-lb-grubex-granules-43-after-rebate-2-5-slickdeals-cashback-pc-req-d-at-ace-free-curbside-pickup

If you are a home owner with a yard, you know maintaining yards is financially draining. Scott's fertilizers are pretty effective in killing weeds and nourishing your grass, however they are expensive and don't go on sale that often. Ace hardware stores have Scott's fertilizer on sale this month, and with scott's rebate program, you can easily get 20% discount over the sale price. I confirmed with a rep via chat that "Ace hardware" stores are indeed eligible for rebate as they are locally owned stores. These are some of the rebate offers. Don't pay attention to the slickdeals link above, as it doesn't list best possible combo for rebate purposes. There are various lucrative combo possible:

Rebates are all online, so if they come through, it's pretty simple to get the rebate. Rebate forms are not very clear in what's included and what's the rebate per item. Reps were also not able to tell me exactly what quantity of itms need to be bought for rebate, etc. So, it's going to be hit or miss. I've gotten as much info as I could talking to a rep on 1-888-770-9020.

https://www.scottsmiraclegrorebates.com

  • 4 bags of scott's fertilizer: Get 4 weed and feed bags (15,000 sq ft, largest bags) for about $200 (with $25 online coupon and $24 discount for ace rewards members) and then get $10 rebate on each resulting in net cost of $40/bag (Lowes/HomeDepot sell it for $60/bag). You can mix and match bag shown in pictures, but can't exceed 4 bags.
  • Annual 4 step program: 4 bags of fertilizers (15,000 sq ft, largest bags) for about $170 and then get $50 rebate on them resulting in net cost of $120 for 4 bags. (Lowest you can get them on amazon is for $170 for 4 bags). This may not be the cheapest price as some of the bags in this promo go on sale for $30sh each.
  • Round up: Offer says save up to $10, but doesn't say how many you need to buy and what products. From the pictures, looks like Roundup "grass and weed killer concentrate" is included. I bought 2 for $40, and with hopefully it's at least $5 rebate per item.
  • Ortho insect control: Offer says up to $8, but doesn't say how many you need to buy and what products. From the pictures, looks like ortho "fire ant killer" is included, so got 2 for $28. Hopefully it's at least $4 rebate per item.
  • GrubEx: The offer says up to $15, but doesn't say how many you need to buy. It's only 1 kind of product "grubEx", so no confusion there. It's on sale for $36. Hopefully $15 rebate is valid on 2 of them.
  • Misc: All other offers are either repetition of one or more of above offers, or I'm not really sure about the offer (couldn't find consistent info on them)

 


 

EXPIRED: 02/28/2021: Subway Offer - BOGO (expires 04/14/2021): PROMO: FREEFOOTLONG

https://slickdeals.net/f/14863126-subway-restaurant-buy-one-footlong-sub-get-one-footlong-sub-free

This offer is back, same as what was offered last few times. It's byu one, get one free = effectively 2 subway for price of one. Can't beat the price. See below for details. Need to order online or from app.

 


 

EXPIRED: 02/09/2021: US Bank Checking account $400 offer => expires Mar 31, 2021

Look in bank account bonus section for details of the offer: best bank bonus

 


 

 

Thermodynamic: Thermodynamics simply describes the movement of heat. It deals with heat related motion or other effects. Thermodynamics is derived from thermo, meaning heat, and dynamics, (literally “power”), and is used to describe the movement or change of a process due to heat flow. All below material is relevant only for thermal related energy or work.

NOTE: I've included Thermodynamics as part of Chemistry as that is where it's grouped under in most courses, although it could as well be part of Physics, as it invloves Energy, work, etc.

Any object has observable properties as Temperature, Pressure and Volume. These are macroscopic properties observed at object level, but all these objects are made of microscopic components called atoms, which combine to form molecules. Each of these molecules has a distinct state such as position and velocity, which ultimately decides the microstate of each molecule. Microstate of all these molecules combined define the macrostate of the system/object that we observe.

Entropy: It is the measure of how disorganized and random a system is.

Entropy is defined as all possible microstates that the system can occupy. If each state "i" has a probability pi of being occupied, then entrpoy (S) is =>

S = -kb Σ pi log (pi) => Here kb=boltzmann constant = 1.38x10^-23 J/K. So, unit of S is also J/K. Kb provides conversion from Temp to Energy and represents the energy of a particle per unit temperature. So, a particle at 0K has 0 energy but one at 100K has 1.38*10^-21J (multiplying Kb by 100)

If a system has Ω number of possible microstates, and each microstate has equal probability of happening, then S = -kb * Ω * 1/ Ω * log (1/ Ω) => S=  kb*log( Ω). This is true for an isolated system in equilibrium. In thermodynamics, such a system is one in which the volume, number of molecules, and internal energy are fixed.

In other words, entropy measures the disorder or uncertainty about a system, i.e billions of different possible microstates that the system can have, can give rise to uncertainty as to what state the system is in now. If there are 50 molecules of water, and each molecule of water can be in 10 different states, then total number of possible states is 10^50 (since each molecule can be in any of 10 states, and there are 50 molecules, so simple probability says it is 10 multiplied 50 times). So, entropy is kb*log( Ω) = kb*log(10^50).

NOTE that entropy is a measure of a system's thermal energy per unit temperature that is unavailable for doing useful work. Every system has internal thermal energy in it, that keeps atoms vibrating. As we cool things, things change from gas to liquid (less vibration), then to solid (even less vibration), then start getting into more perfect lattice. If we go to very low temperature close to 0K, we will get lattice structure where there is no vibration, and each atom of lattice is exactly the same way as any other atom. There is no variation or disorder in this lattice structure. It behaves like a perfect crystal, one in which the internal lattice structure extends uninterrupted in all directions. Every lattice element of the structure is in its proper place, whether it is a single atom or a molecular grouping.  Possible number of micro states is just 1 which is the ground state (since each atom has only 1 state (no vibration), so irrespective of number of atoms, there can be only one state for system, as all atoms will have that 1 state). In this case entropy = kb * (log 1) = 0. 

So, at absolute zero temperature (0 Kelvin or -273.15C), entropy of a system should ideally be 0 (i.e only single ground state possible for all atoms). However, in reality perfect crystal structure is not achieved even at 0K. There are other micro states besides the ground state. In other words, the system is at lowest internal energy state (least vibration), but not 0. There is still vibrational motion in particles, which cannot be removed. Perfect crystals never occur in practice; imperfections, and even entire amorphous material inclusions, can and do get "frozen in" at low temperatures, so transitions to more stable states do not occur (even though there may be multiple micro states, but we may just see 1 micro state). Correct form of 3rd law of thermodynamics (mentioned below) is that entropy approaches 0 as temperature goes to 0. So, Entropy at 0K is some finite residual value, but for convenience, we take entropy at 0K to be zero, for reference. 

 

Three Laws of Thermodynamics:

Just like we have Newton's laws for motion, we have 3 separate laws for thermodynamics (as no other laws explain thermal observations. Newton's laws are limited to mechanics). There is also a “Zeroth”L aw that states, in a rather complicated way, that no heat will flow between two objects that are at the same temperature. This seems so obvious that this law is generally ignored, in common practice.

First Law- Energy cannot be created or destroyed, but can change form, and location. For instance, burning wood changes the internal energy in the wood into heat and light energy.

Second Law- The Second Law is the most understandable and useful in real world applications, and makes heating, air conditioning, and refrigeration possible. It is expressed in many different forms, but they all amount to the same thing. Easiest and most common defn is that energy must flow from a higher state to a lower state. That is, heat must always flow from the warmer object to a cooler object and not from the cooler object to the warmer object, unless energy in some form is supplied to reverse the direction of heat flow. Another definition is: "Not all heat energy can be converted into work in a cyclic process, i.e Work can create heat, but not all heat can be converted back to work.

The second law basically is about Entropy and may be formulated by the observation that the entropy of isolated systems left to spontaneous evolution cannot decrease, as they always arrive at a state of Thermodynamic Equilibrium where the entropy is highest at the given internal energy. An increase in the combined entropy of system and surroundings accounts for the irreversibility of natural processes, often referred to in the concept of the arrow of time. 2nd Law of Thermodynamics is also sometimes called as "Law of Entropy", which states that Entropy in Universe is always increasing.

The Second Law holds in our everyday visible world, but on the subatomic level the law is constantly violated, but statistically the law holds true.


Third Law- As a system approaches Absolute Zero, the entropy of the system approaches a minimum value. Absolute Zero cannot be attained in a real system, it is only a theoretical limit. We saw this above.

 

Heat Transfer:

Heat can move in three ways: conduction, convection, and radiation.

Conduction is the easiest and most familiar to anyone who has burned themselves on a stove or a hot pot. It is the direct transfer of heat from one object to another, when they are in contact.

Convection is based on the movement of a fluid to transfer heat from one object or area to another. Weather is a convective process; hot air and warm water move from the tropics toward the poles. Here air or water was used as the medium for transfer.

Radiation is heat transferred directly from a source to an object without using a medium like air or water. Heat radiated from the sun will melt snow on the road, even on a cold day. The radiant energy warms the road surface without directly warming the air.

In the real world, the transfer of heat involves a mixture of all three methods, with the possible exception of outer space.

 

Fermi:

This defn not correct => The Fermi level for electrons of a body is the thermodynamic work required to add one electron to the body. It's the same amount of work to remove one electron from the body. It is a thermodynamic quantity usually denoted by µ or Ef. It's unit is Joules, as it is energy level, not potential level.

 We saw above that each electron in a crystal lattice is in an energy band. However there is a probability distribution that says how many of these electrons will be in which energy level at a given temperature.

The Fermi–Dirac distribution, f ( ϵ ), gives the probability that (at thermodynamic equilibrium) a state having energy ϵ is occupied by an electron:

    f ( ϵ ) = 1 / [e^{(ϵ − μ)/kT} + 1]

Fermi level can be considered to be a hypothetical energy level of an electron, such that at thermodynamic equilibrium this energy level would have a 50% probability of being occupied at any given time. At 0K, since all thermodynamic motion ceases, we would expect that electrons would be frozen, i.e at lowest energy level E0. From above eqn we see that at 0K, all Energy levels below Ef have 100% prob of being occupied, while those above Ef have 0% prob. As is expected at 0K, all these energy states are occupied with 100% certainty, implying only 1 micro state possible (i.e lower N energy states occupied, while upper energy states not occupied. No other combination of energy states possible).

The Fermi level is any energy level having the probability that it is exactly half filled with electrons. Levels of lower energy than the Fermi level tend to be entirely filled with electrons, whereas energy levels higher than the Fermi tend to be empty. Enrgy bands above Ef are called conduction band, while those below Ef are called valence band.

For conducting metals, both conduction and valence band are on each side of Ef right next to it, meaning just little bit of extra energy is needed for these electrons to conduct. Even with no extra energy applied, a lot of thermally active electrons are in conduction band. This causes the electrons to move freely resulting in high conductivity. For insulators, these conduction and valence are further separated out from each other, with Ef in b/w. This means a lot of extra energy is needed for these electrons to conduct. There is a band gap b/w cond and val band, of the order of 10ev. Almost no electrons are in conduction band, resulting in no conductivity. Semiconductors also have these bandgap, are lot smaller bandgap of 1ev. So,  conduction band is very lightly populated with thermally active electrons resulting in low conductivity. Apart from thermal agitation, providing light energy is the other way to move electrons from valence band to conduction band.

NOTE: Fermi level moves around with external voltage applied, so Fermi level is defined with 0 external voltage. Fermi level moves up by "X eV", when "X Volts" applied to the material. So, alternatively, when we say that a conductor is at "X Volts", all electrons have gained an additional "X eV" of energy, so all of the energy band has shifted up by "X eV", so Fermi level has also moved up by "X eV".  So, Fermi level can be known by just dividing voltage of material by "e", if we assign fermi level of 0, for electrical ground (i.e 0 external voltage).  

 

Work function (W)

As we move higher up in energy band (in conduction band), electrons become more free to move around, but still within the solid material. If we go much higher than conduction band region, then electron may finally beak free from the surface of solid. We call this energy level Work function. It's defined as minimum thermodynamic work (or energy) needed to remove an electron from a solid to a point in the vacuum immediately outside the solid surface. Here "immediately" means that the final electron position is far from the surface on the atomic scale, but still too close to the solid to be influenced by ambient electric fields in the vacuum. The work function is not a characteristic of a bulk material, but rather a property of the surface of the material (depending on crystal face and contamination). Work function of most of the metals is around 4eV. Silicon W=4.7eV

W = -eø - Ef (e=charge of electron, ø = electrostatic potential in the vacuum nearby the surface, so -eø represents the energy of electron near the surface)

If we charged a material to V volts, then V=-Ef/e. Rearranging above eqn, ø = -Ef/e - W/e = V - W/e. So, potential near surface of any material in vacuum is less than the potential applied by an amount equal to Work function potential (work function divided by e). This means that if 2 conductors are kept at same potential by shorting to each other, but if their work function are different, then their surface potential will be different. So, there will be an electric field in vacuum going from surface of 1 metal to other metal. This is used to get electrons flowing in vacuum tube filaments or in electron guns.

Work function is very important in solid state physics, as work function of different material control how electrons flow when different materials are put in contact.

It is also important in photo electric emission, where it determines the minimum photon energy required to liberate an electron from a substance. Energy beyond fermi level gets the electron right on the surface of material ready to escape. So, light of frequecy f has energy=hf, which when exceeds workfunction of material will liberate an electron from it.

 

Physics:

In this section, we'll deal with physics.

Feymann Lectures: There is very good lecture series by Nobel Prize winner, Feymann, that describes fundamental Physics in layman's terms.

http://www.feynmanlectures.caltech.edu/

Libretexts.org: is another very good website for learning science related topics including physics. Link => https://phys.libretexts.org

Goto Bookshelves and then choose appropriate Phics level (i.e college level, university level, etc). Below are the sections in the link shown => https://phys.libretexts.org/Bookshelves?readerView

Physics sections include:

  • solid state physics
  • mechanics
  • thermodynamics
  • Electricity and Magnetism

- ...

---------------
Cortex M0-plus (CM0+):
---------------
Here, we use only minimal required C code files from ARM.
steps:
1. make: make 32 bit bin file from c code: only these files needed:
   *.c: test1.c, main.c, boot.c, IRQService.c, export.s
   *.h: address_def.h, defines.h
   *.txt: scatter.txt
2. In irun, load this bin file in rom memory, and start sim

make:
---
make -f /db/.../Makefile all

Makefile:
-------
CCFLAGS = --cpu=Cortex-M0 -c --asm --interleave --apcs=interwork -Otime -D RAM_ABSOLUTE_BASE_ADDR -D main=__main -g
LDFLAGS = --cpu=Cortex-M0 --map --no_debug --datacompressor=off --map --symbols --info=inline
IKDEPS = /sim/.../Makefile

all: clear test1_32.dat clean

############ rm files at start
clear:
      rm -rf *.o *.sym *.list *.bin *.elf *.sec *.dis *.map *.ihex *.obj *.log *.inc *.dat

###########start compilation .dat<=.ihex<=.elf<=.o<=.c
test1_32.dat : test1.ihex
        @echo " *** building $@ ***" => building test1_32.dat
        ihex2dat32 -input $< -output $@ => o/p in 32 bit mem mage file

test1.ihex : test1.elf
        fromelf --i32 $< --output $@

test1.elf : boot.o IRQService.o init.o export.o test1.o
        armlink -o $@  boot.o IRQService.o init.o export.o test1.o $(LDFLAGS) --scatter scatter.txt

test1.o: test1.c $(IKDEPS)
       armcc $(CCFLAGS) -c -o $@ $<

#get .o files for boot.c, IRQService.c, init.c, export.s
boot.o: boot.c $(IKDEPS) => similarly for IRQService.c, init.c
      armcc $(CCFLAGS) -c -o $@ $<
IRQService.o: ...
init.o: ....
export.o: export.s $(IKDEPS) => export.c isn't there, use export.s
      armasm --cpu=Cortex-M0 --keep -o $@ $<


##### remove files at end
clean:
        rm -rf *.obj

------------------------
output of running this:
#clean
rm -rf *.o *.sym *.list *.bin *.elf *.sec *.dis *.map *.ihex *.obj *.log *.inc *.dat

#compile files
armcc --cpu=Cortex-M0 -c --asm --interleave --apcs=interwork -Otime  -D RAM_ABSOLUTE_BASE_ADDR -D main=__main -g -c -o boot.o /sim/.../boot.c
armcc ... IRQService.c
armcc ... init.c
armasm --cpu=Cortex-M0 --keep -o export.o /sim/.../export.s
armcc ... test1.c

armlink -o test1.elf boot.o IRQService.o export.o init.o basic.o --cpu=Cortex-M0 --map --no_debug --datacompressor=off --map --symbols --info=inline --scatter /sim/.../scatter.txt => Here armlink is using --scatter which causes it to use scatter.txt for ro-base, rw-base, zi-base. For sporsho, we used --ro-base and --rw-base on armlink cmdline instead of using scatter file.  

#show inline results => symbol table, memory map,
Image Symbol Table ....
Memory Map of the image ....

#generate .elf and .dat
fromelf --i32 test1.elf --output test1.ihex
ihex2dat32 -input test1.ihex -output test1_32.dat => final *.dat file generated

#clean
rm -rf *.obj

-------------------------------------------
#contents of various files

###### boot.c ######
typedef void (*intr_handler)(void);
extern void IRQService (void); // Default interrupt handler
void BaseIRQService0 (void); //similarly for IRQ0 to IRQ31
intr_handler IRQService0   = IRQService;

//define func for all intr handlers, either as C/asm code or via calling other func.
void Reset_Handler (void) {
        init (); //this calls init func, defined in init.c
}

void BaseIRQService0 (void) { //irq0.
    IRQService0 (); //this ultimately calls IRQService
}

typedef const int * vect_t; //vect_t is a ptr to type "const int"
const int * __Vectors[] __attribute__ ((section("vectors"))) = { //this matches contents of .dat binary file below
        (vect_t) (&USR_STACK),     //addr=0x0000, stores MSP value, here it stores 0x20046F00
        (vect_t) Reset_Handler,    //addr=0x0004
        (vect_t) NMI_Handler,       //addr=0x0008
        (vect_t) HardFault_Handler,//addr=0x000C
        (vect_t) 0xFFFFFFFC,       //addr=0x0010    
        (vect_t) 0xFFFFFFFC,       //addr=0x0014
        (vect_t) 0xFFFFFFFC,       //addr=0x0018
        (vect_t) 0xFFFFFFFC,       //addr=0x001C
        (vect_t) 0xFFFFFFFC,       //addr=0x0020
        (vect_t) 0xFFFFFFFC,       //addr=0x0024
        (vect_t) 0xFFFFFFFC,       //addr=0x0028
        (vect_t) SVC_Handler,       //addr=0x002C, stores addr of SVC intr handler, which in this case is 0x00000115
        (vect_t) 0xFFFFFFFC,       //addr=0x0030
        (vect_t) 0xFFFFFFFC,       //addr=0x0034
        (vect_t) PendSV_Handler,   //addr=0x0038, stores addr of Pend intr handler, which in this case is 0x00000127
        (vect_t) SysTick_Handler,  //addr=0x003C, stores addr of systick intr handler, which in this case is 0x00000139
        (vect_t) BaseIRQService0,  // similarly for IRQ0 to IRQ31, addr=0x0040 to 0x00BC (addr 0x00C0 is the first addr where this vector table ends). stores addr starting from 0x00000141 to 0x000001FB, each IRQ is 6 bytes.
       //(vect_t) IRQService,      //we could directly point to IRQService routine. That's what we used for compiled code below
}

asm code for boot
----------
AREA ||.text||, CODE, READONLY, ALIGN=2 => this is text section

Reset_Handler PROC
000000  b510              PUSH     {r4,lr}
000002  f7fffffe          BL       init => jumps to init, here target addr is not yet finalized, so we see jump inst as f7ff_fffe. Once init addr is know in final linking of *.o files, this BL changes coding to f827_f000 (as seen in *.dat file below) which implies target_msb[10:0]=000, target_lsb[10:0]=027<<1 => pc=pc+(027<<1)=0c6+04e=0x114 (init section starts from 0x114, so it's correct). (LR stored with next PC=06=0xc6, so return from main() comes right here)
000006  bd10              POP      {r4,pc}
ENDP

similarly for other proc handlers
NMI_Handler PROC
000008  4805              LDR      r0,|L1.32| => Load pc+|L1.32| into r0 reg. (4805=>reg=r0,label=05<<2=0x14(dec=20),pc+0x14=0x0a+0x14=0x1e. Note that label=0x05 is resolved here itself, since the label is within this file, so compiler knows how much to add to goto that label.
00000a  6800              LDR      r0,[r0,#0]  ; NMIService, r0=
00000c  4700              BX       r0 => pc=r0=
ENDP

HardFault_Handler PROC
|L1.14|
00000e  bf00              NOP
000010  e7fd              B        |L1.14| => while (1) { __nop (); e7fd => offset=0x7fd=-3, so pc=pc-3=0x012-0x003=0x00e (prev inst)
ENDP

SVC_Handler PROC
|L1.18|
000012  bf00              NOP
000014  e7fd              B        |L1.18| => while (1) { __nop ();
ENDP

PendSV_Handler PROC
|L1.22|
000016  bf00              NOP
000018  e7fd              B        |L1.22|
ENDP

SysTick_Handler PROC
|L1.26|
00001a  bf00              NOP
00001c  e7fd              B        |L1.26|
ENDP

00001e  0000              DCW      0x0000
|L1.32| => NMIService is here
                          DCD      ||.data||
##data section for boot.c starts from here
                          AREA ||.data||, DATA, ALIGN=2 => area named .data
                  NMIService
                          DCD      IRQService
                          AREA ||area_number.5||, DATA, ALIGN=2 => area named .area_number.5
                          EXPORTAS ||area_number.5||, ||.data||
                  IRQService0
                          DCD      IRQService
                         AREA vectors, DATA, ALIGN=2 => area named vectors
                  __Vectors
                          DCD      0x20046f00
                          DCD      Reset_Handler
                          DCD      NMI_Handler
                          DCD      HardFault_Handler
                          DCD      0xfffffffc
                          DCD      0xfffffffc
                          DCD      0xfffffffc
                          DCD      0xfffffffc
                          DCD      0xfffffffc
                          DCD      0xfffffffc
                          DCD      0xfffffffc
                          DCD      SVC_Handler
                          DCD      0xfffffffc
                          DCD      0xfffffffc
                          DCD      PendSV_Handler
                          DCD      SysTick_Handler
                          DCD      IRQService
                ....
                          DCD      IRQService (32 of these)

---------------

######## init.c ###########
void init (void) {
 main(); //this calls "main" func in user code, defined in test1.c
}

asm code for init:
----------
AREA ||.text||, CODE, READONLY, ALIGN=1
init PROC

000000  b510              PUSH     {r4,lr}
000002  f7fffffe          BL       __main => BL is 32 bit inst (LR stored with next PC=06=0x11a, so return from main() comes right here)
000006  bd10              POP      {r4,pc}

ENDP
----------

######## IRQService.c ###########
void IRQService (void) { //default IRQ, doesn't do anything
 (*(volatile uint32 *)(TB_RSVD_ADDR + 0x0F98))++; //FAIL_LOC++
 (*(volatile uint32 *)(TB_RSVD_ADDR + 0x0FEC)) = 0xD0D0D0D0; //DISPLAY(0xD0D0D0D0)
 (*(volatile uint32 *)(TB_RSVD_ADDR + 0x0F90)) = 0xB000B000; //FAIL;   //writes to some reserved mem section to indicate to verilog tb that it's in IRQ
 (*(volatile uint32 *)(TB_RSVD_ADDR + 0x0FAC)) = 0x50; __nop(); (*(volatile uint32 *)(TB_RSVD_ADDR + 0x0FAC)) = 0x11; //EXIT; wrt to BOOTCODE_ADDR
 return; //just returns back
}

asm code:
-------
000000  4807              LDR      r0,|L1.32|
000002  6981              LDR      r1,[r0,#0x18] => FAIL_LOC++;
000004  1c49              ADDS     r1,r1,#1
000006  6181              STR      r1,[r0,#0x18]
000008  4a07              LDR      r2,|L1.40| => DISPLAY(0xD0D0D0D0);
00000a  4906              LDR      r1,|L1.36|
00000c  62d1              STR      r1,[r2,#0x2c]
00000e  4907              LDR      r1,|L1.44| => FAIL
000010  6101              STR      r1,[r0,#0x10]
000012  2150              MOVS     r1,#0x50 => EXIT
000014  62c1              STR      r1,[r0,#0x2c]
000016  bf00              NOP
000018  2111              MOVS     r1,#0x11
00001a  62c1              STR      r1,[r0,#0x2c]
00001c  4770              BX       lr => return
00001e  0000              DCW      0x0000
                  |L1.32|
                          DCD      0x20046f80
                  |L1.36|
                          DCD      0xd0d0d0d0
                  |L1.40|
                          DCD      0x20046fc0
                  |L1.44|
                          DCD      0xb000b000
------

######## test1.c ###########
int main (void) {
  int i=0;
    while(i<1) i=i+1;
    return(0);
}

asm code:
---------
000000  2000              MOVS     r0,#0 => r0=0
|L1.2|
000002  1c40              ADDS     r0,r0,#1 => while(i<1) i=i+1;
000004  2801              CMP      r0,#1
000006  dbfc              BLT      |L1.2|
000008  2000              MOVS     r0,#0 => return(0)
00000a  4770              BX       lr
ENDP
-----------


######## export.s ###########
  IMPORT ||Image$$ROM_EXEC2$$RO$$Limit||  => ROM_EXEC2 region (in scatter.txt below)
  IMPORT ||Image$$RAM_EXEC1$$RW$$Base||   => RAM_EXEC1 region
  IMPORT ||Image$$RAM_EXEC1$$RW$$Length||
  IMPORT ||Image$$RAM_EXEC2$$ZI$$Base||   => RAM_EXEC2 region
  IMPORT ||Image$$RAM_EXEC2$$ZI$$Length||
        END

######## scatter.txt #########
scatter file has 1 or more load region for diff obj *.o files. Each load region has RO and RW/ZI regions. The addr and placement of these regions is specified in

ROM_LOAD 0x0 {
    ROM_EXEC1 0x0 { => start from addr=0x0000
        boot.o (vectors, +First) => boot.c "vectors" sction is put here (RO)
        * (InRoot$$Sections)
    }
    ROM_EXEC2 0xc0 { => addr=0xC0 is where the vector section has ended. We put all other code starting here (RO)
        *.o
    }
    OTP_EXEC3 +0 {
        *.o (.sec_text)
    }
    RAM_EXEC1 0x00043000 { //let's say this has 148 bytes (=0x94 bytes)
      *.o (.data,.RW)
    }
    RAM_EXEC2 +0 { //then starting addr for this is 0x00043094
      *.o (.bss)
    }
}


#contents of .dat (32 bit):
Section 1 => ROM_EXEC1 (192 bytes)
---------
 @00  20046F00 000000C1 000000C9 000000CF => addr 0(msp) loaded with 2004_6f00. Reset=0xC0/NMI=0xC8/HardFault=0xCE
 @10  FFFFFFFC FFFFFFFC FFFFFFFC FFFFFFFC
 @20  FFFFFFFC FFFFFFFC FFFFFFFC 000000D3 => 0xD2=SVC handler
 @30  FFFFFFFC FFFFFFFC 000000D7 000000DB => 0xD6=PendSV, 0xDA=SysTick
 @40  000000E5 000000E5 000000E5 000000E5  => IRQ0-IRQ31 all goto same IRQService
 @50  000000E5 000000E5 000000E5 000000E5
 @60  000000E5 000000E5 000000E5 000000E5
 @70  000000E5 000000E5 000000E5 000000E5
 @80  000000E5 000000E5 000000E5 000000E5
 @90  000000E5 000000E5 000000E5 000000E5
 @a0  000000E5 000000E5 000000E5 000000E5
 @b0  000000E5 000000E5 000000E5 000000E5
--- All vector table ends before here ----

Section 2 => ROM_EXEC2 (104 bytes)
---------
 @c0  => boot.c starts here. reset handler starts, then NMI, HardFault, SVC, PendSV, SysTick  here
----
F000B510 => reset handler (B510 => PUSH {r4,lr})
BD10F827 => F827_F000 => BL init (target addr=000_027=>pc=pc+027=0xc6+(0x27<<1)=0x114, (BD10 => POP {r4,pc})
 @c8 => NMI handler
68004805 BF004700 (BF00 = NOP from HardFault handler)
 @d0 BF00E7FD BF00E7FD BF00E7FD 0000E7FD => HardFault, SVC, PendSV, SysTick (last 0000 is for next inst DCW 0x0000)
 @e0  00043000 => DCD ||.data|| => 0x0004_3000 is addr of RAM region

 @e4 => IRQservice.c starts here
---
69814807 61811C49 49064A07
 @f0  490762D1 21506101 BF0062C1 62C12111
@100  
00004770 => 4770=BX lr, 0000=DCW 0x0000
20046F80 D0D0D0D0 20046FC0 => all DCD
@110  
B000B000 => all DCD

@114 => init.c starts here
---
F000B510 =>
BD10F801 => F801_F000 => BL __main (target addr=000_001 =>PC=PC+1=

@11c => main.c starts here
---
1C402000 =>  main starts from here __main
DBFC2801
47702000 => end of main.c

@128
000000E5 000000E5 => extra bytes, not sure for what

--------------
seq of exec of code above:
1. HCLK starts running. 1 cycle later, HRESET_N gets released.
2. HADDR goes from 0x00->0x04->0xC0,0xC4(reset_handler)->0x114,0x118(init)->0x11c,0x120,0x124(main)->

----------------------------------------
Section 3: RAM_EXEC1
---------
remove below lines ---

4770BF30 => Reset_Handler starts here (B510 => PUSH {r4,lr})
4770B662
4770B672 4770BF00
 @d0  8F5FF3BF F3BF4770 47708F4F 8F6FF3BF
 @e0  00004770
F000B510 => Reset_Handler starts here (B510 => PUSH {r4,lr})
BD10F827 => F827_F000 => BL init, (BD10 => POP {r4,pc})
68004805
 @f0  BF004700 BF00E7FD BF00E7FD BF00E7FD
 @100  0000E7FD 00043000 69814807 61811C49
 @110  49064A07 490762D1 21506101 BF0062C1
 @120  62C12111 00004770 20046F80 D0D0D0D0
 @130  20046FC0 B000B000 F000B510 BD10F81D
 @140  F7FFB510 BD10FFC5 F7FFB510 BD10FFC4
 @150  F7FFB510 BD10FFC3 F7FFB510 BD10FFB7
 @160  F7FFB510 BD10FFAF F7FFB510 BD10FFAD
 @170  F7FFB510 BD10FFA5
 @12C
1C402000 => main starts from here __main
DBFC2801
47702000 => ENDP
 @138
000000E5 000000E5

-------------------------

------------------------------
compiling c files:
------------------------------
create file hellow.c. Put some code in it: int main () {while (1); }. Then compile hellow.c file using armcc, armasm, armlink, fromelf:
A. compiler: creates obj files (*.o) from .c files
   armcc: obj file is created using armcc(ARM C compiler): path is /apps/ame/bin/armcc: run "armcc -help" for options.
    ex: armcc -4.0-821 --cpu=Cortex-M0 -I ./CMSIS/Core/CM0 -c --data_reorder --diag_suppress=2874 --asm --interleave -D MSC_CLOCK -D ITERATIONS=5 -O2 -Otime -Ono_autoinline -o hellow.o hellow.c
       -I <dir> => Include <directory> on the #include search path
       -c => Compile only, do not link
       --cpu => selects cpu for which to generate code,
       --asm => generates assembly code too (hellow.s).
       --interleave => interleaves C source with assembly code in hellow.txt file.
       -O0 => Minimum optimization, -O2 => high optimization
       -Otime => Optimize for maximum performance
       -D <symbol>  =>   Define <symbol> on entry to the compiler
B. linker: combines the contents of one or more object files with selected parts of one or more object libraries to produce executable images, partially linked object files, or shared object files.
   armlink: create object files for any other C files if needed. Then create ELF (Executable and linkable format) file using armlink:
    ex: armlink -4.0-821 --map --ro-base=0x0 --rw-base=0x20000020 --first='boot_debugdriver.o(vectors)' --datacompressor=off --info=inline -o hellow.elf hellow.o boot_debugdriver.o system_cm0ikdebugdriver.o retarget_cm0ikdebugdriver.o
      -o => creates output as hellow.elf
      --datacompressor off => Do not compress RW data sections.
      --ro-base n   =>  Set exec addr of region containing RO sections.
      --rw-base n   =>  Set exec addr of region containing RW/ZI sections.
      --map         =>  Display memory map of image.
      --info topic  =>  List misc. information about image, depending on topic.
C. fromelf: executable image is created using fromelf, which is image loaded into memory:
    ex: fromelf -4.0-821 --bin -o hellow.bin hellow.elf => creates plain binary hellow.bin from hellow.elf

-----------------
RunIk for hellow test case:
-----------------
EX: when we make hellow.c, this is the seq:
cmd: RunIK -build -make hellow

1. Makefile rules specified in Makefile. For TGT=hellow, hellow.bin is needed which in turn is generated from hellow.elf, which in turn is from hellow.o:
 - hellow -> hellow.bin -> hellow.elf -> hellow.o:
   - DEP: hellow.c CMSIS/Core/CM0/core_cm0.h CMSIS/Core/CM0/core_cm0.c cm0ikmcu.h IKtests.h IKtests.c IKConfig.h debug_i2c.h sporsho_tb.h Makefile debugdriver (debugdriver has a rule specified below, so if debugdriver is out of date, armcc(ACTION) doesn't run yet)
   - ACTION: armcc -4.0-821 --cpu=Cortex-M0 -I ./CMSIS/Core/CM0 -c --data_reorder --diag_suppress=2874 --asm  -D MSC_CLOCK -D ITERATIONS=5 -O2 -Otime -Ono_autoinline -Ono_inline -o hellow.o hellow.c

2. debugdriver make rule specified.
 - debugdriver -> debugdriver.bin -> debugdriver.elf -> debugdriver.o:  (We compile debugdriver, since this code always runs on the Cortex-M0 core within the debug driver module in the Integration Kit testbench)
   - DEP: debugdriver.c CMSIS/Core/CM0/core_cm0.h CMSIS/Core/CM0/core_cm0.c cm0ikdebugdriver.h Makefile debugdriver.h IKConfig.h
   - ACTION: armcc -4.0-821 --cpu=Cortex-M0 -I ./CMSIS/Core/CM0 -c --data_reorder --diag_suppress=2874 -o debugdriver.o debugdriver.c => action

3. ELF file generated using linker.
 - debugdriver.elf:
   - DEP: debugdriver.o boot_debugdriver.o system_cm0ikdebugdriver.o retarget_cm0ikdebugdriver.o
   - ACTION: armlink -4.0-821  --map --ro-base=0x0 --rw-base=0x20000020 --first='boot_debugdriver.o(vectors)' --datacompressor=off --info=inline -o debugdriver.elf debugdriver.o boot_debugdriver.o system_cm0ikdebugdriver.o retarget_cm0ikdebugdriver.o (boot_debugdriver.o system_cm0ikdebugdriver.o retarget_cm0ikdebugdriver.o have their DEP and ACTION defined for each, which uses .c files for each to generate .o files)

4. shows Memory Map of the image after running armlink
  Image Entry point : 0x000000c1
  Load Region LR_1 (Base: 0x00000000, Size: 0x00000ea8, Max: 0xffffffff, ABSOLUTE)
    Execution Region ER_RO (Base: 0x00000000, Size: 0x00000e2c, Max: 0xffffffff, ABSOLUTE)

   Base Addr    Size         Type   Attr      Idx    E Section Name        Object

    0x00000000   0x000000c0   Data   RO            6    vectors             boot_debugdriver.o
    0x000000c0   0x00000008   Code   RO           18  * !!!main             __main.o(c_p.l)
    0x000000c8   0x0000003c   Code   RO          173    !!!scatter          __scatter.o(c_p.l)
    0x00000104   0x0000001a   Code   RO          175    !!handler_copy      __scatter_copy.o(c_p.l)
    0x0000011e   0x00000002   PAD
    0x00000120   0x0000001c   Code   RO          177    !!handler_zi        __scatter_zi.o(c_p.l)
    0x0000013c   0x00000006   Code   RO           53    .ARM.Collect$$libinit$$00000000  libinit.o(c_p.l)
    0x00000142   0x00000000   Code   RO           62    .ARM.Collect$$libinit$$00000006  libinit2.o(c_p.l)
    ...
    0x00000144   0x00000002   Code   RO          119    .ARM.Collect$$libshutdown$$00000000  libshutdown.o(c_p.l)
    ...
    0x00000160   0x00000006   Code   RO          106    .ARM.Collect$$rtexit$$00000004  rtexit2.o(c_p.l)
    0x00000166   0x00000002   PAD
    0x00000168   0x00000c0c   Code   RO            1    .text               debugdriver.o
    0x00000d74   0x00000020   Code   RO            5    .text               boot_debugdriver.o
    0x00000d94   0x00000002   Code   RO           14    .text               use_no_semi_2.o(c_p.l)
    0x00000d96   0x00000020   Code   RO           16    .text               llushr.o(c_p.l)
    0x00000db6   0x00000002   Code   RO           20    .text               use_no_semi.o(c_p.l)
    0x00000db8   0x0000003e   Code   RO           42    .text               sys_stackheap_outer.o(c_p.l)
    0x00000df6   0x0000000c   Code   RO           45    .text               exit.o(c_p.l)
    0x00000e02   0x00000002   PAD
    0x00000e04   0x00000008   Code   RO           54    .text               libspace.o(c_p.l)
    0x00000e0c   0x00000020   Data   RO          171    Region$$Table       anon$$obj.o
    
    Execution Region ER_RW (Base: 0x20000020, Size: 0x0000007c, Max: 0xffffffff, ABSOLUTE)

    Base Addr    Size         Type   Attr      Idx    E Section Name        Object

    0x20000020   0x0000007c   Data   RW            3    .data               debugdriver.o


    Execution Region ER_ZI (Base: 0x2000009c, Size: 0x00000078, Max: 0xffffffff, ABSOLUTE)

    Base Addr    Size         Type   Attr      Idx    E Section Name        Object

    0x2000009c   0x00000018   Zero   RW            2    .bss                debugdriver.o
    0x200000b4   0x00000060   Zero   RW           55    .bss                libspace.o(c_p.l)

5. generate bin file from .elf:
 - debugdriver.bin:
   - DEP: debugdriver.elf
   - ACTION: fromelf -4.0-821 -bin -o debugdriver.bin debugdriver.elf

6. Now, since debugdriver is made, hellow.o gets generated running armcc (STEP 1). Once that is done, linker runs to gen hellow.elf
 - hellow.elf:
   - DEP: hellow.o boot.o system_cm0ikmcu.o retarget_cm0ikmcu.o IKtests.o debug_i2c.o sporsho_tb.o
   - ACTION: armlink -4.0-821 --map --ro-base=0x0 --rw-base=0x20000020 --symbols --first='boot.o(vectors)' --datacompressor=off --info=inline -o hellow.elf hellow.o boot.o system_cm0ikmcu.o retarget_cm0ikmcu.o IKtests.o debug_i2c.o sporsho_tb.o (boot.o system_cm0ikmcu.o retarget_cm0ikmcu.o IKtests.o debug_i2c.o sporsho_tb.o have their own DEP and ACTION defined and so make runs for each)

7. It show image symbol table at this point:
Image Symbol Table
    Local Symbols
    Symbol Name                              Value     Ov Type        Size  Object(Section)

    vectors                                  0x00000000   Section       96  boot.o(vectors)
    ../../angel/boardlib.s                   0x00000000   Number         0  boardshut.o ABSOLUTE
    similarly for kernel.s, startup.s, sys.s. armsys.c, libinit.s, signal.c, hellow.c, boot.c, etc
    .text                                    0x000000ec   Section        0  hellow.o(.text)
    .text                                    0x000001b0   Section        0  boot.o(.text)
    .text                                    0x000001f0   Section        0  sporsho_tb.o(.text)
    .text                                    0x000006e8   Section        2  use_no_semi_2.o(.text)
    .text                                    0x000006ec   Section        0  strlen.o(.text)
    .text                                    0x00000730   Section        2  use_no_semi.o(.text)
    .text                                    0x00000732   Section       62  sys_stackheap_outer.o(.text)
    .text                                    0x00000770   Section        0  exit.o(.text)
    .text                                    0x0000077c   Section        8  libspace.o(.text)
    .bss                                     0x20000020   Section       96  libspace.o(.bss)

    Global Symbols
    Symbol Name                              Value     Ov Type        Size  Object(Section)
    
    __ARM_use_no_argv                        0x00000000   Number         0  hellow.o ABSOLUTE
    __Vectors                                0x00000000   Data          96  boot.o(vectors)
    _printf_flags                            0x00000000   Number         0  printf_stubs.o ABSOLUTE
    _init_alloc                               - Undefined Weak Reference
    __main                                   0x00000061   Thumb Code     8  __main.o(!!!main)
    main                                     0x000000ed   Thumb Code   116  hellow.o(.text)
    NMI_Handler                              0x000001b1   Thumb Code     2  boot.o(.text)
    __temporary_stack_top$libspace           0x20000080   Data           0  libspace.o(.bss)

8. shows Memory Map of the image
  Image Entry point : 0x00000061
  Load Region LR_1 (Base: 0x00000000, Size: 0x00000794, Max: 0xffffffff, ABSOLUTE)
    Execution Region ER_RO (Base: 0x00000000, Size: 0x00000794, Max: 0xffffffff, ABSOLUTE)

    Base Addr    Size         Type   Attr      Idx    E Section Name        Object
    0x00000000   0x00000060   Data   RO            4    vectors             boot.o
    0x00000060   0x00000008   Code   RO           22  * !!!main             __main.o(c_p.l)
    0x00000784   0x00000010   Data   RO          175    Region$$Table       anon$$obj.o

    Execution Region ER_RW (Base: 0x20000020, Size: 0x00000000, Max: 0xffffffff, ABSOLUTE)
    **** No section assigned to this execution region ****

    Execution Region ER_ZI (Base: 0x20000020, Size: 0x00000060, Max: 0xffffffff, ABSOLUTE)
    Base Addr    Size         Type   Attr      Idx    E Section Name        Object
    0x20000020   0x00000060   Zero   RW           59    .bss                libspace.o(c_p.l)

9. generate binary executable hellow.bin which gets loaded into fram (This loading is done via using preload feature of memory to write desired hex value into fram. This is done in verilog "initial begin .. end").
 - hellow.bin:
   - DEP: hellow.elf
   - ACTION: fromelf -4.0-821 --bin -o hellow.bin hellow.elf

10. After this the simulator runs.
---------------------------------------



---------------------------------------------------------------
cortex M0 assembly:
---------------------------------------------------------------

ARM assembly code: => http://www.keil.com/support/man/docs/armasm/armasm_babdagdi.htm
-----------------------------------------

ASM syntax: ASM syntax depends on assembler we are using. Here syntax wrt ARM assembler is discussed. The general form of source lines in assembly language is:

{symbol} {instruction|directive|pseudo-instruction} {;comment}

All three sections of the source line are optional.

symbol is usually a label. In instructions and pseudo-instructions it is always a label. In some directives it is a symbol for a variable or a constant. The description of the directive makes this clear in each case.

Instructions and pseudo-instructions make up the code a processor uses to perform tasks. It's of form: opcode, operand1, operand2, ... => 1st operand is destination, remaining operands depend on type of inst.

double bars || ... || : If you use the same name as an instruction mnemonic or directive, use double bars to delimit the symbol name.

Directives provide important information to the assembler that either affects the assembly process or affects the final output image. They are used by assembler and are not part of m/c code to be generated.

Data definition directives allow insertion of constants inside assembly code. 3 kinds generally used:

1. DCI (define constant inst): used to code an inst, if assembler can't generate the exact inst that we want, and if we know the binary code of that inst. ex: DCI 0xBE00 :

2. DCB:

3. DCD:

Previous

ex: MOV R0, #0x12; set R0=0x12 (in hex)

ex: ADD R0, R1; R0=R0+R1, written in traditional Thumb syntax (not to be used)

ex: ADD R0, R0, R1; R0=R0+R1, written in UAL syntax, which is what is preferred


ELF sections:
-------------
AREA: In a source file, the AREA directive marks the start of a section. This directive names the section and sets its attributes.
END: The END directive instructs the assembler to stop processing this source file. Every assembly language source module must finish with an END directive on a line by itself.

----------------------------------------------
example assembly file generated by armcc
------------------------------------------------
This is the c code:
---------------------
#include "cm0ikmcu.h"
#include "sporsho1.h"
#include "sporsho_tb.h"

volatile uint16_t err = 1;

int main() {
  SYSTEM->MAGICN = 0x4A454449;
  SYSTEM->FRAM_WAIT = 0;
  SYSTEM->MAGICN = 0x0;
  msg_disp("kail_rtsc:\n");
  RTSC->CTRL = RTSC_IE_EN;
  NVIC_EnableIRQ(RTSC_IRQn);
  while (err);
  return err;
}
void RTSC_IRQHandler()
{
  NVIC_DisableIRQ(RTSC_IRQn);
  RTSC->CTRL = RTSC_IE_DIS;
  err--;
  NVIC_EnableIRQ(RTSC_IRQn);
  RTSC->CTRL = RTSC_IE_EN;
}
-------------------------------
this is the asm code:
---------------------
; generated by ARM C/C++ Compiler, RVCT4.0 [Build 821]
; commandline armcc [-c --asm -okail_rtsc.o --cpu=Cortex-M0 -Otime --data_reorder -Ono_autoinline -Ono_inline --diag_suppress=2874 -I./CMSIS/Core/CM0 -DMSC_CLOCK -DITERATIONS=5 kail_rtsc.c]
        THUMB
        REQUIRE8
        PRESERVE8

----- defines code section below -----
        AREA ||.text||, CODE, READONLY, ALIGN=2 => The AREA directive instructs the assembler to assemble a new code or data section. Sections are independent, named, indivisible chunks of code or data that are manipulated by the linker. Syntax "AREA sectionname{,attr}{,attr}..." |.text| is used for code sections produced by the C compiler, or for code sections otherwise associated with the C library. Attr are: CODE=Contains machine instructions. READONLY is the default. DATA=Contains data, not instructions. READWRITE is the default. ALIGN=expression => aligns on "expr" byte boundry. ALIGN=2=> align on 2^2=4 byte boundary. If ALIGN=10=> align on 2^10=1 KB boundary. By default, ELF sections are aligned on a 4-byte boundary.
    
-----------------------
#NVIC_EnableIRQ PROC is defined in Testbenches/digtop/tc/c/CMSIS/Core/CM0/core_cm0.h. C code is below:
static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
{
  NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F));                             /* enable interrupt */
}

#NVIC is a struct of type NVIC_Type
#define     __I     volatile const            /*!< defines 'read only' permissions      */
#define     __O     volatile                  /*!< defines 'write only' permissions     */
#define     __IO    volatile                  /*!< defines 'read / write' permissions   */

typedef struct
{
  __IO uint32_t ISER[1];                      /*!< Interrupt Set Enable Register            */
       uint32_t RESERVED0[31];
  __IO uint32_t ICER[1];                      /*!< Interrupt Clear Enable Register          */
       uint32_t RSERVED1[31];
  __IO uint32_t ISPR[1];                      /*!< Interrupt Set Pending Register           */
       uint32_t RESERVED2[31];
  __IO uint32_t ICPR[1];                      /*!< Interrupt Clear Pending Register         */
       uint32_t RESERVED3[31];
       uint32_t RESERVED4[64];
  __IO uint32_t IP[8];                        /*!< Interrupt Priority Register              */
}  NVIC_Type;

#define SCS_BASE            (0xE000E000)                              /*!< System Control Space Base Address    */
#define NVIC_BASE           (SCS_BASE +  0x0100)                      /*!< NVIC Base Address =  0xE000E100      */
#define NVIC                ((NVIC_Type *)          NVIC_BASE)        /*!< NVIC configuration struct            */

---------------------
NVIC_EnableIRQ PROC asm code below=> r0 is already loaded with 7, which is IRQn
        LSLS     r2,r0,#27 => r2:= r0 << 27 (logical left shift by 27, shifting in 0)
        LSRS     r2,r2,#27 => r2:= r2 >> 27 (logical right shift by 27, shifting in 0), so [31:5]=0 => r2 stores lower 5 lsb of r0 => r2=7. => corresponds to r2= ((uint32_t)(IRQn) & 0x1F))
        MOVS     r1,#1       => r1:= 1
        LSLS     r1,r1,r2  => r1:= r1 << r2, In r1, 1 is placed at bit location 7 (which is stored in [4:0] of r0). corrsponds to r1= (1 << ((uint32_t)(IRQn) & 0x1F))
        LSRS     r0,r0,#5  => r0:= r0 >> 5, since r0 was 7, so now r0=0. => corresponds to r0=((uint32_t)(IRQn) >> 5)
        LDR      r2,|L1.112| => loads word from this label. r2:= 0xe000e100(4 bytes stored in this mem loc) (label needs to be word aligned). This addr=0xe000e100 is in system segment (top 512MB) as NVIC->ISER (interrupt set enable register). It stores "set" bits for IRQ31 to IRQ0.
        LSLS     r0,r0,#2  => r0:= r0 << 2 , r0=r0*4 (r0=0)
        ADDS     r0,r0,r2  => r0:= r0 + r2 , r0=0 + 0xe000e100 (since initial r0=0, so r0=0xe000e100)
        STR      r1,[r0,#0]=> [r0+0]:=r1, stores word from reg r1 (which has bit set for IRQ7) to mem addr [r0]=0xe000e100.  corresponds to NVIC->ISER[((uint32_t)(IRQn) >> 5)] = r1 => [0xe000e100]=IRQ7 set.
        BX       lr        => PC:=lr & 0xFFFF_FFFE, so, pc=lr (with lsb=0), HW aligned
        ENDP

--------------------
#NVIC_DisableIRQ PROC clears the int bit.
static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
{
  NVIC->ICER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F));    /* disable interrupt */
}

-----------
NVIC_DisableIRQ PROC asm code below:
        LSLS     r2,r0,#27
        LSRS     r2,r2,#27
        MOVS     r1,#1
        LSLS     r1,r1,r2
        LSRS     r0,r0,#5
        LDR      r2,|L1.116| => r2:= 0xe000e180
        LSLS     r0,r0,#2
        ADDS     r0,r0,r2
        STR      r1,[r0,#0]
        BX       lr
        ENDP

------------
int main() {

  SYSTEM->MAGICN = 0x4A454449;
  SYSTEM->FRAM_WAIT = 0;
  SYSTEM->MAGICN = 0x0;

  msg_disp("kail_rtsc:\n");
  RTSC->CTRL = RTSC_IE_EN;

  NVIC_EnableIRQ(RTSC_IRQn);
  while (err);

  return err;
}
-----------
main PROC
        PUSH     {r4,lr}      => push r4 lr on stack
        LDR      r0,|L1.124|  => r0:=0x50007000 (addr of SYSTEM->MAGICN)
        LDR      r1,|L1.120|  => r1:=0x4a454449 (value of SYSTEM->MAGICN)
        STR      r1,[r0,#0]   => [r0+0]:=r1, stores 0x4a454449 into 0x50007000(SYSTEM->MAGICN = 0x4A454449;)
        MOVS     r1,#0           => r1:=0
        STR      r1,[r0,#0xc] => stores 0 into addr 0x50007000+0xc (SYSTEM->FRAM_WAIT = 0;)
        STR      r1,[r0,#0]   => stores 0 into addr 0x50007000+0x0 (SYSTEM->MAGICN = 0x0;)
        ADR      r0,|L1.128|  => load label into r0. r0:=label |L1.128| which stores "kail_rtsc:\n",0 (0=null char to signify end of string)
        BL       msg_disp     => branch to msg_disp. arg of msg_disp is a pointer to char, so starting addr stored in r0. There's strlen() fn called within msg_disp that figures out the length of the string (string is the arg to msg_disp)
        MOVS     r0,#1          => r0:= 1
        LDR      r1,|L1.140|  => r1:= 0x50006000
        LSLS     r0,r0,#11    => r0:= r0 << 11 , r0=1*2048, bit[11]=1, everything else is 0
        STRH     r0,[r1,#0]   => sets bit[11]=IE into 0x50006000(RTSC_reg)(RTSC->CTRL = RTSC_IE_EN;)
        MOVS     r0,#7        => r0:=7
        BL       NVIC_EnableIRQ => jumps to EnIRQ, which uses r0=7, LR=addr of next inst
        LDR      r0,|L1.144|  => r0:=.data section. .data section has mem addr that is determined later. It stores data variable "err" which has initial value=0x0001.
|L1.76|                       => following 3 inst are for while (err);
        LDRH     r1,[r0,#0]  ; err => LDRH calc addr=r0+#0 and loads halfword from mem and 0 extends it to form word and writes into r1. here, r1:=load contents from .data section, which stores variable "err" with value=0x0001. so, r1:=0x0001
        CMP      r1,#0        => subtracts 0 from contents of r1, updates condition flag (z bit, nbit, cbit, vbit in APSR) based on result and discards the result.
        BNE      |L1.76|    => if Z bit (Zero flag in APSR) != 0, jump to |L1.76| (2 stmt above)
        MOVS     r0,#0        => else r0:=0
        POP      {r4,pc}    => pop r4 pc from stack. So, r4 gets it's initial value while pc=lr
        ENDP

---------------
void RTSC_IRQHandler()
{
  NVIC_DisableIRQ(RTSC_IRQn);
  RTSC->CTRL = RTSC_IE_EN;
  err--;
}
------------
RTSC_IRQHandler PROC asm code below         => this process not called from anywhere inside the pgm
        PUSH     {r4,lr}    => push r4 lr on stack just as in main proc
        MOVS     r0,#7        => r0:=7
        BL       NVIC_DisableIRQ =>jump to DisIRQ
        MOVS     r0,#1          => r0:=1. following inst to set IE
        LDR      r1,|L1.140|    => r1:= 0x50006000
        LSLS     r0,r0,#11    => r0:=r0<<11 => 11th bit of r0=1.
        STRH     r0,[r1,#0]     => stores bit[11]=IE=1 into 0x50006000 (RTSC->CTRL = RTSC_IE_EN;)
        LDR      r0,|L1.144|    => r0:=.data section (start of err--; )
        LDRH     r1,[r0,#0]  ; err => same as main process above. r1 stores err value:=0x0001,
        SUBS     r1,r1,#1    => r1:=r1-1 =>  err--;
        STRH     r1,[r0,#0]    => .data section start addr:=err=0
        POP      {r4,pc}    => pop r4 pc from stack.
        ENDP

|L1.112|
        DCD      0xe000e100 => DCD directive allocates one or more words of memory, aligned on 4-byte boundaries, and defines the initial runtime contents of the memory. & is a synonym for DCD. syntax: {label} DCD{U} expr{,expr}. Here it defines 1 word (4 bytes) of mem containing 0xe000e100 = mem addr of NVIC-ISER.
|L1.116|
        DCD      0xe000e180 =>  mem addr of NVIC-ICER.
|L1.120|
        DCD      0x4a454449
|L1.124|
        DCD      0x50007000
|L1.128|
        DCB      "kail_rtsc:\n",0 => DCB is same as DCD except that it allocates one or more bytes of memory, = is a synonym for DCB. It has 12 bytes here (incl null char at end), so next mem loc has offset 128+12=140 => |L1.140|
|L1.140|
        DCD      0x50006000
|L1.144|
        DCD      ||.data||

----- defines data section with name=arm_vfe_header below -----
        AREA ||.arm_vfe_header||, DATA, READONLY, NOALLOC, ALIGN=2

        DCD      0x00000000

----- defines data section with name=.data below -----
        AREA ||.data||, DATA, ALIGN=1 => |.data| is used for code sections produced by the C compiler. global and static variables are stored in the .data segment. .data section is as big as the sum of sizes of the initialized variables.
#below code is for this declaration of var: volatile uint16_t err = 1;
err
        DCW      0x0001 => DCW is same as DCD except that it allocates one or more halfwords (2 bytes as it's unit16_t) of memory. Here label "err" stores 0x0001.

__ARM_use_no_argv EQU 0

        EXPORT __ARM_use_no_argv => The EXPORT directive declares a symbol that can be used by the linker to resolve symbol references in separate object and library files. GLOBAL is a synonym for EXPORT. Use EXPORT to give code in other files access to symbols in the current file.
        EXPORT main [CODE]
        EXPORT RTSC_IRQHandler [CODE]
        EXPORT err [DATA,SIZE=2]

        IMPORT ||Lib$$Request$$armlib|| [CODE,WEAK] =>  => The IMPORT directive provides the assembler with a name that is not defined in the current assembly. symbol name defined in a separately assembledsource file, object file, or library. The name is resolved at link time to a symbol defined in a separate object file. The symbol is treated as a program address. WEAK = prevents the linker generating an error message if the symbol is not defined elsewhere. It also prevents the linker searching libraries that are not already included.
        IMPORT msg_disp [CODE] => msg_disp symbol defined in another file

        KEEP NVIC_EnableIRQ => The KEEP directive instructs the assembler to retain local symbols in the symbol table in the object file.
        KEEP NVIC_DisableIRQ

        ATTR FILESCOPE
        ATTR SETVALUE Tag_ABI_PCS_wchar_t,2 => sets value of Tag_ABI_PCS_wchar_t to 2
        ATTR SETVALUE Tag_ABI_enum_size,1
        ATTR SETVALUE Tag_ABI_optimization_goals,2
        ATTR SETSTRING Tag_conformance,"2.06"
        ATTR SETVALUE AV,18,1

        ASSERT {ENDIAN} = "little" => The ASSERT directive generates an error message during the second pass of the assembly if a given assertion is false. Use ASSERT to ensure that any necessarycondition is met during assembly.
        ASSERT {INTER} = {TRUE}
        ASSERT {ROPI} = {FALSE}
        ASSERT {RWPI} = {FALSE}
        ASSERT {IEEE_FULL} = {FALSE}
        ASSERT {IEEE_PART} = {FALSE}
        ASSERT {IEEE_JAVA} = {FALSE}
        END => denotes end of assembly file

----------------------------------------
hexdump of kail_rtsc.bin file:
------------------------------------------
This file is hexdump of kail_rtsc.bin
----------------------------
below is memory map of image:
Image Entry point : 0x00000061 => actually it's 00000060 (since HW aligned) which is from where the actual code starts. Before this addr is vector table.

Load Region LR_1 (Base: 0x00000000, Size: 0x00000794, Max: 0xffffffff, ABSOLUTE) => this indicates the total size of binary file. It has 3 execution regions:
1. Execution Region ER_RO (Base: 0x00000000, Size: 0x00000790, Max: 0xffffffff, ABSOLUTE) => this is read only section. Section names are .text for user binary and .ARM,.* for other binaries. It is primarily code section, but has data section in 2 places: vector table (0x00000000 to 0x0000060) and Region table (0x00000770 to 0x00000790)

2. Execution Region ER_RW (Base: 0x20000020, Size: 0x00000004, Max: 0xffffffff, ABSOLUTE) => this is read write ".data" section for storing global and static variables (which should be initialized as per C lang convention). It comes from object kail_rtsc.o. Here it stores "err", which is a variable defined in kail_rtsc.c.

NOTE: The Base addr of ER_RO and ER_RW comes from the Makefile during armlink" step, where ro-base=0x0 and rw-base=0x20000020. The size of these regions is figured out by the compiler during compilation. Remember that addr 0 of binary image file has MSP stored in it, so that should be modified to be pointing to the sram area. It's in boot.c in vector table section.

3. Execution Region ER_ZI (Base: 0x20000024, Size: 0x00000060, Max: 0xffffffff, ABSOLUTE) => this is read write ".bss" section which starts 4 bytes after the end of 2nd execution section. Is is that part of the data section that contains statically allocated variables. uninitialized data are stored in the .bss segment.It is zero initialized and comes from libspace.o in linker file (c_p.l)


----------------------------
1. Execution Region ER_RO
----------------------------

-----------------------
######### vector table
-----------------------
#0x00000000 to 0x0000060 is vector table (It's data section named "vectors" in object boot.o with type=DATA)
code in boot.c:
vect_t __Vectors[]
__attribute__ ((section("vectors"))) = {
  (vect_t)(0x00001FF0),     // Top of Stack - for 8KB FRAM
  (vect_t)Reset_Handler,    // Reset Handler
  (vect_t)NMI_Handler,      // NMI Handler
  (vect_t)HardFault_Handler,// Hard Fault Handler
  0,                        // Reserved
  0,                        // Reserved
  0,                        // Reserved
  0,                        // Reserved
  0,                        // Reserved
  0,                        // Reserved
  0,                        // Reserved
  (vect_t)SVC_Handler,      // SVCall Handler
  0,                        // Reserved
  0,                        // Reserved
  (vect_t)PendSV_Handler,   // PendSV Handler
  (vect_t)SysTick_Handler,  // SysTick Handler

  // External Interrupts 0 - 7
  (vect_t)CWT_IRQHandler,
  (vect_t)TMR0_IRQHandler,
  (vect_t)TMR12_IRQHandler,
  (vect_t)GPIO_IRQHandler,
  (vect_t)SIO_IRQHandler,
  (vect_t)ADC_IRQHandler,
  (vect_t)CPSW_IRQHandler,
  (vect_t)RTSC_IRQHandler,
};
----
asm code in boot.s is:
--
        AREA vectors, DATA, READONLY, ALIGN=2

__Vectors
        DCD      0x00001ff0
        DCD      Reset_Handler
        DCD      NMI_Handler
        DCD      HardFault_Handler
        DCD      0x00000000
        DCD      0x00000000
        DCD      0x00000000
        DCD      0x00000000
        DCD      0x00000000
        DCD      0x00000000
        DCD      0x00000000
        DCD      SVC_Handler
        DCD      0x00000000
        DCD      0x00000000
        DCD      PendSV_Handler
        DCD      SysTick_Handler
        DCD      CWT_IRQHandler
        DCD      TMR0_IRQHandler
        DCD      TMR12_IRQHandler
        DCD      GPIO_IRQHandler
        DCD      SIO_IRQHandler
        DCD      ADC_IRQHandler
        DCD      CPSW_IRQHandler
        DCD      RTSC_IRQHandler
----
#0000000 (starting from addr 0, these are the values in each mem addr)
03f0 2000 => addr 0(msp) is loaded with 2000_03f0 (this value hardcoded in boot.c)

NOTE: all vector handler addr below have 1 as LSB (not HW aligned), since bit[0] of vector addr sets the T bit (implies THUMBS code is being executed) in EPSR on that particular exception entry. If we have 0 in LSB, then T bit gets cleared. Attempting to execute instructions when the T bit is 0 results in a HardFault or lockup (since inst are Thumbs code and NOT arm code).
01bd 0000 => addr 4(reset vector) = 0000_01bd (addr of reset vector handler). since 01bd is not HW aligned, jump to addr=01bc
019d 0000 => addr 8 NMI fault handler addr, 0000_019d gets aligned to 0000_019c
019f 0000 => addr c Hard Fault handler addr, 0000_019f gets aligned to 0000_019e

#0000010 to 0000002b is reserved
0000010 0000 0000 0000 0000 0000 0000 0000 0000
0000020 0000 0000 0000 0000 0000 0000

01a1 0000 => addr 2C SVcall, 01a1 gets aligned to 01a0

#0000030 to  0000037 is reserved
0000030 0000 0000 0000 0000

01a3 0000 => adde 38 PendSV, 01a3 gets aligned to 01a2
01a5 0000 => addr 3C systick handler vector
01a9 0000 => addr 40 IRQ0
01ab 0000 => addr 44 IRQ1
01b1 0000 => addr 48 IRQ2
01a7 0000 => addr 4c IRQ3
01b3 0000 => addr 50 IRQ4
01b5 0000 => addr 54 IRQ5
01b7 0000 => addr 58 IRQ6
015f 0000 => addr 5c IRQ7 (Total 8 IRQ)


-----------------------
######### files from c_p.l
-----------------------
#An initialization sequence executes to set up the system before the main task is executed. These object files are part of C library provided in c_p.l. __main is the image entry point. It copies code, copies or decompress RW data, and zeroes uninit data. It then calls __rtentry which sets up stack and heap, init lib func, and then calls user main() code. Once user code finishes, it returns from user code and calls __rexit to exit from the app.

#0x0000060 to 0x00000108 is __main.o, __scatter.o, libinit.o, rtentry.o, rexit.o etc (all in /apps/arm/rvds/4.0-821/RVCT/Data/4.0/400/lib/armlib/c_p.l). Note that all std functions as stdio.h, etc are in /apps/arm/rvds/4.0-821/RVCT/Data/4.0/400/include/unix/*)

#0000060: __main starts here
f000 f802 => 0000060 jumped to this addr1 from Reset_Handler: f000f802  =  BL       {pc} + 0x8  ; 0x68
f000 f840

#0000068: __scatter.o starts here
a00c = 00000068 a00c =      ADR      r0,{pc}+0x34  ; 0x9c
c830 = 0000006a c830 =      LDM      r0!,{r4,r5}
3808 = 0000006c 3808 =      SUBS     r0,r0,#8
1824 = 0000006e 1824        ADDS     r4,r4,r0
182d = 00000070 182d        ADDS     r5,r5,r0
46a2 = 00000072 46a2        MOV      r10,r4
1e67 = 00000074 1e67        SUBS     r7,r4,#1
46ab = 00000076 46ab        MOV      r11,r5
4654 = 00000078 4654        MOV      r4,r10
465d = 0000007a 465d        MOV      r5,r11
42ac = 0000007c 42ac        CMP      r4,r5
d101 = 0000007e d101        BNE      {pc} + 0x6  ; 0x84
f000 f832 = 00000080 f000f832    BL       {pc} + 0x68  ; 0xe8 => jumps to rtentry.o only after loading of .data/.bss is done.
467e = 00000084 467e        MOV      r6,pc
3e0f = 00000086 3e0f        SUBS     r6,r6,#0xf
cc0f = 00000088 cc0f        LDM      r4!,{r0-r3} => Load Multiple Increment (LDM) After loads multiple registers from consecutive memory locations using an address from a base register. "!" means that base register should not included for loading. lowest numbered reg is loaded from lowest mem addr and highesr numbered reg is loaded from highest mem addr. here reg r0,r1,r2,r3 are loaded with mem loc starting from addr in r4. Reg r4=0x00000780. So, r0=(0x770)=00000790, r1=(0x774)=20000020, r2=(0x778)=00000004, r3=(0x77c)=000000a4. so, 1st symbol table entry (ER_RW) for .data is loaded. Next time it comes here, Reg r4=0x00000790, so it loads the 2nd symbol table entry (ER_ZI)

46b6 = 0000008a 46b6        MOV      lr,r6
2601 = 0000008c 2601        MOVS     r6,#1
4233 = 0000008e 4233        TST      r3,r6
d000 = 00000090 d000        BEQ      {pc} + 0x4  ; 0x94
1afb =
46a2 = 00000094 46a2        MOV      r10,r4
46ab = 00000096 46ab        MOV      r11,r5
4333 = 00000098 4333        ORRS     r3,r3,r6
4718 = 0000009a 4718        BX       r3 => jump to scatter_copy.o the first time. Next time it jumps to scatter_zi.o.
06d4
0000
00000a0 06f4 0000

#000000a4: __scatter_copy.o starts here
3a10 = 000000a4 3a10        SUBS     r2,r2,#0x10
d302 c878 c178 d8fa 0752
00000b0 d301 c830 c130 d501
6804 = 000000b8 6804        LDR      r4,[r0,#0]
600c = 000000ba 600c        STR      r4,[r1,#0] => stores 1 into mem addr=2000_0020 (init err=1)
4770 = 000000bc 4770        BX       lr => jump to 0x78
0000 => 2 byte padding

#000000c0: __scatter_zi.o
00000c0 2300 2400 2500 2600 3a10 d301 c178 d8fb
00000d0 0752 d300 c130 d500 600b 4770

#00000dc: libinit.o,
b51f = 000000dc b51f        PUSH     {r0-r4,lr}
46c0 = 000000e0 46c0        MOV      r8,r8
46c0 = 000000e0 46c0        MOV      r8,r8

#00000e2: libinit2.o,
bd1f = 000000e2 bd1f        POP      {r0-r4,pc} => pc is loaded with 000000f2 which has inst to jmp to main proc (few inst below)

#000000e4: libshutdown.o
b510 = 000000e4 b510        PUSH     {r4,lr}

#000000e6: libshutdown2.o
bd10 = 000000e6 bd10        POP      {r4,pc}

#000000e8: rtentry.o, rtentry2.o, rtentry4.o
f000 fb19 = 000000e8 f000fb19    BL       {pc} + 0x636  ; 0x71e => jumps to sys_stackheap_outer.o
4611      = 000000ec 4611        MOV      r1,r2

#000000ee: rtentry2.o
f7ff fff5 = 000000ee f7fffff5    BL       {pc} - 0x12  ; 0xdc => jump few inst above
f000 f81d = 000000f2 f000f81d    BL       {pc} + 0x3e  ; 0x130 => jump to main proc in kail_rtsc.c
f000 fb31 = 000000f6 f000fb31    BL       {pc} + 0x666  ; 0x75c

#000000fa: rtexit.o
b403 = 000000fa b403        PUSH     {r0,r1}

#000000fc: rtexit2.o
f7ff fff2 = 000000fc f7fffff2    BL       {pc} - 0x18  ; 0xe4
bc03 = 00000100 bc03        POP      {r0,r1}
f000 f862 = 00000102 f000f862    BL       {pc} + 0xc8  ; 0x1ca
0000 = 2 byte padding


-----------------------
######### user code
-----------------------

#0x0000108 to 0x0000019c is kail_rtsc.o. It starts with inst in NVIC_EnableIRQ (since that process is in top of file) and then has NVIC_DisableIRQ proc, then main proc.
#In asm code for kail_rtsc.s, we see that this is marked as .text section: AREA ||.text||, CODE, READONLY, ALIGN=2
0000108: start of NVIC_EnableIRQ:
06c2 = 00000108 06c2        LSLS     r2,r0,#27
0ed2 = 0000010a 0ed2        LSRS     r2,r2,#27
2101 = 0000010c 2101        MOVS     r1,#1
4091 = 0000010e 4091        LSLS     r1,r1,r2
0940 = 00000110 0940        LSRS     r0,r0,#5
4a19 = 00000112 4a19        LDR      r2,[pc,#100]  ; [0x178] => 0x0114(next pc)+0d100=0x0114+0x0064=0x178. has NVIC->ISER addr=0xe000e100
0080 = 00000114 0080        LSLS     r0,r0,#2
1880 = 00000116 1880        ADDS     r0,r0,r2
6001 = 00000118 6001        STR      r1,[r0,#0]
4770 = 0000011a 4770        BX       lr

000011c: start of NVIC_DisableIRQ
06c2 = 0000011c 06c2        LSLS     r2,r0,#27
0ed2 = 0000011e 0ed2        LSRS     r2,r2,#27
2101 = 00000120 2101        MOVS     r1,#1
4091 = 00000122 4091        LSLS     r1,r1,r2
0940 = 00000124 0940        LSRS     r0,r0,#5
4a15 = 00000126 4a15        LDR      r2,[pc,#84]  ; [0x17c] => 0x0128(next pc)+0d84=0x0128+0x0054=0x017c. has NVIC->ICER addr=0xe000e180
0080 = 00000128 0080        LSLS     r0,r0,#2
1880 = 0000012a 1880        ADDS     r0,r0,r2
6001 = 0000012c 6001        STR      r1,[r0,#0]
4770 = 0000012e 4770        BX       lr

0000130: start of main proc. jumped here from addr=0x000000f2 which is in rtentry2.o
b510 = 00000130 b510        PUSH     {r4,lr}
4814 = 00000132 4814        LDR      r0,[pc,#80]  ; [0x184]
4912 = 00000134 4912        LDR      r1,[pc,#72]  ; [0x180]
6001 = 00000136 6001        STR      r1,[r0,#0]
2100 = 00000138 2100        MOVS     r1,#0
60c1 = 0000013a 60c1        STR      r1,[r0,#0xc]
6001 = 0000013c 6001        STR      r1,[r0,#0]
a012 = 0000013e a012        ADR      r0,{pc}+0x4a  ; 0x188
f000 f855 = 00000140 f000f855    BL       {pc} + 0xae  ; 0x1ee => branch to msg_disp
2001 4913 02c0 8008 2007 f7ff
ffdb
4811 = 00000152 4811        LDR      r0,[pc,#68]  ; [0x198] => loads r0 with data at 0x198 (which is .data section storing 0x2000_0020). So, r0=0x2000_0020
8801 = 00000154 8801        LDRH     r1,[r0,#0] => r0 stores mem addr=20000020, which has variable "err". so r1=err
2900 = 00000156 2900        CMP      r1,#0
d1fc = 00000158 d1fc        BNE      {pc} - 0x4  ; 0x154
8800 = 0000015a 8800        LDRH     r0,[r0,#0]
bd10 = 0000015c bd10        POP      {r4,pc}

000015e: start of RTSC_IRQHandler
b510 = 0000015e b510        PUSH     {r4,lr}
2007 = 00000160 2007        MOVS     r0,#7
f7ff ffdb = 00000162 f7ffffdb    BL       {pc} - 0x46  ; 0x11c => jump to NVIC_DisableIRQ
2001 = 00000166 2001        MOVS     r0,#1
490a = 00000168 490a        LDR      r1,[pc,#40]  ; [0x194]
02c0 = 0000016a 02c0        LSLS     r0,r0,#11
8008 = 0000016c 8008        STRH     r0,[r1,#0]
480a = 0000016e 480a        LDR      r0,[pc,#40]  ; [0x198]
8801 = 00000170 8801        LDRH     r1,[r0,#0]
1e49 = 00000172 1e49        SUBS     r1,r1,#1
8001 = 00000174 8001        STRH     r1,[r0,#0]
bd10 = 00000176 bd10        POP      {r4,pc} => end of process for main.

data varaibles start below. NOTE: this is NOT .data section for main(). It is still .text section. It stores all fixed constants .data section is put separately at the end, as we keep all .text section for all .o files together, and all .data section together for all .o files. Note that order of byte pair is reversed, since data is stored in mem as [31:0], while data in hexdump is [15:0],[31:16]
e100 e000 = 00000178 = |L1.112| DCD      0xe000e100 =>  allocates 1 word (4 bytes) of mem with initial contents = 0xe000e100. This initial content is actually mem addr of NVIC->ISER.
e180 e000 = 0000017c = |L1.116| DCD      0xe000e180 => mem addr of NVIC->ICER
4449 4a45 = 00000180 = |L1.120| DCD      0x4a454449
7000 5000 = 00000184 = |L1.124| DCD      0x50007000
616b 6c69 725f 7374 3a63 000a = 00000188 = |L1.128| DCB      "kail_rtsc:\n",0 => data in hexdump shows as [15:0], so data stored in mem[0:xx]=6b61_696c_5f72_7473_633a_0a00 => 6b=k, 61=a, 69=i, 6c=l ...  3a=:, 0a=new line feed(\n), 00=NULL. A string is always terminated by NULL character. That is how, end of string can be identified.
6000 5000 = 00000194 = |L1.140| DCD      0x50006000
0020 2000 = 00000198 = |L1.144| DCD      ||.data|| => .data section starts at 2000_0020

-----------------------
######### boot file:
-----------------------
#boot.c defines all of these: fault handlers as infinite while loop, reset handler which calls __main, vector_table which has msp, and addr of fault handlers and _sys_exit function.
#0x000019c to 0x000001dc is boot.o (look in boot.c or boot.s)
000019c to 000001bb: all fault handler (except reset handler) which branch to itself (infinite loop)
e7fe = 000019c: NMI_hanlder e7fe        B        {pc} => branches to itself, infinite loop, while(1);
e7fe = 000019e: HardFault_Handler
e7fe = 00001a0: SVC_Handler
e7fe = 00001a2: PendSV_Handler
e7fe = 00001a4: Systick nadler
e7fe = 00001a6: GPIO_IRQHandler
e7fe CWT_IRQHandler
e7fe TMR0_IRQHandler
4770 TMR1_IRQHandler BX       lr => just return back to caller. return;
4770 TMR2_IRQHandler

00001b0
e7fe TMR12_IRQHandler
e7fe SIO_IRQHandler
e7fe ADC_IRQHandler
e7fe CPSW_IRQHandler
e7fe RTSC_IRQHandler
e7fe Default_IRQHandler

#000001bc to 000001bf: Reset_Handler PROC starts here: it just calls __main
void Reset_Handler(void) {  __main(); }

b510 = 000001bc b510 PUSH     {r4,lr}
f7ff ff4f = 000001be BL       {pc} - 0x15e  ; jump to addr1=0x60 which is __main process
bd10 = POP      {r4,pc}

#__user_initial_stackheap PROC: this is the c code in boot.c:
__user_initial_stackheap(unsigned hb, unsigned sb, unsigned hl, unsigned sl) {    
  struct __initial_stackheap s;    
  s.heap_base   = hb;
  s.stack_base  = sb;
  s.heap_limit  = s.stack_base;
  s.stack_limit = s.heap_base;
  return s;
}

460a = 000001c4 460a        MOV      r2,r1 => r2 assigned 200003e8 = stack base
4603 = 000001c6 4603        MOV      r3,r0 => r3 assigned 20000020 = heap base
4770 = 000001c8 4770        BX       lr

#_sys_exit PROC: defn of TB_COM in sporsho_tb.h
typedef struct
{
  __IO uint8_t    STB;    // [0] stroble bit
  __IO uint8_t    CMD;    // [4:0] command bit
  __IO uint8_t    RUN;    // [0] dbg_run 0: idle, 1: run
  __IO uint8_t    ERR;    // [0] dbg_err 0: pass, 1: fail
} TB_DBG_TypeDef; //total size of TB_DBG is 1+1+1+1=4

typedef struct
{
  __IO uint16_t   ERR;    // Error code depend on each test case
  __IO uint8_t    STAT;   // Cleared by 0 during simulation startup phase.
              // Reset signal will not change this data
  __IO uint8_t    COM;    // Command for verilog test bench and data byte
              // Upper 4bit is byte num, Lower 4bit is command
  __IO uint32_t   DATA1;  // 4 byte data for verilog test bench
  __IO TB_DBG_TypeDef  DBG;
  __IO uint32_t   FLUSH;  // dummy for flush write buffer
} TB_COM_TypeDef; //total size of TB_COM is 2+1+1+4+4+4=16 bytes
#define TB_COM                  ((volatile TB_COM_TypeDef*) SRAM1K_BASE    )

#This is the c code in boot.c.
void _sys_exit(int return_code) {
  TB_COM->ERR   = return_code; // No error is 0x0000
  TB_COM->COM   = TB_COM_EXIT; // If this bit is asserted then Verilog testbench catch up this flag and call $finish.
  TB_COM->FLUSH = 0x00;        // Flush SRAM write buffer. If you don't, then TB_COM_EXIT bit is not carried to Verilog testbench
  while(1); //infinite loop, so pgm runs for ever
}
2101 = 000001ca 2101        MOVS     r1,#1
0749 = 000001cc 0749        LSLS     r1,r1,#29
8008 = 000001ce 8008        STRH     r0,[r1,#0]
2001 = 000001d0 2001        MOVS     r0,#1
70c8 = 000001d2 70c8        STRB     r0,[r1,#3]
2000 = 000001d4 2000        MOVS     r0,#0
60c8 = 000001d6 60c8        STR      r0,[r1,#0xc]
e7fe = 000001d8 e7fe        B        {pc}  ; 0x1d8
0000 = 000001da is 2 byte PADDING

data area vectors is defined after this in boot.s, which has vectors starting from addr=0x00 to 0x60

-----------------------
######### user lib file for common functions
-----------------------

#0x000001dc to 0x000006d4 is sporsho_tb.o (generated from sporsho_tb.c)
00001dc: start of putchar function
2101 0749
7108 2200 70ca 2312 70cb 60ca 4770

00001ee to 0006d3: start of msg_disp function
00001ee b5f8
00001f0 4604 f000 fa71 2100 460a 2800 dd17 2700
...
00006d0 4040 5000

-----------------------
######### additional files from c_p.l
-----------------------

#0x000006d4 to 0x00000790 is use_no_semi_2.o, strlen.o, exit.o, etc (in c_p.l)

#00006d4; use_no_semi_2.o
4770
0000 = 2 byte PAD

#000006d8: strlen.o
b530 1c44 e005 7801
00006e0 1c40 2900 d101 1b00 bd30 0781 d1f7 4b0a
00006f0 01dd c804 1ad1 4391 4029 d0fa 1b00 060a
0000700 d001 1ec0 bd30 040a d001 1e80 bd30 0209
0000710 d0fc 1e40 bd30 0000 0101 0101

#0000071c: use_no_semi.o
4770

#0000071e: sys_stackheap_outer.o
4675
0000720 f000 f822 46ae 0005 4669 4653 08c0 00c0
0000730 4685 b018 b520
f7ff fd45 =  00000736 f7fffd45    BL       {pc} - 0x572  ; 0x1c4
bc60 2700 0849
46b6 = 00000740 46b6        MOV      lr,r6
2600 = 00000742 2600        MOVS     r6,#0
c5c0 = 0000074e c5c0        STM      r5!,{r6,r7}
c5c0
c5c0
c5c0
c5c0
c5c0
c5c0
c5c0 = 00000752 c5c0        STM      r5!,{r6,r7}
3d40 = 00000754 3d40        SUBS     r5,r5,#0x40
0049 = 00000756 0049        LSLS     r1,r1,#1
468d = 00000758 468d        MOV      sp,r1
4770 = 0000075a 4770        BX       lr

#0000075c: exit.o
4604 = 0000075c 4604        MOV      r4,r0
46c0 = 0000075e 46c0        MOV      r8,r8
46c0 = 00000760 46c0        MOV      r8,r8
4620 = 00000762 4620        MOV      r0,r4
f7ff fcc9 = 00000764 f7fffcc9    BL       {pc} - 0x66a  ; 0xfa

#00000768: libspace.o
4800 4770 0024 2000

-----------------------
######### Region Table for .data/.bss
-----------------------

#00000770 to 00000790 is Region Table: anon$$obj.o. It's .data (not .text) section but Read only. Compiler relocates this .data section to appr mem loc, so that it can be RW instead of RO.
0000770 => deatils about .data section. (execution Region ER_RW). object is kail_rtsc.o
addr 770 = 0790 0000 = source location (from fram) to be copied. addr 770 stores 00000790, which is starting addr of all .data values. It stores value of err
addr 774 = 0020 2000 = dest location (in sram) to be init. addr 774 stores base addr for .data as 2000_0020 corresponding to err (execution Region ER_RW starts at 2000_0020)
addr 778 = 0004 0000 = no. of bytes to be init. addr 778 stores size of ER_RW as 4 bytes, even though it's only 2 bytes in size (as it's uint16_t). this is due to 2 byte padding because mem access in M0 are always word-aligned.
00a4 0000 = misc info.

0000780 => details about .bss section (execution Region ER_ZI). object is libspace.o(c_p.l)
0794 0000 = source location (from fram) to be copied. addr 780 stores 00000794 which stores nothing as it's .bss data (un initialized)
0024 2000 = dest location (in sram) to be init. addr 784 stores base addr for .bss as 2000_0024 (execution Region ER_ZI starts at 2000_0024)
0060 0000 = no. of bytes to be init. addr 788 stores size of ER_ZI as 96 bytes (hex=0x60 bytes)
00c0 0000 = misc info

-----------------------
######### actual init values to be stored for .data section
-----------------------

#0000790: this stores the initial values of all .data and .bss sections.
0001 => init value of err. err is deined as 16 bit in kail_rtsc.c (volatile uint16_t err = 1;)
0000 => PADDING.
           
-symbol table above looks like this:
-------------
0x770: ER_RW = src_addr (in fram) | dest_addr (in sram) | no_of_bytes | misc_info
0x780: ER_ZI = src_addr (in fram) | dest_addr (in sram) | no_of_bytes | misc_info
0x790: DATA  = var1, var2, .... varn => this stores initial values of all var to be init in ER_RW section.
------------

-----------------------
######### end of binary file. No data below. 0000793 is last addr, so, size of file is 0x794 bytes
-----------------------


--------------------------------------
inst seq during execution on M0:
--------------------------------
At start, HReset line is low. Processor in in reset, with AHB bus idle. HTRANS[1]=0(idle), HADDR[31:0]=4, HMASTER=1(=> src of transactio is NOT core but slave, so basically it refers to idle spot). HPROT[3:0]=1010=a (cacheable, not bufferable, privileged, opcode). HSIZE=0(1 byte).

Now, when HRESET goes high, then 2 cycles later, AHB starts firing.
3rd HCLK cycle: HADDR=0, HMASTER=0, HSIZE=2(1 Word), HTRANS=2. HPROT[3:0]=1011=b (cacheable, not bufferable, privileged, data). HSIZE=0(1 byte) => read from addr 0. Loading msp.
4th HCLK cycle: HADDR=4 => read from addr 4 (addr of reset vector). HPROT[0]=1=data. It's read as 10D (HRDATA[31:0]=10C)
5th HCLk cycle: HADDR=4, HMASTER=1, HSIZE=0(1 byte), HTRANS=0. => dumy cycle. inst to jump is being prepared.
6th HCLK cycle: HADDR=10C, HMASTER=0, HSIZE=2(1 Word), HTRANS=2, HPROT[0]=0=opcode => jumps to reset ISR and fetches 1st inst from there.
7th HCLK cycle: still processing previous inst. 1st inst in any function call is "PUSH     {r4,lr}" which is being processed here.
8th-10th HCLK cycle: actual push inst executes here.  This pushes r4 onto the lower mem and lr onto higher mem. SP is updated to point to the lowest loaded mem. In 8th HCLK, next seq inst at addr 110 gets fetched. In 9th HCLK, r4 is written to mem SP-8. In 10th HCLK, lr is written to mem SP-4, SP is updated to SP-8 and next inst is fetched which is "branch to 0x60 = __main process".

----------------------------------------

retarget.c: (in veridian) => This file Retargets printf and scanf statements to AHB Snooper or UART. printf fn calls fputc/fgetc (via compiled code), and we intercept the fputc/fgetc to retarget to AHB or UART
----------

#ifdef UART //for UART
int fputc(int ch, FILE *f) {
        int delay,codereturn;
        codereturn = UartPutc(ch); //UartPutc defined as {USART_Transmit(USART,ch); return(ch);} => In USART_Transmit, ch assigned to tx buffer. pusart->UTBUF = ch;
        for(delay = 0; delay < 2000; delay++);
  return (codereturn);
}
int fgetc(FILE *f) {
  return (UartPutc(UartGetc())); //UartGetc defined as {unsigned short int data = 0; USART_Receive(USART, &data); return data;} => In USART_Receive, *(&data) assigned to rx buffer. *pdata |= (pusart->URBUF);
}
#else //for AHB
int fputc(int ch, FILE *f) {
  (*(volatile int *)(0x20002F10)) = ch; //string i/p on this addr
  (*(volatile int *)(0x20002F14)); //string display on this addr. NOTE: this is just reading that addr, but not assigning read value to anything.
  return ch;
}
int fgetc(FILE *f) {
  return 0; //does nothing as we don't process any scanf inputs
}
#endif
----
display_monitor.v => This snoops for addr and outputs string in verilog
----
//set flag
always @ (posedge HCLK or negedge HRESETN) begin //this snoops for above addr on AHB bus, and sets flag
    if(~HRESETN)
        string_input_flag <= 0;
        string_display_flag <= 0;
    else if ((i_haddr == 32'h20002F10) & `hready & `htrans[1]) string_input_flag <= 1;
    else if ((i_haddr == 32'h20002F14) & `hready & `htrans[1]) string_display_flag <= 1;
end

//store string
reg [7:0] string_store;
always @ (posedge HCLK) begin
 if(string_input_flag)
   string_store = hwdata[7:0]; => on each addr match, data on next clk is stored in this array (only lower 8 bits, as it's ASCII char) .
   string_input_flag <= 0; => after each char, flag is again reset
end

//display string
always @ (posedge HCLK) begin
 if(string_display_flag)
     $write("%s",string_store); //In this case, in fgetc function, string display is right after string input, so only 1 char stored at a time. %s used to display ASCII equiv for hex value.
     string_display_flag <= 0;
end
------