📄 main.asm
字号:
;==================================================================================
; The information contained herein is the exclusive property of
; Sunplus Technology Co. And shall not be distributed, reproduced,
; or disclosed in whole in part without prior written permission.
; (C) COPYRIGHT 2004 SUNPLUS TECHNOLOGY CO.
; ALL RIGHTS RESERVED
; The entire notice above must be reproduced on all authorized copies.
;==================================================================================
;==================================================================================
; Project Name :
; Applied Body : SPMC65P2404A
; Firmware version:
; Programer :
; Date : 2004-8-30
; Description : This program presents an example that how to use stack.
;
; Hardware Connect:
; Link File :
; IDE Version : V1.6.5
; BODY Version : V1.0.0A
;=================================================================================
.SYNTAX 6502 ;process standard 6502 addressing syntax
.LINKLIST ;generate linklist information
.SYMBOLS ;generate symbolic debug information
;************************************************************************************
;* *
;* System Register Define *
;* *
;************************************************************************************
.INCLUDE SPMC65P2404A.inc ;Define all hardware,Registers and ports.
;************************************************************************************
;************************************************************************************
;* *
;* Data memory Define *
;* *
;************************************************************************************
.PAGE0 ;define values in the range from 00h to FFh
;************************************************************************************
.DATA ;define data storage section
;************************************************************************************
;* *
;* Program Area *
;* *
;************************************************************************************
.CODE
;************************************************************************************
;* *
;* Power on Reset Process *
;* *
;************************************************************************************
V_Reset:
sei ;Disable interrupt
ldx #C_STACK_BOTTOM ;Initial stack pointer at $01FF
txs ;Transfer to stack pointer
jsr F_Tim0_Init
cli ;Enable interrupt
?L_Main_Loop: ;the example for test
;==============================================================
;stack pointer is extended from $01FF to $01E0,when data pushed
;onto stack,stack pointer will decrease by 1,when data is poped
;from stack,stack pointer is increased by 1.stack has the
;property that the last item placed on the stack will be the
;first item removed(last in,first out).
;==============================================================
lda #$34
ldx #$90
pha ;Push A register,then sp<=sp-1.
txa
pha ;Push X register,then sp<=sp-1.
lda #$23
ldx #$44
pla ;\ first sp<=sp+1,then pop X register,the value
tax ;/ of X is #$90.
pla ;first sp<=sp+1,then pop A register,the value
;of A is #$34.
;==============================================================
;push and pop status register
;==============================================================
clc
php ;Push status register,then sp<=sp-1.
sec
plp ;first sp<=sp+1,then pop status register,the carry
;flag is "0".
;==============================================================
;when jump to a subprogram,stack is used for storing return
;address
;==============================================================
jsr F_1 ;before jump is performed,stack is used for storing
;return address:an address location where the
;instruction"jsr F_1" is held.first,push the high
;8bit address, then (sp<=sp-1);second,push the low
;8bit address,then (sp=sp-1).
jmp ?L_Main_Loop
;==============================================================
;when return from a subprogram,SP pop return address
;==============================================================
F_1:
nop ;for user
rts ;before the subprogram return,first sp<=sp-1,
;then SP pop the low 8bit address,second,
;sp=sp-1,then pop the high 8bit address
;====================================================================
; Function: F_Tim0_Init
; Description: Set 4ms interrupt in timer0
; Input: none
; Output: none
; Destroy: A
; Stacks: 1
;====================================================================
F_Tim0_Init:
lda #C_T08B_Timer ;Timer0 Function as 8 Bit Timer
sta P_TMR0_1_Ctrl0
lda #C_T0FCS_Div_128 ;DIV=1/128
sta P_TMR0_1_Ctrl1
lda #6 ;Preload counter= 166
sta P_TMR0_Preload ;8000000/128/250=250Hz=4ms
lda #C_INT_T0OIE
sta P_INT_Ctrl1 ;Timer0 overflow INT enable
lda #$FF
sta P_INT_Flag1
rts
;**********************************************************************************
;* *
;* Interrupt Vector Table *
;* *
;**********************************************************************************
;=================================================================
;when interrupt coming on,the return address and status register
;are pushed into stack.push the high 8bit address firstly,then
;(sp<=sp-1);push the low 8bit address secondly,then (sp=sp-1);
;push the status register thirdly,then (sp=sp-1).
;=================================================================
V_IRQ:
pha
txa ;Push A register,then sp<=sp-1.
pha ;Push X register,then sp<=sp-1.
lda P_INT_Flag1
and #C_INT_T0OIF ;4ms INT comming?
bne ?L_Timer0 ;yes
jmp L_IntExit
?L_Timer0:
nop ;for user
L_IntExit:
lda #C_INT_T0OIF
sta P_INT_Flag1
pla ;\ sp<=sp+1,then pop X register
tax ;/
pla ;sp<=sp+1,then Pop A register
rti ;before interrupt return,
;first sp<=sp-1,pop the status register;
;second sp<=sp-1,pop the low 8bit address;
;third sp<=sp-1, pop the high 8bit address.
V_NMI:
rti
VECTOR .SECTION
;*********************************************************************************
DW V_NMI ; may download program emulated either
DW V_Reset ; in internal memory or external memory
DW V_IRQ ; dw define two bytes interrupt vector
;**********************************************************************************
;* *
;* End of Interrupt Vector Table *
;* *
;**********************************************************************************
.END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -