c_asm01.asm
来自「伟福 WAVE6000 环境下MCS51 C51调用汇编例程」· 汇编 代码 · 共 76 行
ASM
76 行
;ASM程序
public readbyte ; 函数定义为全局
public readword
public ?readbyte?byte ; 函数调用时的参数
public ?readword?byte ;
public mydata ; 在汇编代码中定义数据
extrn code(t0int) ; 外部程序模块,在C语言定义
extrn data(g_char) ; 内部RAM的全局变量
extrn data(g_int) ;
extrn data(counter) ;
extrn xdata(gx_char) ; 外部RAM的全局变量
extrn xdata(gx_int) ;
bytes segment data ; 定义数据段
proc segment code ; 定义代码段
rseg bytes
?readbyte?byte:
?readword?byte:
ds 8 ; 参数预留空间
cseg at 000bh ; 定义绝对地址程序
LJMP int_t0 ; 定时中断0
rseg proc
readbyte: ; 返回值 = 传入值 + g_char + 1
mov a,?readbyte?byte ; 传入的单字节数据
add a,g_char ; 加上全局变量
inc a ; 返回字节型数据的
; 值存在ACC中
ret
readword: ; 返回值 = 传入值 + 1 + g_int + gx_int
mov b,?readword?byte ; 传入的双字节数据高位
mov a,?readword?byte+1 ; 传入的双字节数据低位
inc a ; 双字节加1
cjne a,#00, rw_nn
inc b
rw_nn: ;
add a, g_int+1 ; 加上变量 g_int 低字节
xch a,b
addc a, g_int ; 加 g_int 高字节
mov r6,a
mov r7,b
mov dpl, #low(gx_int) ; gx_int的地址
mov dph, #high(gx_int) ;
movx a,@dptr ; 读取 gx_int 的高字节
mov r5,a ; 暂存到R5
inc dptr
movx a, @dptr ; 读取 gx_int 的低字节
add a,r7
mov r7,a ; 返回的双字节数据低位
mov a,r5
addc a,r6
mov r6,a ; 返回的双字节数据高位
ret
int_t0:
lcall t0int ; 调用C语言程序模块
reti
cseg at 2000h
mydata:
db 1,2,3,4,5,6,7,8,9,0
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?