2012-07-11 204 views
1

我試圖理解這個代碼:smulwb彙編指令

inline SInt32 smul32by16(SInt32 i32, SInt16 i16) 
{ 
    register SInt32 r; 
    asm volatile("smulwb %0, %1, %2" : "=r"(r) : "r"(i32), "r"(i16)); 
    return r; 
} 

有誰知道這個彙編指令做什麼?

更新: P.S.我使用目標C,我應該理解來自程序集的一些代碼。這就是爲什麼我很難理解這個代碼。

+0

架構?臂? – 2012-07-11 12:21:42

+0

請看我的更新。我真的不知道,什麼是ARM。我只是分析蘋果示例代碼。我沒有裝配知識。 – 2012-07-11 12:23:30

+0

我問裏面的命令。 「smulwb%0,%1,%2」:「= r」(r):「r」(i32),「r」(i16) – 2012-07-11 12:25:53

回答

4

它由符號16位乘法符號32位和返回前32位的48位結果。 b指定使用第三個操作數的底部16位。通過使用asm你可以給彙編指令

int_48 temp; 
temp = i32*i16; 
result = temp >> 16; 
+0

非常感謝 – 2012-07-11 12:29:36

4

因此,將其轉化爲僞代碼。

,並使用volatile的原因,

volatile for the asm construct, to prevent GCC from deleting the asm statement as unused 

看到這個link更好地理解

命令裏面問指令是指:

SMULWB  R4, R5, R3  ; Multiplies R5 with the bottom halfword of R3, 
           ; extracts top 32 bits and writes to R4. 
+0

不,我只詢問命令「smulwb% 0,%1,%2「:」= r「(r):」r「(i32),」r「(i16) – 2012-07-11 12:27:17