Question

In: Computer Science

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

Solutions

Expert Solution

Codes

find out the largest among 8-bit n numbers, where size “10" is stored at memory address 2000 : 600 and the numbers are stored from memory address 2000 : 601 and store the result (largest number) into memory address 2000 : 800.

Example

Input data and memory address

10 20 21 22 23 24 25 36 26 27 28
600 601 602 603 604 605 606 607 608 607 608

Out put data

36
800

Algorithm –

  1. Load data from offset 600 to register CL and set register CH to 00 (for count).
  2. Load first number(value) from next offset (i.e 601) to register AL and decrease count by 1.
  3. Now compare value of register AL from data(value) at next offset, if that data is greater than value of register AL then update value of register AL to that data else no change, and increase offset value for next comparison and decrease count by 1 and continue this till count (value of register CX) becomes 0.
  4. Store the result (value of register AL ) to memory address 2000 : 800.

Program

MEMORY ADDRESS MNEMONICS COMMENT
500 MOV SI, 600 SI<-600
503 MOV CL, [SI] CL<-[SI]
505 MOV CH, 00 CH<-00
507 INC SI SI<-SI+1
508 MOV AL, [SI] AL<-[SI]
50A DEC CL CL<-CL-1
50C INC SI SI<-SI+1
50D CMP AL, [SI] AL-[SI]
50F JNC 513 JUMP TO 513 IF CY=0
511 MOV AL, [SI] AL<-[SI]
513 INC SI SI<-SI+1
514 LOOP 50D CX<-CX-1 & JUMP TO 50D IF CX NOT 0
516 MOV [800], AL AL->[800]
51A HLT END

Explanation –

  1. MOV SI, 600 : set the value of SI to 600
  2. MOV CL, [SI] : load data from offset SI to register CL
  3. MOV CH, 00 : set value of register CH to 00
  4. INC SI : increase value of SI by 1.
  5. MOV AL, [SI] : load value from offset SI to register AL
  6. DEC CL : decrease value of register CL by 1
  7. INC SI : increase value of SI by 1
  8. CMP AL, [SI] : compares value of register AL and [SI] (AL-[SI])
  9. JNC 513 : jump to address 513 if carry not generated
  10. MOV AL, [SI] : transfer data at offset SI to register AL
  11. INC SI : increase value of SI by 1
  12. LOOP 50C : decrease value of register CX by 1 and jump to address 50D if value of register CX is not zero
  13. MOV [800], AL : store the value of register AL to offset 800
  14. HLT : stop

Related Solutions

Write a program that uses a while loop with a priming read to ask the user...
Write a program that uses a while loop with a priming read to ask the user to input a set positive integers. As long as the user enters a number greater than -1, the program should accumulate the total, keep track of the number of numbers being entered and then calculate the average of the set of numbers after the user enters a -1. This is a sentinel controlled-loop. Here is what a sample run should look like: Enter the...
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
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
Problem description Write a program that uses a loop to read integer values from the standard...
Problem description Write a program that uses a loop to read integer values from the standard input stream. Each non-zero value, x, is the first number of a sequence. Define a0 = x; an+1 = an / 2 if an is even; an+1 = 3 * an + 1 if an is odd. Then there exists an integer k such that ak = 1. For each non-zero value of x, the program outputs the integer k such that ak =...
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
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
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
Write a program that uses a for loop to print One of the months of the...
Write a program that uses a for loop to print One of the months of the year is January One of the months of the year is February ...
Write a Java program to read in the 10 numbers in the example file Book1.csv provided...
Write a Java program to read in the 10 numbers in the example file Book1.csv provided above. The program should sum all the numbers, find the lowest number, find the highest number, and computer the average. Upon completion of the processing, the program should write a new text file named stats.txt with the information found in the following format where xxx represents a number calculated above. The sum of the numbers is: xxx The lowest number is: xxx The highest...
1. Write MIPS assembly code to sum “n” positive integers. Forexample, n=5, read 5 numbers...
1. Write MIPS assembly code to sum “n” positive integers. For example, n=5, read 5 numbers in memory (“.data” section) and add them together. 2. Write MIPS assembly code to calculate N-factorial. Read n from the memory. (Hint: use “.data” to define the content in a memory location)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT