Question

In: Electrical Engineering

Write a program that runs on SPIM that allows the user to enter the number of...

Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm

Solutions

Expert Solution

c++ code :

#include<iostream>

using namespace std;

intmain()

{

while (true)
{
    cout << "Enter hours, minutes and seconds." << endl;
    cout << "hours:";
    cin >> hour;
    if (hour < 0 || hour > 23)
    {
        cout << "Error: hours should be in between [0..23]" << endl;
        continue;
    }

    cout << "minutes:";
    cin >> min;
    if (min < 0 || min > 59)
    {
        cout << "Error: minutes should be in between [0..59]" << endl;
        continue;
    }

    cout << "seconds:";
    cin >> sec;
    if (sec < 0 || sec > 59)
    {
        cout << "Error: seconds should be in between [0..59]" << endl;
        continue;
    }
    break;
}
}

cout << "Total seconds: " << (sec + min*60 + hour*60*60) << endl;

ASSEMBLY LEVEL PROGRAMMING

.MODEL SMALL
 .STACK 100H

 .DATA
   PROMPT_1  DB  'Enter the time in seconds up to 65535 = $'
   PROMPT_2  DB  0DH,0AH,'The time in hh:mm:ss format is = $'
   SEPARATOR DB  ' : $'

 .CODE
   MAIN PROC
     MOV AX, @DATA                ; initialize DS
     MOV DS, AX

     LEA DX, PROMPT_1             ; load and display the string PROMPT_1
     MOV AH, 9
     INT 21H

     CALL INDEC                   ; call the procedure INDEC

     PUSH AX                      ; puah AX onto the STACK

     LEA DX, PROMPT_2             ; load and display the string PROMPT_2
     MOV AH, 9
     INT 21H

     POP AX                       ; pop a value from STACK into AX

     XOR DX, DX                   ; clear DX
     MOV CX, 3600                 ; set CX=3600
     DIV CX                       ; set AX=DX:AX\CX , DX=DX:AX%CX

     CMP AX, 10                   ; compare AX with 10
     JGE @HOURS                   ; jump to label @HOURS if AX>=10

     PUSH AX                      ; push AX onto the STACK

     MOV AX, 0                    ; set AX=0
     CALL OUTDEC                  ; call the procedure OUTDEC

     POP AX                       ; pop a value from STACK into AX
                                   
     @HOURS:                      ; jump label
     CALL OUTDEC                  ; call the procedure OUTDEC

     MOV AX, DX                   ; set AX=DX

     PUSH AX                      ; push AX onto the STACK

     LEA DX, SEPARATOR            ; load and display the string SEPARATOR
     MOV AH, 9
     INT 21H

     POP AX                       ; pop a value from STACK into AX
     XOR DX, DX                   ; clear DX

     MOV CX, 60                   ; set CX=60
     DIV CX                       ; set AX=DX:AX\CX , DX=DX:AX%CX

     CMP AX, 10                   ; compare AX with 10
     JGE @MINUTES                 ; jump to label @MINUTES if AX>=10

     PUSH AX                      ; push AX onto the STACK

     MOV AX, 0                    ; set AX=0
     CALL OUTDEC                  ; call the procedure OUTDEC

     POP AX                       ; pop a value from STACK into AX

     @MINUTES:                    ; jump label
     CALL OUTDEC                  ; call the procedure OUTDEC

     MOV BX, DX                   ; set BX=DX

     LEA DX, SEPARATOR            ; load and display the string SEPARATOR
     MOV AH, 9
     INT 21H

     MOV AX, BX                   ; set AX=BX

     CMP AX, 10                   ; compare AX with 10 
     JGE @SECONDS                 ; jump to label @SECONDS if AX>=10

     PUSH AX                      ; push AX onto the STACK 

     MOV AX, 0                    ; set AX=0
     CALL OUTDEC                  ; call the procedure OUTDEC

     POP AX                       ; pop a value from STACK into AX

     @SECONDS:                    ; jump label
     CALL OUTDEC                  ; call the procedure OUTDEC

     MOV AH, 4CH                  ; return control to DOS
     INT 21H
   MAIN ENDP

Related Solutions

Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm Explain step by step
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
Write a MATLAB program to do the following: 1- Allows the user to enter unlimited number...
Write a MATLAB program to do the following: 1- Allows the user to enter unlimited number of data set. 2- Allows the user to exit the program at any time by entering zero. 3- Calculates and displays the following statistics for the entered data set: a- Count of positive, negative, and total numbers. b- Maximum and Minimum numbers. c- Sum and Average of positive numbers. d- Sum and Average of negative numbers. e- Overall Sum and overall average of all...
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
C++ Vector Write a program that allows the user to enter the last names of the...
C++ Vector Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name more than once and assume that two or more candidates receive the same number of votes. Your program should output the...
Fat Percentage Calculator Create a C++ program that allows the user to enter the number of...
Fat Percentage Calculator Create a C++ program that allows the user to enter the number of calories and fat grams in a food. The application should display the percentage of the calories that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating the food is low in fat. One gram of fat has 9 calories, so: Calories from fat = fat grams *...
Write an application that allows a user to enter any number of student quiz scores, as...
Write an application that allows a user to enter any number of student quiz scores, as integers, until the user enters 99. If the score entered is less than 0 or more than 10, display Score must be between 10 and 0 and do not use the score. After all the scores have been entered, display the number of valid scores entered, the highest score, the lowest score, and the arithmetic average.
Write a program that asks the user to enter an unsigned number and read it. Then...
Write a program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6. COMMENT COMPLETE CODE PLEASE
IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT