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 x assembly program implements a simple guessing game where the user tries to guess a random number between and 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 and :
correctmsg db 'Congratulations! You guessed the correct number.
wrongmsg db 'Wrong guess. The correct number was:
newline db
section text
global start
; Function to convert ASCII to integer
; Input: ecx pointer to the ASCII string
; Output: eax integer value
asciitoint:
xor eax, eax ; Clear eax to store the result
convertdigit:
movzx edx, byte ecx ; Load the next character
cmp edx, ; Check for null terminator
je doneconversion ; If null terminator, conversion is done
sub edx, ; Convert ASCII to integer
imul eax, ; Multiply the current result by
add eax, edx ; Add the current digit
inc ecx ; Move to the next character
jmp convertdigit
doneconversion:
ret
start:
; Display prompt
mov eax,
mov ebx,
mov ecx, prompt
mov edx,
int x
; Generate a random number between and
mov eax, ; syscall for get random number
xor ebx, ebx ; no flags
mov ecx, ; maximum value exclusive
int x
add eax, ; ensure the number is between and
mov correctnumber eax ; store the correct number
; Read user input
mov eax,
mov ebx,
mov ecx, userguess
mov edx,
int x
; Convert ASCII to integer
lea ecx, userguess
call asciitoint
mov ebx, eax
; Compare user's guess with the generated number
cmp ebx, correctnumber
je correctguess
jmp wrongguess
correctguess:
; Display correct message
mov eax,
mov ebx,
mov ecx, correctmsg
mov edx,
int x
jmp endprogram
wrongguess:
; Display wrong message
mov eax,
mov ebx,
mov ecx, wrongmsg
mov edx,
int x
; Display the correct number
mov eax, correctnumber
add eax, ; convert integer to ASCII
mov edx,
mov ebx,
mov ecx, eax
int x
; Display newline character
mov eax,
mov ebx,
mov ecx, newline
mov edx,
int x
jmp start
endprogram:
; Exit program
mov eax,
xor ebx, ebx
int x
section bss
userguess resb
correctnumber resb
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
