Using An assembly code
Read a 3 digit number from one row, then a 1 digit number from the second row. Subtract the 1 digit number from the 3 digit number, and display the result. Make sure you print your name first, then your output.
Sample Input
123
1
Output
Name Last name
122
Sample Input
100
1
Output
Name Last name
099 (or you can display 99 without the 0, either one is fine)

Sample Input
001
1

Output

Name Last name
0 (or you can display 000, either one is fine by me)

Answers

Answer 1

An example implementation of the algorithm you described in x86 assembly language using NASM syntax:

The Assembly Language Program

section .data

   ; Define your data here if needed

section .text

   global _start

_start:

   ; Print your name here

   

   ; Read the 3-digit number

   mov eax, 3       ; number of characters to read

   mov ebx, 0       ; file descriptor (stdin)

   mov ecx, buf     ; buffer to store the input

   mov edx, eax     ; maximum number of characters to read

   int 0x80         ; invoke the read system call

   

   ; Convert the input to a number

   mov eax, buf

   sub eax, '0'     ; convert the hundreds digit

   mov ebx, 10

   imul ebx

   mov ecx, buf+1

   sub ecx, '0'     ; convert the tens digit

   add eax, ecx

   imul ebx

   mov ecx, buf+2

   sub ecx, '0'     ; convert the units digit

   add eax, ecx

   

   ; Read the 1-digit number

   mov eax, 1       ; number of characters to read

   mov ebx, 0       ; file descriptor (stdin)

   mov ecx, buf     ; buffer to store the input

   mov edx, eax     ; maximum number of characters to read

   int 0x80         ; invoke the read system call

   

   ; Convert the input to a number

   mov ebx, 10

   mov ecx, buf

   sub ecx, '0'     ; convert the digit

   mul ebx

   

   ; Subtract the 1-digit number from the 3-digit number

   sub eax, ecx

   

   ; Convert the result to a string

   mov ebx, 10

   div ebx

   add edx, '0'     ; convert the units digit

   mov [result+2], dl

   div ebx

   add edx, '0'     ; convert the tens digit

   mov [result+1], dl

   add eax, '0'     ; convert the hundreds digit

   mov [result], al

   

   ; Print the result

   mov eax, 4       ; system call for write

   mov ebx, 1       ; file descriptor (stdout)

   mov ecx, result  ; address of the string to print

   mov edx, 3       ; number of characters to print

   int 0x80         ; invoke the write system call

   

   ; Exit the program

   mov eax, 1       ; system call for exit

   xor ebx, ebx     ; exit status

   int 0x80

section .bss

   buf resb 4       ; buffer for input (3 digits + newline)

   result resb 4    ; buffer for output (3 digits + null terminator)

Note that this implementation uses system calls for input/output and assumes that the input is terminated by a newline character. You may need to modify it to suit your specific requirements or platform.

Read more about assembly language here:

https://brainly.com/question/30299633

#SPJ1


Related Questions

he files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly.

An example of the program is shown below:

Enter a number between 1 and 20 >> 5
5 4 3 2 1 Blastoff!
JAVA CODE:
// Prompt user for value to start
// Value must be between 1 and 20 inclusive
// At command line, count down to blastoff
// With a brief pause between each displayed value
import java.util.Scanner;
public class DebugSix3
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int userNum, val;
final int MIN = 1;
final int MAX = 20;
final int TIME_WASTER = 100000;
System.out.print("Enter a number between " + MIN +
" and " + MAX + " >> ");
userNum = keyboard.nextInt();
while(userNum < MIN && userNum < MAX)
{
System.out.println("Number out of range");
System.out.print("Enter a number between " + MIN + " and " +
MAX + " inclusive >> ");
userNum = keyboard.nextInt();
}
for(val = userNum; val == 0; --val)
{
System.out.print(val + " ");
for(int x = 0; x < TIME_WASTER; ++x)
for(int y = 0; y < TIMEWASTER; ++y)
for(int z = 0; z < TIME_WASTER;);
// Adjust these numbers for faster or slower performance
}
System.out.println("Blastoff!");
}
}

Answers

Fixed code:

import java.util.Scanner;

public class DebugSix3 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int userNum, val;
final int MIN = 1;
final int MAX = 20;
final int TIME_WASTER = 100000;

Kotlin:
System.out.print("Enter a number between " + MIN + " and " + MAX + " >> ");
userNum = keyboard.nextInt();

while (userNum < MIN || userNum > MAX) {
System.out.println("Number out of range");
System.out.print("Enter a number between " + MIN + " and " + MAX + " inclusive >> ");
userNum = keyboard.nextInt();
}

for (val = userNum; val >= 0; --val) {
System.out.print(val + " ");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("Blastoff!");
}

Changes made:

Fixed the while loop condition to use OR instead of AND
Fixed the for loop condition to use greater than or equal to instead of equal to
Added a try-catch block to pause the loop for 1 second using Thread.sleep() instead of nested for loops
Fixed some syntax errors and indentation issues.

