Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Guessuing_Game/gusessing_game.asm
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
300 lines (230 sloc)
7.99 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section .data | |
;Welcome message for game | |
;Welcome message size | |
welcome_msg db "Welcome to population guessing game you caan choose between h/l for the game ", 10 | |
welcomeLen equ $-welcome_msg | |
victorymsg db " Victory to population guessing game", 10 | |
victorymsglen equ $-victorymsg | |
;msg that the guess is correct | |
;Size of the msg | |
correct db "You guess correctly. They are the Correct. ",10 | |
correctlen equ $-correct | |
;Msg that the guess is incorrect | |
;Size of the Msg | |
incorrect db "Your guess is incorrect. They are not the Correct: ", 10 | |
incorrectlen equ $-incorrect | |
;Message that the guess is question | |
;Size of the questions | |
question1 db "is population in china is higher than india[h/l] :" | |
question1len equ $-question1 | |
question2 db "is population in china is higher than USA[h/l] :" | |
question2len equ $-question2 | |
question3 db "is population in china is higher than UK[h/l]. :" | |
question3len equ $-question3 | |
question4 db "is population in china is higher than France[h/l]. :" | |
question4len equ $-question4 | |
question5 db "is population in india is higher than china[h/l]. :" | |
question5len equ $-question5 | |
question6 db "is population in india is higher than UK[h/l]. :" | |
question6len equ $-question6 | |
question7 db "is population in india is higher than USA[h/l]. :" | |
question7len equ $-question7 | |
question8 db "is population in india is higher than France[h/l]. :" | |
question8len equ $-question8 | |
question9 db "is population in USA is higher than UK[h/l] :" | |
question9len equ $-question9 | |
question10 db "is population in France is higher than UK[h/l] :" | |
question10len equ $-question10 | |
; Msg explaining the t_letter | |
; Msg Size | |
letter_msg db "the correct answer was " | |
letter_msglen equ $-letter_msg | |
; msg explaining the Inc_msg | |
; Msg Size | |
Inc_msg db " the score now is " | |
Inc_msglen equ $-Inc_msg | |
;newline | |
cr db 10 | |
inc_value db 0 ; the value of thst will be incremented for the storing points | |
global list_questions | |
list_questions: | |
; the pointer to the quotes are stored in 8 bytes | |
dq question1 | |
dq question2 | |
dq question3 | |
dq question4 | |
dq question5 | |
dq question6 | |
dq question7 | |
dq question8 | |
dq question9 | |
dq question10 | |
global list_answers | |
list_answers: | |
dq 'h' | |
dq 'h' | |
dq 'h' | |
dq 'h' | |
dq 'l' | |
dq 'h' | |
dq 'h' | |
dq 'h' | |
dq 'h' | |
dq 'l' | |
t_letter: | |
; we store each of the answers 1 at a time | |
dq 0 | |
segment .bss | |
; store the users guess | |
guess resb 1 | |
section .text | |
global _start ;must be declared for linker (ld) | |
_start: | |
call Welcome_dis | |
call new_line | |
mov rax,10 ;no of ans | |
mov rbx,0 ;rbx will store the ans | |
mov rcx,list_answers ; rcx will point to the curr element to be processed | |
mov rdx,0 ; rbx willstore the question | |
mov rsi,list_questions ;move list of questions to rcx | |
top: | |
mov rbx,[rcx] ; put the current use in register rbx | |
mov [t_letter],rbx ; move rbx into a variable t_letter and store curr guess | |
push rax ; push the val to stack | |
push rcx ; push the val to stack | |
call new_line | |
call Questions_dis ; Display the questions | |
call Inp_letter ; input from the users guess | |
call letter_msg_dis ; msg for correct msg | |
call Display ; print the t_letter that | |
call new_line ; new line like endl | |
call Victorymsg | |
mov eax,[inc_value] ;moving inc_value to eax register | |
add eax,48 ;convert the integer into ascii value to print | |
mov [inc_value],eax ;Put the val back variable in th register | |
;writing code to the increment statement to screen. | |
mov eax, 4 ;Syst call for the scrn call the scrn | |
mov ebx, 1 ; standarded out | |
mov ecx,Inc_msg ;print inc of msg message | |
mov edx, Inc_msglen ;Length of the message | |
int 80h ;syst int | |
;write the code incremented value to screen. | |
mov eax, 4 ;Sys call the scrn | |
mov ebx, 1 ; sys stand out | |
mov ecx, inc_value ; print the inc_va;ue | |
mov edx, 1 ; 1 byte in size | |
int 80h ; int | |
mov eax, [inc_value] ; move the inc_value variable in eax | |
add eax, -48 ; convert the integer into ascii val to print | |
mov [inc_value], eax ; Put the val back variable | |
;write the code incremented value to screen | |
mov eax, 4 ; Sys call the scrn | |
mov ebx, 1 ; stand out | |
mov ecx, cr ; newline | |
mov edx,1 ; 1 byte in size | |
int 80h ; int | |
pop rcx ; get back from stack | |
pop rax ; get back from stack | |
add rcx,8 ;move pointer to next element as 8 bits for each cove on by 8 | |
add rsi,8 | |
dec rax ;decrement counter so going down | |
jnz top ;if counter not equal O, then we loop again | |
call done ;end of the program | |
Display: | |
mov edx,1 ;msg length | |
mov ecx, t_letter ;msg to write the t_letter to be predicted | |
mov ebx, 1 ;making file descriptor | |
mov eax, 4 ;sys call number | |
int 0x80 ;calling kernel | |
ret | |
;function to read the user guess and comp with the ans | |
Inp_letter: | |
mov eax, 3 ; readinng from the keyboard | |
mov ebx, 2; | |
mov ecx, guess ; move the guess into the ecx | |
mov edx, 1 ; As single t_letter using 1 byte | |
int 80h ; call int | |
mov rax, [guess] ; move guess by user into rax | |
cmp rax, [t_letter] ; compare correct answer with what in rax | |
je Correct ; if guess was correct jump to Correct function | |
call Inc_correct ; if the guess is incorrect then go to Inc_correct function | |
ret | |
;function to show message that answer was not correct answer | |
Inc_correct: | |
mov ecx,incorrect ; Not Correct msg | |
mov edx, incorrectlen ; length of Correct msg | |
mov ebx,1 ;file descriptors | |
mov eax,4 ;sys calling num | |
int 80h | |
mov eax, 3 ; read pre enter key entry | |
mov ebx, 2; | |
mov ecx, guess ; pre key doesnot messy up the loop | |
mov edx, 1 ; As single t_letter 1 byte | |
int 80h ; calling int | |
ret | |
; function to show message answer was correct | |
Correct: | |
mov ecx,correct ; Correct msg | |
mov edx, correctlen ; length of Correct msg | |
inc byte [inc_value] ; incre value of values | |
mov ebx,1 ;file descript | |
mov eax,4 ;sys calling number | |
int 80h | |
mov eax, 3 ; read previous enter key d | |
mov ebx, 2; | |
mov ecx, guess ; press so it doesnot messy up loop | |
mov edx, 1 ; single t_letter 1 byte | |
int 80h ; calling int | |
ret | |
; Function to create a New line | |
new_line: | |
mov eax,4 ; call for write (sys_write) | |
; | |
mov ebx,1 ; output to the screen | |
; | |
mov ecx, cr ; newline value into ecx | |
mov edx, 1 ; length of the newline edx | |
; | |
int 80h ; Call the kernel with interrupt to check the | |
; | |
; | |
ret ; | |
Welcome_dis: | |
mov edx,welcomeLen ;msg length | |
mov ecx, welcome_msg ;msg to write | |
mov ebx, 1 ; making file descriptor | |
mov eax, 4 ;sys call number | |
int 0x80 ;calling kernel | |
ret | |
Victorymsg: | |
mov edx,victorymsglen ;msg length | |
mov ecx,victorymsg ;msg to write | |
mov ebx, 1 ;making file descriptor | |
mov eax, 4 ;sys call number | |
call done | |
int 0x80 ;calling kernel | |
call done | |
ret | |
;Function to Display question for quiz | |
Questions_dis: | |
;msg length | |
mov edx,50 | |
mov ecx, [rsi] ;msg to write | |
mov ebx, 1 ;making file descrptor | |
mov eax, 4 ;sys call number | |
int 0x80 ;calling kernel | |
ret | |
; Function to Display the correct answer sentence | |
letter_msg_dis: | |
;message length | |
mov edx,letter_msglen | |
;message to write | |
mov ecx, letter_msg | |
mov ebx, 1 ;file descriptor (stdout) | |
mov eax, 4 ;cmd system call number | |
int 0x80 ;calling kernel | |
ret | |
; Function to end the program | |
done: | |
mov eax, 1 ;cmd sys call number | |
int 0x80 ;calling kernel |