Create an assembly language program that will have two arrays, of five elements
ID: 3831237 • Letter: C
Question
Create an assembly language program that will have two arrays, of five elements each. Sum the corresponding elements in the two arrays together and store the result in one of the arrays. Do this for each element. In other words: a[0] = a[0] + b[0] a[1] = a[1] + b[1] etc. When this is complete, add all of the values in the array that contains the sums together, and store that value in memory. The values in each array should be: 1, 2, 3, 4, 5. The code that adds the two arrays together and then sums the elements together is to be in a separate sub - routine
Explanation / Answer
DATA SEGMENT is the starting point of the Data Segment in a Program and DATA is the name given to this segment and SEGMENT is the keyword for defining Segments, Where we can declare our variables.
Next Line – NUM1 DB 36H,55H,27H,42H
NUM2 DB 38H,41H,29H,39H
RESULT DB 5 DUP (0)
NUM1 DB 36H,55H,27H,42H and NUM2 DB 38H,41H,29H,39H this line is a declaration of 8-bit Numbers Array initialized with 36H,55H,27H,42H and 38H,41H,29H,39H the numbers are seperated by Comma (,). RESULT DB 5 DUP (0) is used to Save the Result of Array Addition which will save sum of each elements of a Array NUM1 and NUM2. DUP is used to Duplicate the value in the Bracket ahead.
Next Line – DATA ENDS
DATA ENDS is the End point of the Data Segment in a Program. We can write just ENDS But to differentiate the end of which segment it is of which we have to write the same name given to the Data Segment.
Now, Selection of data type is DB data type the numbers which we are adding will be integers so DB is sufficient.
DATA SEGMENT
NUM1 DB 36H,55H,27H,42H
NUM2 DB 38H,41H,29H,39H
RESULT DB 5 DUP (0)
ENDS
In Assembly programming, the variable are all defined by bytes only.
DB – Define Byte (Size – 1 Byte)
DW – Define Word (Size – 2 Byte)
DD – Define Double word (Size - 4 Bytes)
DQ – Define Quad word (Size – 8 Bytes)
DT – Define Ten Bytes (Size – 10 Bytes)
NUMBER SYSTEM in Assembly Programming is Decimal, Octal, Hexadecimal, Binary.
In the Program, We are entering the values for the variables and Do arithmetical Operations like Addition, Subtraction, Multiplication and Division So the Computer should understand which kind of Number is entered. Hence there is a different letters for different Number Systems. O or o stands for Octal, H or h stands for Hexadecimal, B or b stands for Binary, D or d stands for Decimal. By default type of numbering system is Decimal. If you do not specify any letter then the number is understood to be Decimal (By default).
DATA SEGMENT
NUM1 DB 36H,55H,27H,42H
NUM2 DB 38H,41H,29H,39H
RESULT DB 5 DUP (0)
ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA SI,NUM1
LEA DI,NUM2
LEA BX,RESULT
MOV CX,5
LOOP1:
MOV AL,[SI]
ADD AL,[DI]
MOV [BX],AL
INC BX
INC SI
INC DI
LOOP LOOP1
MOV AH,4CH
INT 21H
ENDS
END START
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.