program to take the command line input to cut down the blast off.

// DebugSix3.java

// Prompt user for value to start

// Value must be between 1 and 20 inclusive

// At command line, count down to blastoff

// With a brief pause between each displayed value

import javax.swing.*;

public class DebugSix3

{

 public static void main(String[] args)

 {

   String userNumString;

   int userNum, val;

   final int MIN = 1;

   final int MAX = 20;

   userNumString = JOptionPane.showInputDialog(null,

       "Enter a number between " + MIN + " and " + MAX + " inclusive");

   userNum = Integer.parseInt(userNumString);

   while(userNum < MIN || userNum > MAX)

   {

      userNumString = JOptionPane.showInputDialog(null,

       "Number out of range" +

       "\nEnter a number between " + MIN + " and " + MAX + " inclusive");

      userNum = Integer.parseInt(userNumString);

   }

   for(val = userNum; val > 0; --val)

   {

     System.out.print(val + "  ");

     for(int x = 0; x < 100000; ++x)

      for(int y = 0; y < 10000; ++y);

      // Adjust these numbers for faster or slower performance

   }

   System.out.println("Blastoff!");

 }

}

learn more about command line input here:

https://brainly.com/question/19569210

#SPJ1

Other Questions
he san andreas fault is... group of answer choices associated with deep focus earthquakes a world-famous example of a hot spot is an intraplate fault within the juan de fuca plate an oceanic transform fault a continental transform fault if a plant produces 4.91 mol c6h12o6, 4.91 mol c 6 h 12 o 6 , how many moles of co2 co 2 are needed? if the price of a good rise from 10 dollars to 15 and quantity sold decreases from 10000 to 7000 what is the elastiity which of the following cells or substances particpates in non-specific immune defenses? natural killer cells antibodies cytotoxic t cells none of the above the bookkeeper for company wrote a check for to pay for furnace maintenance. the check was incorrectly recorded in the general journal as . the entry to correct this error would be Solve the problems. Show your work.71. Mr. Nguyen had 7/8pint of water in his water bottle. Then, he drank 2/3 pint. How much water is left in the bottle? Which of these lines from "APiece of String" illustratesMatre Hauchecome'sconflict?A. "...he took a turn in the village...He onlymet with incredulity. It made him ill atnight."B. "Along all the roads around Godervillethe peasants and their wives were comingtoward the burgh..."C. "The news had spread." calculate the horizontal component of the net force, in newtons, on the charge which lies at the lower left corner of the rectangle. Question 5(Multiple Choice Worth 2 points)(Appropriate Measures MC)The scores earned in a flower-growing competition are represented in the stem-and-leaf plot.0 51 0, 3, 72 4, 6, 83 24 5 8Key: 5|8 means 58What is the appropriate measure of variability for the data shown, and what is its value? The range is the best measure of variability, and it equals 18.5. The IQR is the best measure of variability, and it equals 45. The range is the best measure of variability, and it equals 45. The IQR is the best measure of variability, and it equals 18.5.Question 6(Multiple Choice Worth 2 points)(Appropriate Measures MC)The line plot displays the cost of used books in dollars.A horizontal line starting at 1 with tick marks every one unit up to 9. The line is labeled Cost in Dollars, and the graph is titled Cost of Used Books. There are two dots above 1, 2, 3, 5, and 6. There are four dots above 7.Which measure of center is most appropriate to represent the data in the graph, and why? The median is the best measure of center because there are no outliers present. The median is the best measure of center because there are outliers present. The mean is the best measure of center because there are no outliers present. The mean is the best measure of center because there are outliers present. what is the electron configuration of a ground-state cu atom? multiple choice 1s22s22p63s23p64s13d10 Help I will mark you as a brainliest If the graph of a polynomial function P(x) has -intercepts at x = - 4, x = 0, x * 1 point= 5, which of the following must be true for P(x)? (x + 5) is a factor of the polynomial. (x-4) is a factor of the polynomial.' The degree of the polynomial is 3. The degree of the polynomial is greater than or equal to 3. Using the information on this page, explain in your own words at least three ways in which the U.S. and Canadian economies are interrelated.Respond in at least three complete sentences. why was it not until the late eighteenth century that large numbers of individuals considered slavery to be morally wrong? In a car park,the number of cars: the number of vans = 7:4the number of vans: the number of lorries = 3:2The total number of cars, vans and lorries in the car park is 205How many vans are in the car park? when a salesperson has been introduced to a sales lead by another customer, that salesperson has been provided a(n) . which one of the following amino acids r groups (a.k.a. side chain) is most likely to participate in hydrogen bonding with water? group of answer choices asparagine alanine leucine phenylalanine valine In one to two sentences, describe a theme of the excerpt. Self porptrait What is the difference in volume (in mL) of oxygen produced between the low-light and high-light plants after 45 minutes? jean piaget believed that human behavior is based on specific human needs that must often be met in a specific order true false