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
Hi this is Assembly Language MASM x86 program. Please write it in the language and please...
Hi this is Assembly Language MASM x86 program. Please write it in the language and please explain it with comments thank you Please answer it I really need help this question was refunded before so please answer. Thank you so much also these are two separate programs thank you. 1) Write a procedure to read in decimal or hex number (byte-sized) Then write a procedure using shifts and ANDS to convert the string to a binary number (if is backward,...
in assembly language x86 Masm, Write a program that calculate the first seven values of the...
in assembly language x86 Masm, Write a program that calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(0) = 0, Fib(1) = 1, Fib(2) = Fib(0)+ Fib(1), Fib(n) = Fib(n-1) + Fib(n-2). You NEED to calculate each value in the series "using registers and the ADD operation" You can also use variables, Have your program print out "The first seven numbers is" Use WriteInt for the printing, Place each value in the EAX...
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 In MASM assembler to calculate the sum of odd numbers only stored...
Write an assembly program In MASM assembler to calculate the sum of odd numbers only stored in a 16-bit integers array. The size of the array is provided in a separate variable. Use the following design: Sum = 0 FOR i = 0 TO SizeOfArray - 1     IF Arr[i] % 2 = 1           Sum = Sum + Arr[i]     END IF END FOR
Please code C# 6. Write a program that generates a random number between 0 and 10...
Please code C# 6. Write a program that generates a random number between 0 and 10 and asks the user to guess that number. The program then informs the user if they guessed correctly or incorrectly then displays the correct answer.
Create a program RandomFile.java that generates files with random numbers/characters. You are required to write the...
Create a program RandomFile.java that generates files with random numbers/characters. You are required to write the following three methods in the class RandomFile: ​public static void randomBinaryFile(String fileName, int length) ​public static void randomNumberFile(String fileName, intlength) ​public static void randomCharFile(String fileName, int length) The parameter “fileName” specifies the file name, and “length” specifies the length of the sequence in the file. ● randomBinaryFile will generate a file containing a sequence of 0 or 1 of the specified length; ● randomNumberFile...
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 an assembly language program that repeatedly prompts the user to enter signed decimal integer numbers....
Write an assembly language program that repeatedly prompts the user to enter signed decimal integer numbers. The program should be run from the command prompt, output a text prompt to the screen, and then wait for the user to type in a number followed by the Enter key. (The legitimate range of user input values is any signed integer that can be represented in 32 bits.) After each number is entered, the program should determine and display the following information...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT