簡體   English   中英

匯編程序的正確模板

[英]Correct Template for an Assembly Program

我剛開始組裝時,正在查看教師共享的一些示例程序,例如,下面的程序交換2個數字。

ORG 0h
; This line tells the MCR to place the first instruction at add 0
; But does this have to be the first statement? I tried writing the line
; 'num1 EQU #20h' before org, but this was throwing an error

LJMP main
; This line transfers the control to the main block unconditionally
ORG 100h
; Why do we need this? The code if for the 8051 which has a total RAM range 
; of 256B, so this address seems out of range 
main:
    MOV 70H,#20H
    MOV 71H,#21H

    MOV A,70H
    MOV 70H,71H
    MOV 71H,A
    ; The accumulator A acts like a temp in a simple C program

    HERE:SJMP HERE
    ; What is the purpose of this line?
END

請幫助解決有關此模板的問題(作為代碼注釋)


編輯

label_name EQU const_value的問題似乎是其他問題,無論將行放置在何處,我都會遇到語法錯誤

第一條指令加0; 但這必須是第一個陳述嗎?

可能不是,但這會使文件更易於理解。 現實世界的代碼可能會以一些include語句開始以加載宏。 但這超出了初學者的學習范圍。

如果代碼為8051,它具有總RAM范圍; 256B,因此此地址似乎超出范圍

RAM!= ROM 8051是一台哈佛機器,僅從程序存儲器中執行指令,該程序存儲器是只讀的(大多數情況下僅在Flash變體的情況下是只讀的)。 它無法從RAM執行代碼。 大多數8051具有幾個KB ROM或更多。

由於中斷表,您需要跳轉到地址100h。 您將在以后的課程中了解這一點。

HERE:SJMP HERE 這條線的目的是什么?

沒有神奇的“停止”指令,但是跳轉到當前指令的地址具有與停止程序流非常相似的效果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM