"你不斷講 native 咁行, 其實一個 app, 有幾多地方係直接 cpu instruction? "

Compile出黎既Application係pure cpu instruction黎架....sighs
你係唔係講緊.net?
如果Microsoft Office/同C++/Win32 API, 出黎既.exe/.dll入面係pure CPU native code...
請問你有冇寫過C++架?

TOP

本帖最後由 Super169 於 2014-1-10 18:17 編輯

回復 31# goshigoo

你只係講到 c++ 咋, 幾驚你問我 assembly 甚至 micro-programming, 呢 d 就真係無掂好多年了.

既然你對 c 有認識, 咁就易講 D 喇, 用番 c 講.   唔知你對 c compile 出黎既 program, 同佢點樣在 os execute, 又知道有幾多呢?  真係 native 比 cpu 行?

你有咁既諗法, 可能你只係做過 d console 既 program, 計下數 print 番個 result 出黎呢類功課.  或者係因為 compile 出黎既 binary 好多時會叫做 machine code.   令你以為成個都係純 cpu instruction.

windows 比較複雜, 先用比較簡單既 dos 去睇, 當一個簡單既 console in/out.

你用 c 寫句 printf 去 display 一個 character, 你估背後會 compile 出乜?
真係一個直接可以在 cpu 行既 instruction?  就算寫 assembly, 好多野都唔係直接 instruction, 都係經番一 d dos 既 interrupt 去做.  int 21 就係 dos 包裝左既 int 了.  定係你諗住佢會 gen code 直接 update display map? (Coding level 我最盡就係做到呢步, 完全 bypass OS. 最後點轉化成畫面既顯示, 就係 hw level 既野了.  我唔知家陣係咪可以寫野落 display card control 佢出 monitor. 如果你識得 coding level control hardware 出 display 既做法, 我都想請教一下.  不過, 我相信 office 呢類野唔會咁做, 肯定係經 api 出.)

由 windows 去就更長遠, 要 display 一個 character,  對 cpu 黎講係無意義既, 當中要經 windows / bios 內部去處理, 轉化成對 hd 既 code.  而你 compile 出黎果個, 只係比 windows 行到既 "machine code".  雖然 比 .net 既 IL 更低 level, 但都未去到完全 native 比 cpu 行既 code, 當中仲有大把 OS level 既 call.

另一個簡單D講, 一句 malloc, 你估佢係問 cpu 攞 memory 定係問 os 攞 memory?  

以上只係簡單既兩個 function, 我諗你唔會唔認識吧, 你認為佢地可唔可能 compile 出一段唔駛靠 os 純 cpu 行既 instruction?

你應該聽過 DLL 吧, 你寫 program 或者都會用到一 d 人地既 library, 你都應該知道,  compile 出黎既 code 唔係直接 native 行到哂喇 - 無左 d library 行到嗎?  再者, 就算你唔用人地既 library, 又或者個 DLL 都係你寫既, 你估 compile 完既 program 背後可唔可以唔需要用 windows 既 library?  

真係純 cpu intruction? 你估佢無左個 os 仲行到幾多?

就算你 command prompt 用 debug 直接入 code 寫 program, 都未必可以完全係 cpu 直接行既 instruction 喇, 何況 windows application.

如果你只係話佢行出黎唔會慢好多, 因為 overhead 唔太大, 都仲講得通.  但就唔係因為 gen 出黎既 program 成個係 native 既 cpu instuction 囉.

都係果句, 諗下 app, os, cpu 之間既關係吧.
除非你寫緊 BIOS 或者一d low level 既 driver, 否則都好難話 compile 出黎既成舊 cpu instruction (就算 driver 都可能 call 左好多其他野).

TOP

Ching攪錯咗Concept啦

C++ Application要Call DLL / API 唔等如Application啲code唔係CPU行

你講Console App原因係因為Console App自己self-contain; 你以為咁樣個application先係CPU行; 而Win32 application係行個OS 個virtual machine?

This is wrong concept

"你用 c 寫句 printf 去 display 一個 character, 你估背後會 compile 出乜?"

Application入面句printf咪就係直接係CPU行lor; 佢translate咗出黎既Machine code/assembly 會係
(實際assembly當然唔係咁, 但出咗黎係真係直接係CPU行到既code)
push "Hello World"
call "printf"

"printf"呢個function係另一個dll, 咁個CPU Instruction Pointer咪跳去printf個rountine行lor
個app同printf個C Library都已經pre-compile咗個x86 instructions



"真係純 cpu intruction? 你估佢無左個 os 仲行到幾多?"

個Application真係pure x86 native instructions; 但佢都要有Windows啲DLL先行到(Windows啲DLL都係x86 native instructions); 因為個Application Call緊DLL入面啲code

"都係果句, 諗下 app, os, cpu 之間既關係吧"
請ching睇多啲書先講啦...


如果.Net/Java就唔係Native code; 佢地係virtual machine上行
我估ching你睇API Stack時攪錯咗concept以為每一層都係virtual machine.....

TOP

64 bit

TOP

兩隻都裝過,其實冇乜分別

TOP

本帖最後由 Super169 於 2014-1-14 20:25 編輯

回復 33# goshigoo


或者我明白大家既分歧, 呢樣係我講錯了.

我想講既係佢有好多地方, 唔係 pure cpu intruction set 做, 係唔需要再經 OS 既功能自己做哂.  例只好簡得一個 mov command.  你無講錯, 雖然要依賴個 os, 佢既 command 都係 cpu instruction.  
但係有部份既 instruction 係要經 OS 去 implement, 對我黎講, 呢 D 唔算係純 cpu instruction (例如 int 21, 佢 call 果下係, 但個 inplementation 要靠 OS).  係我自己傻左, 見到 pure 既字, 成日諗住你講佢成個 implementation 唔需要其他野, 即係 gen 出黎既 code, 足夠獨立去行.  雖然 OS 既 code 都係 pure cpu instruction (如果唔係都唔行到), 我會睇成佢要依賴其他野, 唔係 pure 由佢 gen 出黎既 code 行哂.  就好似部機行到 javascript, 背後經左好多層, 最後都係 cpu instruction.  當然, 一個係直接用其他 library, 一個仲要先轉多幾次.  點都有分別.

我本想係想講因為佢地要依賴個 OS 既野, 當你要行一個 win32 既 app 時, 佢唔可以直接用番 windows pre-load 左既 library, WOW64 係要 load 番一套 dll 比佢, 模擬番個 win32 既 環境.......講講下我自己講到傻左.  係我衰左添.

TOP

回復  goshigoo
我本想係想講因為佢地要依賴個 OS 既野, 當你要行一個 win32 既 app 時, 佢唔可以直接用番 windows pre-load 左既 library, WOW64 係要 load 番一套 dll 比佢, 模擬番個 win32 既 環境.......講講下我自己講到傻左.
Super169 發表於 2014-1-14 20:22


我明白wow64要 load返32 bit dll
我一直只係想講呢啲32 bits既code係直接係CPU上行
同OSX Rosetta realtime 將PowerPC Code轉到x86 Code唔同

TOP