Question

In: Computer Science

In Assembly Language MASM Write a program that generates 10 random numbers (0~99). Save the numbers...

In Assembly Language MASM

Write a program that generates 10 random numbers (0~99). Save the numbers into arrayInt and calculate the sum.

.data

arrayInt Byte 10 DUP(?)

Displays the array and the sum as follows:

The random numbers are:

xx xx xx xx xx xx ….

The sum is   xxxx

Solutions

Expert Solution

Here is code in Assembly Language:

.MODEL SMALL
.STACK 100H

.DATA
PROMPT DB \'The Array elements are : $\'
RESULT DB 0DH,0AH,\'The Sum of the Array is = $\'

ARRAY DB 10,20,30,40,50,60,70,80,90,100

.CODE
MAIN PROC
MOV AX, @DATA ; initialize DS
MOV DS, AX

MOV BX, 10 ; set BX=10

LEA DX, PROMPT ; load and display the string PROMPT
MOV AH, 9
INT 21H

MOV CX, BX ; set CX=BX
LEA SI, ARRAY ; set SI=offset address of ARRAY

@LOOP: ; loop label
XOR AH, AH ; clear AH
MOV AL, [SI] ; set AX=[SI]

CALL OUTDEC ; call the procedure OUTDEC

INC SI ; set SI=SI+1

MOV AH, 2 ; set output function
MOV DL, 20H ; set DL=20H
INT 21H ; print a character
LOOP @LOOP ; jump to label @LOOP while CX!=0

LEA DX, RESULT ; load and display the string RESULT
MOV AH, 9
INT 21H

LEA SI, ARRAY ; set SI=offset address of ARRAY

CALL SUM ; call the procedure SUM
CALL OUTDEC ; call the procedure OUTDEC

MOV AH, 4CH ; return control to DOS
INT 21H
MAIN ENDP

;------------------------- Procedure Definitions ------------------------;


;--------------------------------- SUM ----------------------------------;


SUM PROC
; this procedure will calculate the sum of an array
; input : SI=offset address of the array
; : BX=size of the array
; output : AX=sum of the array

PUSH CX ; push CX onto the STACK
PUSH DX ; push DX onto the STACK

XOR AX, AX ; clear AX
XOR DX, DX ; clear DX
MOV CX, BX ; set CX=BX

@SUM: ; loop label
MOV DL, [SI] ; set DL=[SI]
ADD AX, DX ; set AX=AX+DX
INC SI ; set SI=SI+1
LOOP @SUM ; jump to label @SUM while CX!=0

POP DX ; pop a value from STACK into DX
POP CX ; pop a value from STACK into CX

RET ; return control to the calling procedure
SUM ENDP


;-------------------------------- OUTDEC --------------------------------;


OUTDEC PROC
; this procedure will display a decimal number
; input : AX
; output : none

PUSH BX ; push BX onto the STACK
PUSH CX ; push CX onto the STACK
PUSH DX ; push DX onto the STACK

CMP AX, 0 ; compare AX with 0
JGE @START ; jump to label @START if AX>=0

PUSH AX ; push AX onto the STACK

MOV AH, 2 ; set output function
MOV DL, \"-\" ; set DL=\'-\'
INT 21H ; print the character

POP AX ; pop a value from STACK into AX

NEG AX ; take 2\'s complement of AX

@START: ; jump label

XOR CX, CX ; clear CX
MOV BX, 10 ; set BX=10

@OUTPUT: ; loop label
XOR DX, DX ; clear DX
DIV BX ; divide AX by BX
PUSH DX ; push DX onto the STACK
INC CX ; increment CX
OR AX, AX ; take OR of Ax with AX
JNE @OUTPUT ; jump to label @OUTPUT if ZF=0

MOV AH, 2 ; set output function

@DISPLAY: ; loop label
POP DX ; pop a value from STACK to DX
OR DL, 30H ; convert decimal to ascii code
INT 21H ; print a character
LOOP @DISPLAY ; jump to label @DISPLAY if CX!=0

POP DX ; pop a value from STACK into DX
POP CX ; pop a value from STACK into CX
POP BX ; pop a value from STACK into BX

RET ; return control to the calling procedure
OUTDEC ENDP

END MAIN


Related Solutions

In Assembly Language Write a program that generates 10 random numbers (0~99). Save the numbers into...
In Assembly Language Write a program that generates 10 random numbers (0~99). Save the numbers into arrayInt and calculate the sum. .data arrayInt Byte 10 DUP(?) Displays the array and the sum as follows: The random numbers are: xx xx xx xx xx xx …. The sum is   xxxx
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE...
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO SOLVE THE EQUATION Z=A+B-(C/D)+E please write the answer separately part A its own code and part B its own code this is microprocessor the ASSEMBLY LANGUAGE emu8086 should be written like this EX: mov ax,100h mov bx,200h etc
Write an assembly program that lets the user to input only the word MASM and displays...
Write an assembly program that lets the user to input only the word MASM and displays invalid input for any other user inputs.
Write a Python program which generates a random number between 0 and 24 inclusive and that...
Write a Python program which generates a random number between 0 and 24 inclusive and that print out: • the double of the random number if the random number is greater than 12, • the triple of the random number if it is equal to 12 • and the quadruple of the random number if it is less than 12
Write a program in C to perform the following: Generates an array of 10 double random...
Write a program in C to perform the following: Generates an array of 10 double random values between 1.0 and 100.0 – assume these are prices for 10 items that a store sells Generates an array of 10 integer random values between 0 and 200 – assume that these are the number of items/units (first array) sold Generate another array called “itemSale” which would contain the total sale for each item. Calculate the total sale for this store and display...
Write a MASM program that uses a loop to multiply 2 numbers. Use the equal sign...
Write a MASM program that uses a loop to multiply 2 numbers. Use the equal sign directive to define the two numbers. Save the product in the EAX register. Hint 4 x 5 = 4 + 4 +4 + 4 + 4 = 5 + 5 + 5 + 5 Language (Assembly) ASAP
Assembly using x86 irvine (masm) Write a complete program that will input values for num1 ,num2,...
Assembly using x86 irvine (masm) Write a complete program that will input values for num1 ,num2, and num3 and display the value of the expression ( (num1 ^ 3) * num2 + 5 * ( num2 ^ 2) ) / num3. assume that the user enters only numbers that are greater than zero and the calculation never exceed 4 bytes size. Sample run: num1 = 1 num2 = 2 num3 = 3 ((num1 ^ 3) * num2 + 5 *...
Write an assembly program (Data and Code) that uses loop to read 10 numbers and output...
Write an assembly program (Data and Code) that uses loop to read 10 numbers and output the largest of those numbers, you can assume any length for those numbers. 80x86 assembly language
Create a program that generates a file of random numbers, and then prints them in neat...
Create a program that generates a file of random numbers, and then prints them in neat fashion to another file, and also saves to that file the average and standard deviation of those numbers. I) First, you would need to generate a file of random numbers that consists of N random numbers (100 < N < 1000). Each random digit should be a real number (type double) between 0 and 50. This file and its digits would now serve as...
Write a C++ program that 1) generates a vector containing 10 different random integers with values...
Write a C++ program that 1) generates a vector containing 10 different random integers with values between 1 and 100, then 2) calculates the average value in that vector in floating point format with 1 decimal place. Output the vector values and the average value to cout. Your program output should look like this: Vector values: 3, 78, 55, 37, 8, 17, 43, 60, 94, 1 Average value: 39.6
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT