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 for loop output a string in reverse printing it character...
Write a program that uses a for loop output a string in reverse printing it character by character. C++ Program Example: "Enter some text:" this is a test "your text in reverse is:" tset a si siht Please note that you can find the length of the string by using the length function: string str = "hello" cout << str.length(); Also you can et a character in a string by providing an index to the function string str = "hello"...
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
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate...
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 2, … Fib(n) = Fib(n-1) + Fib(n-2). Place each value in the EAX register and display it with a call DumpRegs statement inside the loop For example: Fib(1) = 1, Fib(2) = 2, Fib(3) = Fib(1) + Fib(2) = 3, Fib(4) = Fib(2) + Fib(3)...
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 ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT