COMPUTER ASSEMBLY LANGUAGE 1.In this program data comes in pairs, say height and
ID: 3716285 • Letter: C
Question
COMPUTER ASSEMBLY LANGUAGE
1.In this program data comes in pairs, say height and weight:
.data pairs:
.word 5 # number of pairs
.word 60, 90 # first pair: height, weight
.word 65, 105
.word 72, 256
.word 68, 270
.word 62, 115
Write a program that computes the average height and average weight. Leave the results in two registers.
2. Compute the dot product of two vectors. A vector is an array of integers. Both vectors are the same length. Ask the user for the length of the vectors. Then prompt for and read in the value of each element of each vector. Reserve space in memory for vectors of up to 10 elements, but allow vectors of any size one through 10.
.data
length: .word 0
vectorA: .space 40 # space for 10 integers
vectorB: .space 40 # space for 10 integers
The dot product of two vectors is the sum of the product of the corresponding elements. For example, (1, 2, 3) dot (4, 5, 6) is 1*4 + 2*5 + 3*6. After computing it, write out the dot product to the monitor.
3. (Please use stack to solve this problem) Write a subroutine that takes three arguments, A, X, and Y. It then computes A*X*Y and returns it. Use the subroutine to evaluate the following for various values of u and v:
5u2 - 12uv + 6v2.
Write a main method, in a loop, prompts the user for values of u and v and prints out the result. End the loop when the user enters zero for both u and v.
Explanation / Answer
1) Here i am storing the input data slightly in a different way, i ll be storing heights value in one array and weight value in another array and compute each average seperately.
performing average for just height, weight can be done by following this
DATA SEGMENT
ARRAY DB 60, 65, 72, 68, 62
AVG DB ?
ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA SI,ARRAY
LEA DX,MSG
MOV AH,9
INT 21H
MOV AX,00
MOV BL,9
MOV CX,9
LOOP1:
ADD AL,ARRAY[SI]
INC SI
LOOP LOOP1
DIV BL
ADD AL,30H
MOV DL,AL
MOV AH,2
INT 21H
MOV AH,4CH
INT 21H
ENDS
END START
for 2nd question finding the dot product which is also easier similar to previous example, where you have two arrays. here multifly one array first element with another array and store it into another array, similar to follow the algorithm till the end of the array.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.