loading...

CS401 Computer Architecture and Assembly Language Assignment 3 Solution Spring 2013

Question:

We have an array of whole numbers in the main program as follows:

ARRAY :  0,1,2,3,4,5,6,7,8,9,10

You are required to write an assembly language program having a subroutine “SUM_OF_SQUARE”. The subroutine should find out the square of each number and then add them together along with storing the result into a separate data label “SUM” as follows:

Copy “SUM” into “DX” after executing the subroutine.

Provide the final snapshot of AFD that should display the contents of data label “SUM” and “DX”.

Marking Distribution:                                                                                  (Total = 20 marks) 

  1. Writing correct subroutine.                                                                 (15 marks)
  1. AFD command used for showing data in data label “SUM”.                        (2 marks)
Solution: [ORG 0x0100]MOV BX, VAL
MOV CX, 10
MOV AX, 0

CALL SUM_OF_SQUARE

MOV AX, 0X4C00
INT 0X21

SUM_OF_SQUARE:
MOV AX, [BX]
MUL AX
ADD AX, [SUM]
MOV [SUM], AX
ADD BX, 2
SUB CX, 1
JNZ SUM_OF_SQUARE
MOV DX, [SUM]
RET

VAL: DW 0,1,2,3,4,5,6,7,8,9
SUM: DW 0

  1. AFD snapshot showing result of “SUM” and “DX”.                                    (3 marks)

snapshot.jpg (677×466)

DOWNLOAD SOLUTION HERE
loading...