英語翻譯拉丁語只是確保可以動作,但效率欠好。
括號內的,和上一個指令有關。
無前提跳越直接可以翻成 goto Label;
好在只是在Windows上摹擬,先可以過再說。還有一堆的問題還要解決啊!
做完了才覺察是完成這個動作。
long atol (const char * Str)
{
register char *a0=(char *)Str;
register long d2=0;
register int d0=0;
register int d1=0;
register int a1=0;
White:
d1 = *a0++;
if( d1 == ' ') goto White;
if( d1 > 13 ) goto Sign;
if( d1 >= 9 ) goto White;
Sign:
if( d1 == 43 ) goto Nextc;
if( d1 != 45 ) goto Digit;
d2 = 1;
Nextc:
d1 = *a0++;
Digit:
d1 -= 48;
if( d1 == 0) goto Nextc;
if( d1 < 0 ) goto Return;
if( d1 > 9 ) goto Return;
Loop:
d0 += d1;
d1 = *a0++;
d1 -= 48;
if( d1 < 0 ) goto Done;
if( d1 > 9 ) goto Done;
d0 += d0;
a1 = d0;
d0 = d0 << 2;
d0 += a1;
goto Loop;
Done:
if( d2 == 0 ) goto Return;
d0 = -d0;
Return:
return d0;
}
Bee不去向理程式構造的轉換,所以只要把標記(Label)直接轉成C的標記。
上個指令不是比較指令,就將有影響的暫存器放入括號內翻譯
XDEF _atol
?type 260翻譯社x,'atol',0,1,14336,20,1,259,0
?f_x_d 'atol',12,260
_atol:
?v_a_d 'Str',4,259
?v_l_d 'a0'翻譯社0,a0,261
?v_l_d 'd2',0翻譯社d1翻譯社20
?v_l_d 'd0',0,d3,16
?v_l_d 'd1',0翻譯社d2翻譯社16
?v_l_d 'a1',0,d4,16
?line 21翻譯社30
lea.l -12(sp),sp
movem.l d2/d3/d4,(sp)
moveq #0,d0
?line 74,33
movea.l 16(sp),a0
?line 75,23
moveq #0,d1
?line 76翻譯社23
moveq #0,d3
?line 77,23
moveq #0,d2
?line 78翻譯社23
moveq #0,d4
?line 80翻譯社14
L1:
move.b (a0)+,d2
extb.l d2
?line 81,17
moveq #32翻譯社d0
cmp.l d2,d0
beq.s L1
?line 82,15
moveq #13,d0
cmp.l d2,d0
blt.s L4
?line 83,15
moveq #9,d0
cmp.l d2,d0
ble.s L1
?line 85,16
L4:
moveq #43翻譯社d0
cmp.l d2,d0
beq.s L7
?line 86翻譯社16
moveq #45,d0
cmp.l d2翻譯社d0
bne.s L9
?line 87翻譯社10
moveq #1,d1
?line 89,14
L7:
move.b (a0)+翻譯社d2
extb.l d2
?line 91,12
L9:
moveq #-48,d0
add.l d0,d2
?line 92翻譯社15
beq.s L7
?line 93,14
tst.l d2
bmi.s L12
?line 94翻譯社14
moveq #9,d0
cmp.l d2,d0
blt.s L12
?line 96,12
L14:
add.l d2,d3
?line 97,14
move.b (a0)+,d2
extb.l d2
?line 98,12
moveq #-48,d0
add.l d0,d2
?line 99,14
bmi.s L16
?line 100,14
moveq #9,d0
cmp.l d2,d0
blt.s L16
?line 101翻譯社12
add.l d3,d3
?line 102翻譯社11
move.l d3,d4
?line 103,16
lsl.l #2,d3
?line 104翻譯社12
add.l d4,d3
?line 105翻譯社13
bra.s L14
?line 107,15
L16:
tst.l d1
beq.s L12
?line 108,12
neg.l d3
?line 110翻譯社13
L12:
move.l d3,d0
?line 111,1
movem.l (sp),d2/d3/d4
lea.l 12(sp),sp
rts
; code: 124 bytes stack: 12 bytes
?end
發生的狀態是:
上個指令是比力指令,就直接移進括號內。
有些和系統及功課系統相幹的組合說話,因為在Windows下有另外一套函式取代,所以不轉移。
可是Bee完成了如許的事!
問題是它是100%的組合說話,本想改寫,後來就寫成另一個樣子翻譯
這是新改函式產生出來的組合說話檔
有的則是利用內嵌組合語言的,因為和處理器設定有關的,則是操縱條件編譯的方式跳掉翻譯
可以看看翻出來的組合說話,多出了很多動作。
大部門組合語言可以轉成單行的C語言翻譯
改寫為
Bee在做分歧平台間的移植功課。
一路就做完了,也沒有問題。
來曆是68K的系統,目的系統未便明說翻譯
比較有問題的是程式控制指令。
原始函式為:
並且在寫的過程當中發現轉換的方式翻譯
為了便利移植工作順利,先移到Windows平台做摹擬驗證動作。
所得答案是:沒有這類方式。
一路修改所有組合說話相幹的程式。直到最後一個...
獨一要處理的是if括號內的器材翻譯
這是在一個不知不覺下完成的一個工作翻譯
沒想到就如許完成了一個網路找不到謎底的問題。
經比對轉出的組合說話動作契合。然後也能夠在Windows系統下順利編譯。
long atol (const char * Str)
{
asm (" move.l `Str`,a0 ; Address of String");
asm (" move.l d2,-(sp) ; Save D2");
asm (" moveq #0翻譯社d0 ; Initialize sum to 0 in D0");
asm (" moveq.l #0,d1");
asm (" moveq #0,d2 ; Assume positive number");
asm (" move.l d0翻譯社a1");
asm ("white:");
asm (" move.b (a0)+,d1 ; Get one char into D1");
asm (" cmpi.l #32,d1 ; Skip leading white spaces");
asm (" beq white");
asm (" cmpi.l #13,d1 ; White space include HT翻譯社LF,VT翻譯社FF翻譯社CR");
asm (" bgt.s sign");
asm (" cmpi.l #9,d1 ; Is it >= tab ?");
asm (" bge white");
asm ("sign:");
asm (" cmpi.l #43,d1 ; Is there a (+) sign ?");
asm (" beq.s nextc ; Skip to the next char");
asm (" cmpi.l #45翻譯社d1 ; Is it negative ?");
asm (" bne.s digit ; No, start to check for digits");
asm (" moveq #1,d2 ; Remember the number is negative");
asm ("nextc:");
asm (" move.b (a0)+翻譯社d1 ; Get next char");
asm ("digit: ; Find the first non-zero digit");
asm (" subi.l #48翻譯社d1 ; Integer value of this digit");
asm (" beq nextc ; Skip leading zeros");
asm (" bcs.s return ; Value is 0, return");
asm (" cmpi.l #9,d1 ; Test for valid digits");
asm (" bgt.s return ; Value is 0, return");
asm ("loop:");
asm (" add.l d1翻譯社d0 ; Add value of this digit to sum");
asm (" move.b (a0)+,d1 ; Next char");
asm (" subi.l #48,d1 ; Integer value of this digit");
asm (" bcs.s done ; No more digits");
asm (" cmpi.l #9翻譯社d1 ; Test for valid digits");
asm (" bgt.s done");
asm (" ; multiply value in D0 by 10 using shifts and add");
asm (" add.l d0,d0 ; Sum * 2");
asm (" move.l d0翻譯社a1 ; Save a copy in A1");
asm (" lsl.l #2翻譯社d0 ; Sum * 8");
asm (" add.l a1,d0 ; Sum * 10");
asm (" bra loop");
asm ("done:");
asm (" tst.b d2 ; Is the number negative ?");
asm (" beq.s return");
asm (" neg.l d0");
asm ("return:");
asm (" move.l (sp)+,d2 ; Restore D2");
}
做法很簡單,就直接轉成 if() goto Label;
最後一個函式是atol(),這是標準C的函式庫,但原系統就不用標準C的函式庫,而是用一個手寫函式。
寫完後無聊,用Google找找看有沒有組合說話轉成C說話相幹的事。
以下文章來自: https://blog.xuite.net/wallace_tsou/twblog/116635801-%E7%B5%84%E5%90%88%E8%AA%9E%E8%A8%80%E8%BD%89%E有關各國語文翻譯公證的問題歡迎諮詢天成翻譯公司02-77260931
- Nov 06 Tue 2018 05:37
組合語言轉成C說話 @ 統統都是半路落發
文章標籤
全站熱搜
留言列表
發表留言