[英]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.