Question: HELLO, This x 8 6 assembly program implements a simple guessing game where the user tries to guess a random number between 1 and 1

HELLO, This x86 assembly program implements a simple guessing game where the user tries to guess a random number between 1 and 10. The program generates a random number, prompts the user for input, compares it with the correct number, and provides feedback. If the guess is correct, a congratulatory message is displayed; otherwise, the program reveals the correct number. The code uses Linux system calls and stores the correct number in a variable for comparison. But unfornltunalty it keeps revealing the wrong guess as Correct when you it wrong. can you please fix the issue? PLEASE RUN IT in order to have a better understanding of the isssue and the expectation. HERE IS THE CODE: section .data
prompt db 'Guess the number between 1 and 10: ',0
correct_msg db 'Congratulations! You guessed the correct number.',0
wrong_msg db 'Wrong guess. The correct number was: ',0
newline db 10
section .text
global _start
; Function to convert ASCII to integer
; Input: ecx - pointer to the ASCII string
; Output: eax - integer value
ascii_to_int:
xor eax, eax ; Clear eax to store the result
convert_digit:
movzx edx, byte [ecx] ; Load the next character
cmp edx, 0 ; Check for null terminator
je done_conversion ; If null terminator, conversion is done
sub edx, '0' ; Convert ASCII to integer ('0'->0,'1'->1,...,'9'->9)
imul eax, 10 ; Multiply the current result by 10
add eax, edx ; Add the current digit
inc ecx ; Move to the next character
jmp convert_digit
done_conversion:
ret
_start:
; Display prompt
mov eax, 4
mov ebx, 1
mov ecx, prompt
mov edx, 37
int 0x80
; Generate a random number between 1 and 10
mov eax, 22 ; syscall for get random number
xor ebx, ebx ; no flags
mov ecx, 10 ; maximum value (exclusive)
int 0x80
add eax, 1 ; ensure the number is between 1 and 10
mov [correct_number], eax ; store the correct number
; Read user input
mov eax, 3
mov ebx, 0
mov ecx, user_guess
mov edx, 2
int 0x80
; Convert ASCII to integer
lea ecx, [user_guess]
call ascii_to_int
mov ebx, eax
; Compare user's guess with the generated number
cmp ebx, [correct_number]
je correct_guess
jmp wrong_guess
correct_guess:
; Display correct message
mov eax, 4
mov ebx, 1
mov ecx, correct_msg
mov edx, 47
int 0x80
jmp end_program
wrong_guess:
; Display wrong message
mov eax, 4
mov ebx, 1
mov ecx, wrong_msg
mov edx, 41
int 0x80
; Display the correct number
mov eax, [correct_number]
add eax, '0' ; convert integer to ASCII
mov edx, 1
mov ebx, 1
mov ecx, eax
int 0x80
; Display newline character
mov eax, 4
mov ebx, 1
mov ecx, newline
mov edx, 1
int 0x80
jmp _start
end_program:
; Exit program
mov eax, 1
xor ebx, ebx
int 0x80
section .bss
user_guess resb 2
correct_number resb 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!