为什么在用单片机汇编编程时,开头都要写上 ORG 0000H LJMP MAIN ORG 0030H这些?

ORG是伪指令,告诉编译器,程序从ROM的0000开始存放程序,但是LJMP MAIN是一条无条件跳转指令,也就是说,单片机上电之后首先从0000处开始执行程序,但是,AJMP直接将程序跳转到MAIN标号指向的存储区域开始取指令,并执行,而一般MAIN标号是放在语句ORG 0030之后的,也即,主程序是从0030这个地址开始存放的;

这是因为,单片机内部有几个中断源,默认内部中断(包含几个定时器中断,还有外部中断)的入口是在0000-0030之间的,每个中断大概占用两个字节还是四个字节,记不清楚了。而这些内部中断一旦产生,指针必然立刻指向0004-0030之间,如果你的程序有语句放在这个地址内,程序必然跑飞!!!

因此,在8051这个MCU的设计中,已经将0004-0030分配给内部使用了,所以,你的程序只能从0030之后的任何存储区域开始存放,AJMP MAIN就是为了在MCU上电的时候知道从ROM中的那个地址开始取指令

而如果你使用到中断,也必然要在已经定义为中断入口的地址0004--0030写上AJMP,以便于跳转到你自己编写的相应的中断程序中

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是一小部分代码 请参考 org 0000h jmp start ;Start of the program org 0100h start: mov A,#030h ;1 line, 8 bits call wrcmd mov A,#LCD_SETVISIBLE + 4 call wrcmd mov A,#LCD_SETDDADDR+15 ; Start at right hand side of the display call wrcmd mov A,#LCD_SETMODE + 3 ; Automatic Increment - Display shift left. call wrcmd mov 025h,#00h ; Set output mode (floating point). call boundsbuffer ; Initialise the bounds buffer - used for error checking. mov mode,#4 ; Initialise the constant buffer to 100. Primarily used for % ops. mov digitcode,#031h call storedigit mov digitcode,#030h call storedigit mov digitcode,#030h call storedigit mov status,#00h ; variable used to determine the first key press after an operation. mov bufferctr,#00h mov opcounter,#00h mov decimalcnt,#00h call waitkey halt: mov PCON,#1 ;Halt ;*********************************************************** ;**** Floating Point Package **** ;******************************** $INCLUDE (FP52.ASM) ;Routine to peek arg at DPTR argout: mov R0,#FP_NUMBER_SIZE aoloop: movx A,@DPTR anl A,#0F0h rr a rr a rr a rr a add A,#aodata-$-3 movc A,@A+PC call sndchr movx A,@DPTR anl A,#0Fh add A,#aodata-$-3 movc A,@A+PC call sndchr inc DPTR djnz R0, aoloop ret aodata: db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' ;Routine to output character in A, preserving all but A. sndchr: push R0B0 push R1B0 call getmode mov digitcode,A call storedigit pop R1B0 pop R0B0 ret ;Routine to print error message at DPTR. prterr: jmp wrstr ;Routine to handle input parameter error. badprm: mov DPTR,#bpmsg jmp wrstr bpmsg: db 'Bad Parameter',0 ;*********************************************************** ;**** LCD Display Routines **** ;****************************** ;LCD Registers addresses LCD_CMD_WR equ 00h LCD_DATA_WR equ 01h LCD_BUSY_RD equ 02h LCD_DATA_RD equ 03h LCD_PAGE equ 80h ;LCD Commands LCD_CLS equ 1 LCD_HOME equ 2 LCD_SETMODE equ 4 LCD_SETVISIBLE equ 8 LCD_SHIFT equ 16 LCD_SETFUNCTION equ 32 LCD_SETCGADDR equ 64 LCD_SETDDADDR equ 128
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值