Following is the simple program which will compare x and y, and will store 1 if x>y and -1 if x<y
LD R1, x ;load x into R1 LD R2, y ;load y into R2 AND R6,R6,#0 ;initialize R0 with 0 NOT R3, R2 ;R3 = -R2 (we negate NUMBER2) ADD R4, R3, R1 ;R4 = R1 - R2 BRz Equals ;we jump to Equals if x = y (we can just jump directly to END) BRn GreaterR2 ;we jump to GreaterR2 if x < y BRp GreaterR1 ;we jump to GreaterR2 if x > y Equals BRnzp End ;nothing to do, because R0=0 (THIS IS NOT NECCESARY) GreaterR2 ADD R0, R0, #-1 ;R0 = -1 BRnzp End GreaterR1 ADD R0, R0, #1 ;R0 = 1 BRnzp End Done HALT ;THE END x .FILL #2 ;/ Declaration of numbers. y .FILL #6 ;\
So above is the way in which we will compare the values x and y using LC3.
That was a nice question to answer
Friend, If you have any doubts in understanding do let me know in
the comment section. I will be happy to help you further.
Thanks
| 25 pts 25 pts) 2. 2. Write an LC3 program that compares two numbers x...
Write an LC3 program that would implement if (x == 0) then y = y + 1; else y = y - 1;. Assume than variables x and y are at locations with labels x and y, respectively.
Write a program in C or a script in bash, called “compare” that takes two numbers on the command line and compares them. The program should print the result of the comparison. Specifically, it should print “<x> is <comparison> <y>”, where <x> is the first number, <y> is the second number and <comparison> is one of “equal to”, “greater than” or “less than”. If the two numbers are equal, the program should have an exit status of zero. The exit...
Topics If/Else statement Description Write a program that determines the larger of the two numbers provided by the user. The program asks the user to enter a number. Then it asks the user to enter another but a different number. Then, it determines the larger of the two numbers and displays it to the user. (If the user happens to enter the two numbers the same, the program may report either of the two numbers as larger.) Requirements Do...
Number Comparison: Write a program in PYTHON that compares three numbers and displays the following: Check if they are all the same, all different, or neither. Determine if 3 numbers are in increasing order, decreasing order, or neither. Find the highest and lowest number.
1- Write a C program to add and subtract any two given integer numbers using pointers. 2- Write a C program to find the factorial using a function and pointers. 3- Write a C program to find the square of an Integer number using a function and pointers. 4- Write a C program to find the area and perimeter of a rectangle using a function and pointers. 5- Write a C program to find the larger of two integers numbers using...
Adding Two Numbers) Write a program that defines macro SUM with two arguments, x and y, and use SUM to produce the following output: the sum of x and y is 13 Please type answer out fully
1. Write a program that asks the user to enter two integers, obtains the numbers from the user, then prints the larger number followed by the words “is larger.” If the numbers are equal, print the message “These numbers are equal.” Use only the single-selection form of the if statement you learned in this chapter.
Write a program that obtains two numbers from the user and displays the larger of the two numbers. Use if-else
Write a C program to sum up all the odd numbers between a lower limit number and an upper limit number provided by a user. The requirements are: First, request the user to provide a lower limit integer number and an upper limit integer number that is larger than the lower limit number, and save them in variables lowerLimit and upperLimit, respectively. If the user has entered an upper limit number (upper Limit) that is NOT larger than the lower...
mathTutor Write a program that selects two random numbers -20 to 20. The two numbers would get displayed with "+" between them. The user should enter the sum of the two numbers. The program should print "Incorrect" if the user enters a wrong answer and re-prompts the user to re-enter the answer again. Limit the number of incorrect tries to 3. After 3 incorrect tries print the correct answer. The program should print a message like "Correct!" if the user...