MAXQ架构的表操作

[09-13 17:04:17]   来源:http://www.88dzw.com  控制技术   阅读:8503

文章摘要:copyBuffer程序将每次表操作的周期数减至3个,比之前提到的方法节省了约一半时间。当从copyBuffer程序返回时,LC[0]清零,OFFS寄存器指向最近一次写目标地址的下一个位置。因为OFFS是一个8位寄存器,因此用这种方法可以拷贝多达256字的表。 实例:字符串输出在许多基于微控制器的应用中,通常都要将预存的消息输出到控制台。每条消息都指定了一个编号,必须由一个通用程序将该编号转换成消息文本。完成该任务通常采用每个消息字符串以0结尾的技术,同时提供一个表,以便将各消息编号转换成消息字符串的首地址。这项技术非常可靠和快速,但必须建立两个数据结构:地址表及字符串本身。另一项技术是简单地

MAXQ架构的表操作,标签:计算机控制技术,工厂电气控制技术,http://www.88dzw.com
copyBuffer程序将每次表操作的周期数减至3个,比之前提到的方法节省了约一半时间。当从copyBuffer程序返回时,LC[0]清零,OFFS寄存器指向最近一次写目标地址的下一个位置。因为OFFS是一个8位寄存器,因此用这种方法可以拷贝多达256字的表。

实例:字符串输出

在许多基于微控制器的应用中,通常都要将预存的消息输出到控制台。每条消息都指定了一个编号,必须由一个通用程序将该编号转换成消息文本。

完成该任务通常采用每个消息字符串以0结尾的技术,同时提供一个表,以便将各消息编号转换成消息字符串的首地址。这项技术非常可靠和快速,但必须建立两个数据结构:地址表及字符串本身。另一项技术是简单地将以0结尾的各字符串存入一个大的、毗邻的存储器空间,并采用线性查找。虽然该方法比较简单,但却是以花费大量执行时间为代价的,因为在输出之前,必须找到目标字符串里的每一个字符。

还有一种较好的折衷办法,即字符串采用按长度划界的方法取代以0划界的方法。采用这种技术,首先给出每个字符串的长度,然后紧接着是该消息的实际字节信息。这样一来,可以快速跳过不用的信息,并且该表的长度没有以0划定界限的长。这种折衷技术的局限性仅在于表中的每个字符串长度不能超过255个字符。
;
; Output String
;
; Enter with ACC=an index value (one based) indicating which
; string to output.
;
; On exit, LC0=0, DPC=0, ACC, A1, A2, DP0 used.
;
output_string:
	move	lc[0], acc		;Set LC0 to index of string
move	dpc, #4		;Set DP0 to word mode
move	dp[0], #800dh	;Point to table of pointers
move	acc, @dp[0]		;Get address of table
add	#3			;Offset to GETDP0 routine
move	dp[0], acc		;Load pointer to table
move	a[1], @dp[0]++	;Get GETDP0
move	a[2], @dp[0]	;Get GETDP0INC
move	dpc, #0		;Set DP0 to byte mode
move	dp[0], #string_table + 8000h

str_search_loop:
call	a[1]			;Get a string length
djnz	lc[0], next_str	;If not this string, go to next
move	lc[0], gr		;Otherwise, put len in LC0
move	acc, @dp[0]++	;...and point past length

out_loop:
call	a[2]			;Get a char and bump pointer
call	char_out		;Output the character
djnz	lc[0], out_loop	;If more characters, loop
ret				;Otherwise, we're done.

next_str:
move	acc, gr		;GR contains len of this string
add	dp[0]			;Add current ptr to current len...
move	dp[0], acc		;...to create a new pointer
jump	str_search_loop	;Jump back and test index again

;
; Each entry in the string table begins with the string length
; followed by the string characters.
;
string_table:
dc8	string1 - string_table
dc8	"This is the first string."
string1:
dc8	string2 - string1
dc8	"This is a second example of a string"
string2:
dc8	string3 - string2
dc8	"A third string."
string3:
dc8	string4 - string3
dc8	"Finally, a fourth string in the array!!!"
string4:

<-- END: DB HTML -->

上一页  [1] [2] [3] 


Tag:控制技术计算机控制技术,工厂电气控制技术控制技术