79244

Assembly language (arrays)

<h3>Question</h3>

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.

<blockquote>

I want to solve 2 different situations:

</blockquote>

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

<blockquote>

Array: contains some random values

QUANTITY: represent the highest number of elements that the ARRAY can hold

</blockquote>

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 <h2>------------------------------------------------------------------------------------------------------</h2> <hr />

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

Recommend

  • Recommended hash function for overwriting NSObject's hash method
  • How to encode Java files in UTF-8 using Apache Ant?
  • JAXB: Empty string does not produce empty element
  • Bcrypt vs Hash in laravel
  • How to return only text after a comma in a string
  • Open StreetMap Reverse Geocoding
  • adding custom header with classic asp
  • Improve on a 13-parameter constructor
  • CSS Display One Character in 2 Colors [duplicate]
  • Create index on existing table Oracle
  • All I get is a blank page when I visit localhost:9080
  • How to read bytes from a device using c/c++ in windows
  • How to avoid “Merge branch 'master' of ssh://gdcm.git.sourceforge.net/gitroot/gdcm/gdcm”
  • Image is rotated 90 degrees when using clipToMask
  • Mapbox GL JS refresh layer
  • How to pass values to a Custom Resolver in Automapper?
  • Delphi MainFormOnTaskBar Modal windows bug
  • Firebase Cloud Messaging: how to send data message to all users? [duplicate]
  • how to change button text after succes in ajax
  • Javapackager tool from command-line on OSX?
  • Selenium can't locate iframe
  • Passing HTTP Post from AWS API GW to Lambda
  • VS2010: Ctrl-PgUp / -PgDown like in browsers
  • Filtering out choiceless polls in the Django tutorial causes polls in the index to duplicate
  • Using loops in Jasmine (with injected service)
  • How to implement Google Drive and Google Plus sdk in ios project
  • dmtracedump doesn't work, HELP!
  • Bundling python(“.py”)files along with java class files for a web application
  • Query regarding com.jcraft.jsch.JSchException: UnknownHostKey: x.y.com. DSA key fingerprint is “ac:e
  • separate tokens in batch file
  • What are advantages/disadvantages of using Selenium for Java vs .NET applications?
  • Query takes almost two seconds but matches only two rows - why isn't the index helping?
  • LINQ to populate treeview based upon grouping
  • Year over Year Stats from a Crossfilter Dataset
  • PHPMailer return to AJAX
  • Is there a better way for handling SpatialPolygons that cross the antimeridian (date line)?
  • Cloud Code: Creating a Parse.File from URL
  • How to integrate angular2-material (alpha 8.2) with angular2-Quickstart app
  • How to get rgb from transparent pixel in js
  • Sql - ON DUPLICATE KEY UPDATE