68HC11组装(第一步)-排序 [英] 68hc11 assembly (first steps) - sorting
问题描述
我只是爱上了这种特殊的微控制器, 68hc11 具有令人惊叹的体系结构.
我不是专家,但是我想改进,组装有点困难,但是我想对这个微控制器进行编程.
此汇编代码将从$ 100开始执行,将以$ 800分配一个200字节的数组,并将使用值200、199,…1.(降序)初始化该数组.
Vreset equ $FFFE
RAM equ $800
ROM equ $100
ARRAY_SIZE equ 200
org RAM
array rmb ARRAY_SIZE
org ROM
Start ldx #array
ldaa #ARRAY_SIZE
Loop staa ,x
inx
deca
bne Loop
bra *
org Vreset
dw Start
我想从给定的数组中获得两个最大值. 想要创建一个数组,给出10个值(存储在数组中),然后 最终获得两个最高值:
示例:
该数组可能包含以下值:
5 7 9 96 57 58 1 5 6 9
我想获得以下输出:
96 58
可以帮助我做到这一点吗?我有点迷路了:/
68HC11是一种经典的MCU架构,在许多大学中(也许在某种程度上仍是这样).
从官方上讲,这是生命周期的尽头.但是,由于势头强劲,许多人仍在积极地通过FPGA中加载的IP等价物或Tekmos等公司的克隆品来积极使用它.
要创建数组,请使用与显示的代码相似的代码.我的示例在ROM中使用常量数组.
对于您的问题,找到两个最大值,有许多可能的解决方案.这只是让您入门的一种:
Vreset equ $FFFE
ROM equ $100
org ROM
array fcb 5,7,9,96,57,58,1,5,6,9
;ARRAY_SIZE equ *-array
Start ldx #array ;X -> array
ldaa ,x ;let A keep the 1st maximum (assume 1st element)
clrb ;let B keep the 2nd maximum (assume zero)
Loop inx ;X -> next array element
cpx #array+::array ;(ASM11 idiom, ::array = 10 i.e., number of elements)
; cpx #array+ARRAY_SIZE ;(alternative for most assemblers)
bhs Done ;if past the array end, done
cmpa ,x ;compare with current array element
bhi DoB ;if already 1st maximum, skip
tab ;update 2nd maximum with previous 1st
ldaa ,x ;else A = new maximum
bra Cont
; bra Loop ;(optimization of previous line)
DoB cmpb ,x
bhi Cont ;if already 2nd maximum, skip
; bhi Loop ;(optimization of previous line)
ldab ,x ;else B = new maximum <= A
Cont bra Loop ;repeat for all array elements
Done bra * ;A = 1st maximum, B = 2nd maximum <= A
org Vreset
dw Start
I just fell in love with this particular microcontroller, 68hc11 has an amazing architecture.
I'm not an expert but i want to improve, assembly is kinda hard but i want to program this microcontroller.
This assembly code will execute from $100, will allocate a 200-byte array at $800, and will initialize that array with the values 200, 199, … 1. (descending order).
Vreset equ $FFFE
RAM equ $800
ROM equ $100
ARRAY_SIZE equ 200
org RAM
array rmb ARRAY_SIZE
org ROM
Start ldx #array
ldaa #ARRAY_SIZE
Loop staa ,x
inx
deca
bne Loop
bra *
org Vreset
dw Start
I want to get the two highest values from a given array.. i mean, i want to create an array, give 10 values (stored inside an array) and finally obtain the two highest values:
Example:
the array may contain these values:
5 7 9 96 57 58 1 5 6 9
I would like to obtain this output:
96 58
Can help me to do this? I'm kinda lost :/
The 68HC11 is a classic MCU architecture that was (and possibly still is, to some extent) taught in many universities.
Officially, it is end-of-life. But, due to momentum, many people are still actively using it either by IP equivalents loaded in FPGAs, or clones from companies such as Tekmos.
To create the array, use code similar to what you showed. My example uses constant array in ROM.
As to your question finding the two highest values, there are many possible solutions. Here's just one to get you started:
Vreset equ $FFFE
ROM equ $100
org ROM
array fcb 5,7,9,96,57,58,1,5,6,9
;ARRAY_SIZE equ *-array
Start ldx #array ;X -> array
ldaa ,x ;let A keep the 1st maximum (assume 1st element)
clrb ;let B keep the 2nd maximum (assume zero)
Loop inx ;X -> next array element
cpx #array+::array ;(ASM11 idiom, ::array = 10 i.e., number of elements)
; cpx #array+ARRAY_SIZE ;(alternative for most assemblers)
bhs Done ;if past the array end, done
cmpa ,x ;compare with current array element
bhi DoB ;if already 1st maximum, skip
tab ;update 2nd maximum with previous 1st
ldaa ,x ;else A = new maximum
bra Cont
; bra Loop ;(optimization of previous line)
DoB cmpb ,x
bhi Cont ;if already 2nd maximum, skip
; bhi Loop ;(optimization of previous line)
ldab ,x ;else B = new maximum <= A
Cont bra Loop ;repeat for all array elements
Done bra * ;A = 1st maximum, B = 2nd maximum <= A
org Vreset
dw Start
这篇关于68HC11组装(第一步)-排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!