问题
I'm new to assembly language and everything seems a little complicated.
I'm programming an old MCU (68hc11), I'm trying to migrate from C language to assembly code using the 68hc11 instructions.
I want to solve 2 different situations:
FIRST CASE
I want to write a program in assembly that counts the number of POSITIVE, NEGATIVE, and ZERO values that exist inside a given array. DO NOTE that all values inside ARRAY could be all positive or all negative or all zeros,do you get me? So I should define the size of the variables that will store the quantity properly.
NOTE: The end of the array is: ARRAY+QUANTITY-1
Array: contains some random values
QUANTITY: represent the highest number of elements that the ARRAY can hold
I wrote this program in C:
int A[15], pos, neg, nul, i;
[...]
pos = 0;
neg = 0;
nul = 0;
for (i = 0; i < 15; i++) {
if (A[i] > 0) {
pos++;
}
if (A[i] < 0) {
neg++;
}
if (A[i] == 0) {
nul++;
}
}
Now, I want to translate that but in assembly (I GOT STUCK IN HERE)
RWM EQU $0
ROM EQU $C000
VRESET EQU $FFFE
QUANTITY EQU 800 ;MEANS THE MAXIMUM AMOUNT OF VALUES THAT THE ARRAY WILL CONTAIN
ORG RWM
POSITIVE RMB 2
NEGATIVE RMB 2
ZEROS RMB 2
ORG ROM
START:
END BRA END
ARRAY DW 78,554,-44,-4,2547,0,-3,0,1,7,8,
ORG VRESET
DW START
------------------------------------------------------------------------------------------------------
SECOND CASE
I want to obtain the absolute values of all the elements that are stored in a specific array.
ABSOLUTE will contain the absolute values of the elements stored in ARRAY (the size of ABSOLUTE must be related to the amount of elements inside ARRAY)
In C it looks like this:
#include <stdio.h>
#define SIZE 16
int absolute(int array[], int ray[], int N)
{
for (int i=0; i<N; i++)
ray[i] = array[i] * (array[i]<0?-1:1);
}
int main()
{
int array[SIZE] = {0,1,2,3,-4,5,6,7,-8,9,-10,11,12,13,14,20};
int ray[SIZE];
absolute(array,ray,SIZE);
for (int i = 0; i < SIZE; i++ )
printf("The absolute value of %3i is %3i\n", array[i],ray[i]);
return 0;
}
Assembly should look like this (i got stuck in here)
RWM EQU $0
ROM EQU $C000
RESET EQU $FFFE
ORG RWM
ABSOLUTE RMB ;i must dfine a size depending on the amount of elements inside ARRAY
ORG ROM
Start:
END BRA END
ARRAY DW 4,144,447,-14,-555,-1147
ORG RESET
DW Start
Can help me to make it work using the corresponding HC11 instructions?.
PS: I use these instructions: INSTRUCTIONS
来源:https://stackoverflow.com/questions/62337005/assembly-language-arrays