装配程序的正确模板

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 的问题似乎是另外一回事,无论我把行放在哪里,我都会收到语法错误

first instruction at add 0 ; But does this have to be the first statement?

可能不是,但它使文件更易于理解。真实世界的代码可能会以一些 include 语句开始以加载宏。但这超出了初学者课程的范围。

The code if for the 8051 which has a total RAM range ; of 256B, so this address seems out of range

RAM != ROM 8051 是一种哈佛机器,仅从程序存储器执行指令,程序存储器是只读的(在闪存变体的情况下,大多数是只读的)。它不能从 RAM 中执行代码。大多数 8051 有几 KB ROM 或更多。

由于中断 table,您需要跳转到地址 100h。您将在以后的课程中了解这一点。

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

没有神奇的 "stop" 指令,但是跳转到当前指令的地址与停止程序流具有非常相似的效果。