68000 彙編/標籤
外觀
< 68000 彙編
標籤只是行的名稱。您可以擁有任意數量的標籤。通常,您只需要在少數地方引用它們,例如函式的起始點、迴圈的開始和結束以及某些資料儲存位置。
彙編器將標籤視為數字的別名。當它遇到一個標籤時,它會將當前的 PC 值分配給它。(我將稱之為“宣告”標籤。)然後,該標籤可以在任何使用數字的地方用作運算元。它們通常用於 Jcc 或 Bcc 指令。
請注意,您可以在標籤實際宣告之前引用它們。這被稱為 *向前引用*,具體處理方式取決於彙編器。通常,它只是使用一個已知的安全值(如當前 PC),標記該位置,並在第二次遍歷時替換實際值。這可能會改變標籤的大小,在這種情況下需要進行第三次遍歷,依此類推。一些彙編器要求您顯式定義跳轉/分支的大小,以避免進行第三次遍歷。您使用的彙編器可能具有不同的行為。
標籤和儲存空間
MYDATA: ds.b 16 ; Declare 16 bytes of space, MYDATA label refers to this location. global Main ; Inform assembler that the Main label should be exported (made visible to code not in this file) Main: ; Label for the main function MOVEA.L #MYDATA, A0 ; Set address register A0 to refer to MYDATA space MOVE.B #0, 0(A0) ; Copy 0 into the first byte of MYDATA MOVE.B #1, 1(A0) ; Copy 1 into the second byte of MYDATA rts ; Return