學習日誌之runaway c的執行及解釋

2021-09-23 20:49:59 字數 3840 閱讀 3338

1.runaway.c的**展示

2.執行例項

3.詳細解釋及知識點

1.runaway.c**如下

/* example of deep recursion */

#include

#include

intrecurse

(int x)

intmain

(int argc,

char

*ar**)

2.執行例項1.不帶引數

x = 100.  a at 0xbfd3f8b0

x = 99. a at 0xbfd1f890

x = 98. a at 0xbfcff870

x = 97. a at 0xbfcdf850

x = 96. a at 0xbfcbf830

x = 95. a at 0xbfc9f810

x = 94. a at 0xbfc7f7f0

x = 93. a at 0xbfc5f7d0

x = 92. a at 0xbfc3f7b0

x = 91. a at 0xbfc1f790

x = 90. a at 0xbfbff770

x = 89. a at 0xbfbdf750

x = 88. a at 0xbfbbf730

x = 87. a at 0xbfb9f710

x = 86. a at 0xbfb7f6f0

x = 85. a at 0xbfb5f6d0

x = 84. a at 0xbfb3f6b0

x = 83. a at 0xbfb1f690

x = 82. a at 0xbfaff670

x = 81. a at 0xbfadf650

x = 80. a at 0xbfabf630

x = 79. a at 0xbfa9f610

x = 78. a at 0xbfa7f5f0

x = 77. a at 0xbfa5f5d0

x = 76. a at 0xbfa3f5b0

x = 75. a at 0xbfa1f590

x = 74. a at 0xbf9ff570

x = 73. a at 0xbf9df550

x = 72. a at 0xbf9bf530

x = 71. a at 0xbf99f510

x = 70. a at 0xbf97f4f0

x = 69. a at 0xbf95f4d0

x = 68. a at 0xbf93f4b0

x = 67. a at 0xbf91f490

x = 66. a at 0xbf8ff470

x = 65. a at 0xbf8df450

x = 64. a at 0xbf8bf430

x = 63. a at 0xbf89f410

x = 62. a at 0xbf87f3f0

x = 61. a at 0xbf85f3d0

x = 60. a at 0xbf83f3b0

x = 59. a at 0xbf81f390

x = 58. a at 0xbf7ff370

x = 57. a at 0xbf7df350

x = 56. a at 0xbf7bf330

x = 55. a at 0xbf79f310

x = 54. a at 0xbf77f2f0

x = 53. a at 0xbf75f2d0

x = 52. a at 0xbf73f2b0

x = 51. a at 0xbf71f290

x = 50. a at 0xbf6ff270

x = 49. a at 0xbf6df250

x = 48. a at 0xbf6bf230

x = 47. a at 0xbf69f210

x = 46. a at 0xbf67f1f0

x = 45. a at 0xbf65f1d0

x = 44. a at 0xbf63f1b0

x = 43. a at 0xbf61f190

x = 42. a at 0xbf5ff170

x = 41. a at 0xbf5df150

x = 40. a at 0xbf5bf130

x = 39. a at 0xbf59f110

x = 38. a at 0xbf57f0f0

段錯誤 (核心已轉儲)

2.輸入引數如 20

x = 20.  a at 0xbfb0c910

x = 19. a at 0xbfaec8f0

x = 18. a at 0xbfacc8d0

x = 17. a at 0xbfaac8b0

x = 16. a at 0xbfa8c890

x = 15. a at 0xbfa6c870

x = 14. a at 0xbfa4c850

x = 13. a at 0xbfa2c830

x = 12. a at 0xbfa0c810

x = 11. a at 0xbf9ec7f0

x = 10. a at 0xbf9cc7d0

x = 9. a at 0xbf9ac7b0

x = 8. a at 0xbf98c790

x = 7. a at 0xbf96c770

x = 6. a at 0xbf94c750

x = 5. a at 0xbf92c730

x = 4. a at 0xbf90c710

x = 3. a at 0xbf8ec6f0

x = 2. a at 0xbf8cc6d0

x = 1. a at 0xbf8ac6b0

x = 20. recurse(x) = -20

3.詳細解釋該程式可用來估算棧的大小,如在不帶引數的例子中我們可以看到棧內只能分配100-38+1=63個函式recurse的棧幀每個recurse的楨都分配20020h個位元組,在分配到第64個時棧的空間不足,造成棧溢位。

知識點

下面的是通用的棧幀結構

乙個c過程的大致結構如下:

-準備階段

·形成幀底: push指令和mov指令

·生成棧幀(如果需要的話) : sub指令或and指令

·儲存現場(如果有被呼叫者儲存暫存器) : mov指令

-過程(函式)體

·分配區域性變數空間,並賦值

·具體處理邏輯,如果遇到函式呼叫時

-準備引數:將實參送棧幀入口引數處

-call指令:儲存返回位址並轉被呼叫函式

·在eax中準備返回引數

-結束階段

下面例舉乙個簡單的遞迴函式

從這個例子中我們可以看到在每次呼叫sum()後都會形成乙個新的幀,會大量消耗棧空間,所以,雖然運用遞迴對我們來說很方便,但它實際上非常浪費空間,能運用for,while,do-while等循壞結構的情況下,最好不要遞迴。

學習日誌之雜記

今天通過對petium 4的vhd檔案工程進行debug主要發現了如下幾個問題 在carry generator生成進製的邏輯上有問題。在電路中a n b n 為輸入引腳,經過生成了第一層的p和g,其公式如下 然後再經過另乙個結構生成以後的p和g公式為下 在寫carry generator的時候注意...

運維中被低估的日誌

如果把運維看做是醫生給病人看病,則日誌就是病人對自己的陳述,很多時候醫生需要通過對病人的描述中得出病人狀況,是否嚴重,需要什麼計量的藥,什麼型別的藥。所以古人有句話叫對症下藥,這個症就是病人的描述加醫生的判斷,在重一點的病在加上很多的化驗。在醫生看病時病人的描述和化驗單上的資料對醫生是非常重要的。同...

mysql學習 日誌系統 sql更新語句的執行過程

前言 對於更新語句來說,流程是和查詢語句是一樣的,同樣要經過聯結器,分析器,優化器,執行器。mysql update t set c c 1where id 2 不一樣的是,更新流程還涉及到兩個日誌模組 walwal 的全稱是 write ahead logging,它的關鍵點就是先寫日誌,再寫磁碟...