Absolute values (assembly)

荒凉一梦 提交于 2020-06-28 06:44:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!