computer _ student
شنبه 24 دی 1390, 19:44 عصر
سلام
من یک برنامه بازی اسمبلی دارم که به این صورته:
بازیکن اول یک عدد حدس میزنه و بازیکن دوم بر اساس راهنمایی هایی که برنامه بهش میده (مثلا عدد حدس زده شده شما کوچکتر و یا بزرگتر است) عدد را حدس می زند.
حالا باید این برنامه را طوری تغییر بدم که player2 فقط قادر به 10 بار حدس زدن باشه
این کار را با یک مقایسه ساده بر روی تعداد حدس ها (که در cx ذخیره می شود) انجام دادم اما برنامه هیچ عکس العملی به این شرط نشان نمی دهد
باید چه کار کنم؟
; program to implement number guessing game
; author: R. Detmer
; date: revised 9/97
.386
.MODEL FLAT
INCLUDE io.h
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
cr EQU 0dh ; carriage return character
Lf EQU 0ah ; linefeed character
.STACK 4096 ; reserve 4096-byte stack
.DATA ; reserve storage for data
prompt1 BYTE cr,Lf,Lf,"Player 1, please enter a number: ", 0
target DWORD ?
clear BYTE 24 DUP (Lf), 0
prompt2 BYTE cr,Lf,"Player 2, your guess? ", 0
stringIn BYTE 20 DUP (?)
lowOutput BYTE "too low", cr, Lf, 0
highOutput BYTE "too high", cr, Lf, 0
gotItOutput BYTE "you got it", cr, Lf, 0
countLabel BYTE Lf, "Number of guesses:"
countOut BYTE 6 DUP (?)
BYTE cr, Lf, Lf, Lf, "Do you want to play again? ",0
higher10 BYTE "sorry,number of gusses is higher than 10", cr,Lf, 0
.CODE ; start of main program code
_start:
untilDone: output prompt1 ; ask player 1 for target
input stringIn, 20 ; get number
atod stringIn ; convert to integer
mov target,eax ; store target
output clear ; clear screen
mov cx, 0 ; zero count
untilMatch: inc cx ; increment count of guesses
cmp cx,10
je l1
mov DI,0
output prompt2 ; ask player 2 for guess
input stringIn, 20 ; get number
atod stringIn ; convert to integer
INC DI
cmp eax, target ; compare guess and target
jne ifLess ; guess = target ?
equal: output gotItOutput ; display "you got it"
jmp endCompare
ifLess: jnl isGreater ; guess < target ?
output lowOutput ; display "too low"
jmp endCompare
isGreater: output highOutput ; display "too high"
endCompare:
cmp eax, target ; compare guess and target
cmp DI,4
ja endUntilDone
jne untilMatch ; ask again if guess not = target
l1: output higher10
itoa countOut, cx ; convert count to ASCII
output countLabel ; display label, count and prompt
input stringIn, 20 ; get response
cmp stringIn, 'n' ; response = 'n' ?
je endUntilDone ; exit if so
cmp stringIn, 'N' ; response = 'N' ?
jne untilDone ; repeat if not
endUntilDone:
output gameover
INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start ; make entry point public
END ; end of source code
من یک برنامه بازی اسمبلی دارم که به این صورته:
بازیکن اول یک عدد حدس میزنه و بازیکن دوم بر اساس راهنمایی هایی که برنامه بهش میده (مثلا عدد حدس زده شده شما کوچکتر و یا بزرگتر است) عدد را حدس می زند.
حالا باید این برنامه را طوری تغییر بدم که player2 فقط قادر به 10 بار حدس زدن باشه
این کار را با یک مقایسه ساده بر روی تعداد حدس ها (که در cx ذخیره می شود) انجام دادم اما برنامه هیچ عکس العملی به این شرط نشان نمی دهد
باید چه کار کنم؟
; program to implement number guessing game
; author: R. Detmer
; date: revised 9/97
.386
.MODEL FLAT
INCLUDE io.h
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
cr EQU 0dh ; carriage return character
Lf EQU 0ah ; linefeed character
.STACK 4096 ; reserve 4096-byte stack
.DATA ; reserve storage for data
prompt1 BYTE cr,Lf,Lf,"Player 1, please enter a number: ", 0
target DWORD ?
clear BYTE 24 DUP (Lf), 0
prompt2 BYTE cr,Lf,"Player 2, your guess? ", 0
stringIn BYTE 20 DUP (?)
lowOutput BYTE "too low", cr, Lf, 0
highOutput BYTE "too high", cr, Lf, 0
gotItOutput BYTE "you got it", cr, Lf, 0
countLabel BYTE Lf, "Number of guesses:"
countOut BYTE 6 DUP (?)
BYTE cr, Lf, Lf, Lf, "Do you want to play again? ",0
higher10 BYTE "sorry,number of gusses is higher than 10", cr,Lf, 0
.CODE ; start of main program code
_start:
untilDone: output prompt1 ; ask player 1 for target
input stringIn, 20 ; get number
atod stringIn ; convert to integer
mov target,eax ; store target
output clear ; clear screen
mov cx, 0 ; zero count
untilMatch: inc cx ; increment count of guesses
cmp cx,10
je l1
mov DI,0
output prompt2 ; ask player 2 for guess
input stringIn, 20 ; get number
atod stringIn ; convert to integer
INC DI
cmp eax, target ; compare guess and target
jne ifLess ; guess = target ?
equal: output gotItOutput ; display "you got it"
jmp endCompare
ifLess: jnl isGreater ; guess < target ?
output lowOutput ; display "too low"
jmp endCompare
isGreater: output highOutput ; display "too high"
endCompare:
cmp eax, target ; compare guess and target
cmp DI,4
ja endUntilDone
jne untilMatch ; ask again if guess not = target
l1: output higher10
itoa countOut, cx ; convert count to ASCII
output countLabel ; display label, count and prompt
input stringIn, 20 ; get response
cmp stringIn, 'n' ; response = 'n' ?
je endUntilDone ; exit if so
cmp stringIn, 'N' ; response = 'N' ?
jne untilDone ; repeat if not
endUntilDone:
output gameover
INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start ; make entry point public
END ; end of source code