Assembly Language You will be implementing the following procedures: get_score P
ID: 3838627 • Letter: A
Question
Assembly Language
You will be implementing the following procedures:
get_score
Prompts the user for a score (between 0 – 100) and reads it in as a string. The string should be stored in the score BYTE in memory. Then, the ParseInteger32 function is used to store the numeric value (32 bit DWORD) in eax. The numeric value (in eax) will be used to determine the letter grade that corresponds to the score in the calculate_grade function. The string (in score) will be used to write the score to the file in the write_file function.
Input validation loop:
An input validation loop is needed to make sure that all scores are between 0 – 100. If the user enters a score less than 0 or greater than 100, they should be prompted again for the score until they enter something valid.
calculate_grade
Uses the numeric score in eax to determine the corresponding letter grade based on the following criteria*:
- If the score is 90 – 100, the grade is an A
- If the score is 80 – 89, the grade is a B
- If the score is 70 – 79, the grade is a C
- If the score is 60 – 69, the grade is a D
- If the score is less than 60, the grade is an F
*The grading scale could be changed at any time by changing the A_grade, B_grade, C_grade, and D_grade constants in the program. The program should still work correctly even if these constants were changed in the future.
write_file
Write’s the information to the output file in the format shown in the sample run screenshots (see below)
display_output
Display’s the text “The results have been written to the output file: “ followed by the file name (see below).
Built-in procedures from Kip Irvine’s library that you will need to use:
- WriteString
- ReadString
- ParseInteger32
- WriteToFile
You will need these 2 test files:
Scores.txt
Score: 92 Letter grade: A
Score: 86 Letter grade: B
Score: 75 Letter grade: C
Score: 62 Letter grade: D
Score: 41 Letter grade: F
Score: 97 Letter grade: A
Scores2.txt
Score: 95 Letter grade: A
Score: 64 Letter grade: D
Score: 75 Letter grade: C
Score: 82 Letter grade: B
Score: 35 Letter grade: F
Score: 99 Letter grade: A
Score: 78 Letter grade: C
Using this template
Include Irvine32.inc
A_grade = 90 ;the minimum score to get an A (can be changed according to the grading scale used)
B_grade = 80 ;the minimum score to get a B (can be changed according to the grading scale used)
C_grade = 70 ;the minimum score to get a C (can be changed according to the grading scale used)
D_grade = 60 ;the minimum score to get a D (can be changed according to the grading scale used)
.data
prompt1 BYTE "Enter the output filename: ", 0
prompt2 BYTE "Enter the number of inputs (must be at least 1): ", 0
prompt3 BYTE "Enter a score (must be 0 - 100): ", 0
filename BYTE 50 dup(?)
score BYTE 10 dup (?) ; scores entered by the user are read in as strings. For example,
; 100 is read in as the string "100".
; The function ParseInteger32 needs to be used to convert the string
; to the equivalent 32-bit number (DWORD)
; The string is used to write the number to the output file
num_of_digits DWORD ? ; for each number, we need to know the number of digits in that number
; so it can be written to the file correctly
letter_grade BYTE ? ; stores the letter grade ('A', 'B', 'C', 'D', or 'F')
msg_score BYTE "Score: ", 0
msg_grade BYTE " Letter grade: ", 0
msg_end BYTE "The results have been written to the output file: ", 0
line_return BYTE 0Dh, 0Ah
file_handle DWORD ?
.code
main proc
call get_filename
call Crlf
call CreateOutputFile
mov file_handle, eax
call get_num_of_inputs
call Crlf
L1:
push ecx ; save the value of ecx before calling other functions
call get_score
call calculate_grade
call write_file
pop ecx ; restore ecx to it's original value before the loop instruction
loop L1
call Crlf
mov eax, file_handle
call CloseFile
call display_output
invoke ExitProcess, 0
main endp
get_filename proc
mov edx, OFFSET prompt1
call WriteString
mov edx, OFFSET filename
mov ecx, LENGTHOF filename
call ReadString
ret
get_filename endp
get_num_of_inputs proc
mov edx, OFFSET prompt2
L1: call WriteString
call ReadInt ; the user's input is in eax
cmp eax, 1 ; if the users input is less than 1, jump back to label L1 and prompt the user again
jl L1 ; this is a do-while loop in assembly
; jl means "jump is the destination is less than the source"
mov ecx, eax ;setup ecx to prepare for the loop in main
; the result is returned to main through ecx
ret
get_num_of_inputs endp
get_score proc
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
get_score endp
calculate_grade proc
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
calculate_grade endp
write_file proc
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
write_file endp
display_output proc
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
; IMPLEMENT THIS PROCEDURE
display_output endp
end main
Sample Run 1
Enter the output filename: Scores.txt
Enter the number of inputs (must be at least 1): -1
Enter the number of inputs (must be at least 1): -99
Enter the number of inputs (must be at least 1): 0
Enter the number of inputs (must be at least 1): 6
Enter a score (must be 0 – 100): -1
Enter a score (must be 0 – 100): 101
Enter a score (must be 0 – 100): 150
Enter a score (must be 0 – 100): 92
Enter a score (must be 0 – 100): 86
Enter a score (must be 0 – 100): 75
Enter a score (must be 0 – 100): 62
Enter a score (must be 0 – 100): 41
Enter a score (must be 0 – 100): 97
The results have been written to the output file: Scores.txt
Sample run 2
Enter the output filename: Scores.txt
Enter the number of inputs (must be at least 1): -1
Enter the number of inputs (must be at least 1): -99
Enter the number of inputs (must be at least 1): 0
Enter the number of inputs (must be at least 1): 6
Enter a score (must be 0 – 100): -1
Enter a score (must be 0 – 100): 101
Enter a score (must be 0 – 100): 150
Enter a score (must be 0 – 100): 92
Enter a score (must be 0 – 100): 86
Enter a score (must be 0 – 100): 75
Enter a score (must be 0 – 100): 62
Enter a score (must be 0 – 100): 41
Enter a score (must be 0 – 100): 97
The results have been written to the output file: Scores.txt
Scores.txt-Notepad
Score: 92 Letter grade: A
Score: 86 Letter grade: B
Score: 75 Letter grade: C
Score: 62 Letter grade: D
Score: 41 Letter grade: F
Score: 97 Letter grade: A
Sample Run 2
Enter the output filename: Scores2.txt
Enter the number of inputs (must be at least 1): -2
Enter the number of inputs (must be at least 1): -5
Enter the number of inputs (must be at least 1): 0
Enter the number of inputs (must be at least 1): 7
Enter a score (must be 0 – 100): -100
Enter a score (must be 0 – 100): 95
Enter a score (must be 0 – 100): -25
Enter a score (must be 0 – 100): -20
Enter a score (must be 0 – 100): 64
Enter a score (must be 0 – 100): -87
Enter a score (must be 0 – 100): 75
Enter a score (must be 0 – 100): -2
Enter a score (must be 0 – 100): 82
Enter a score (must be 0 – 100): 250
Enter a score (must be 0 – 100): 35
Enter a score (must be 0 – 100): 300
Enter a score (must be 0 – 100): 450
Enter a score (must be 0 – 100): 99
Enter a score (must be 0 – 100): 900
Enter a score (must be 0 – 100): 78
The results have been written to the output file: Scores2.txt
Scores2.txt-Notepad
Score: 95 Letter grade: A
Score: 64 Letter grade: D
Score: 75 Letter grade: C
Score: 82 Letter grade: B
Score: 35 Letter grade: F
Score: 99 Letter grade: A
Score: 78 Letter grade: C
Explanation / Answer
import javafx.scene.image.*;
open class Card executes Comparable<Card>{
private static last String IMAGE_FOLDER_DIR = "picture";
private static last String IMAGE_FORMAT = ".png";
private static last String BACK_IMAGE_DIR = ("picture/back_image.png");
private Image cardImage;
private Image backImage;
private SuitEnum suit;
private RankEnum rank;
open Card(){
}
open Card(SuitEnum suit, RankEnum rank){
this.suit = suit;
this.rank = rank;
String area = generateImageLocation();
attempt {
cardImage = new Image(location);
} get (Exception ex) {
System.out.println(String.format("cannot stack picture from: (%s)", area));
cardImage = invalid;
}
attempt {
backImage = new Image(BACK_IMAGE_DIR);
} get (Exception ex){
System.out.println(String.format("cannot stack picture from: (%s)", BACK_IMAGE_DIR));
backImage = invalid;
}
}
open SuitEnum getSuit() {
return suit;
}
open RankEnum getRank() {
return rank;
}
open Image getCardImage(){
return cardImage;
}
private String generateImageLocation(){
StringBuilder sb = new StringBuilder();
sb.append(IMAGE_FOLDER_DIR);
sb.append("/");
sb.append(suit.toString());
sb.append("_");
sb.append(rank.toString());
sb.append(IMAGE_FORMAT);
return sb.toString().toLowerCase();
}
@Override
open String toString(){
return (suit + " + rank);
}
open int compareTo(Card card) {
on the off chance that (this.rank.compareTo(card.rank) > 0){
return 1;
} else if (this.rank.compareTo(card.rank) < 0){
return - 1;
} else {
if(this.suit.compareTo(card.suit) > 0){
return 1;
} else if (this.suit.compareTo(card.suit) < 0){
return - 1;
} else {
return 0;
}
}
}
@Override
open int hashCode() {
last int prime = 31;
int result = 1;
result = prime * result + ((rank == invalid) ? 0 : rank.hashCode());
result = prime * result + ((suit == invalid) ? 0 : suit.hashCode());
return result;
}
@Override
open boolean equals(Object obj) {
on the off chance that (this == obj)
return genuine;
on the off chance that (obj == invalid)
return false;
in the event that (getClass() != obj.getClass())
return false;
Card other = (Card) obj;
in the event that (rank != other.rank)
return false;
on the off chance that (suit != other.suit)
return false;
return genuine;
}
open Image getBackImage() {
return backImage;
}
Deck Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.