简体   繁体   English

汇编程序的正确模板

[英]Correct Template for an Assembly Program

I have just started off with assembly and was looking at some sample programs shared by the instructor, for example, the below program to swap 2 numbers. 我刚开始组装时,正在查看教师共享的一些示例程序,例如,下面的程序交换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

Kindly help in resolving my questions (as code comments) about this template 请帮助解决有关此模板的问题(作为代码注释)


Edit 编辑

The issue with label_name EQU const_value seems to be something else, I am getting a syntax error no matter where I place the line label_name EQU const_value的问题似乎是其他问题,无论将行放置在何处,我都会遇到语法错误

first instruction at add 0 ; 第一条指令加0; But does this have to be the first statement? 但这必须是第一个陈述吗?

Probably not, but it makes the file simpler to understand. 可能不是,但这会使文件更易于理解。 Real world code would probably start with some include statements to load macros. 现实世界的代码可能会以一些include语句开始以加载宏。 But that is beyond scope in a beginner lesson. 但这超出了初学者的学习范围。

The code if for the 8051 which has a total RAM range ; 如果代码为8051,它具有总RAM范围; of 256B, so this address seems out of range 256B,因此此地址似乎超出范围

RAM != ROM The 8051 is a havard machine and executes instructions only from program memory, which is read-only (mostly read only in case of flash variants). RAM!= ROM 8051是一台哈佛机器,仅从程序存储器中执行指令,该程序存储器是只读的(大多数情况下仅在Flash变体的情况下是只读的)。 It cannot execute code from RAM. 它无法从RAM执行代码。 Most 8051 have a few KB ROM or more. 大多数8051具有几个KB ROM或更多。

You need the jump to address 100h because of the interrupt table. 由于中断表,您需要跳转到地址100h。 You will get to this in a future lesson. 您将在以后的课程中了解这一点。

HERE:SJMP HERE ; HERE:SJMP HERE What is the purpose of this line? 这条线的目的是什么?

There is no magic "stop" instruction, but a jump to the address of the current instruction has a very similar effect of halting the program flow. 没有神奇的“停止”指令,但是跳转到当前指令的地址具有与停止程序流非常相似的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM