问题
I want to obtain the absolute values of all the elements that are stored in a specific array (i'm using MC 68HC11)
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;
}
I did this in assembly, but i'm not getting what i want:
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:
LDX #ARRAY
LDY #ABSOLUTE
SIGNED LDD 0,X
BMI NEGATIVE_NUMBER
LOOP STD 0,Y
INX
INX
INY
INY
CPY #(ABSOLUTE+6-1)
BLS SIGNED
BRA END
NEGATIVE_NUMBER CMPB #0
BEQ 2S_COMPLEMENT
NEGB
COMA
BRA LOOP
2S_COMPLEMENT NEGA
BRA LOOP
END BRA END
ARRAY DW 4,144,447,-14,-555,-1147
ORG RESET
DW Start
I want to store inside ABSOLUTE all the absolute elements from ARRAY
I would like to see these values inside ABSOLUTE:
4,144,447,14,555,1147 (UNSIGNED NUMBERS)
来源:https://stackoverflow.com/questions/62494971/absolute-values-assembly