【发布时间】:2016-01-20 19:57:35
【问题描述】:
我在使用这个程序时遇到了问题,不知道是什么问题。在这个“猜数字游戏”中,用户告诉游戏的最小数字和最大数字范围。然后用户告诉他有多少机会玩。
有两个主要问题: 1.循环计数器不起作用 2. 我的条件跳转行为很少见。
请注意,我将 Irvine 库用于此装配程序。 需要帮助,我需要让它工作。非常感谢!!! 代码如下:
; Asignación Gabriel E. Rosario
INCLUDE Irvine32.inc
.data
; MSG
startMsg BYTE "Saludos! Tienes que adivinar un numero escondido.",0
minMsg BYTE "Dame el valor minimo a adivinar: ",0
maxMsg BYTE "Dame el valor maximo a adivinar: ",0
intentos BYTE "Cuantos intentos deseas para adivinar este numero? ",0
esMenor BYTE "El numero es menor ",0
esMayor BYTE "El numero es mayor ",0
tienes BYTE "Tienes ",0
adivina BYTE " intentos. Adivina el numero: ",0
won BYTE "Felicidades, Adivinastes!!!",0
loss BYTE "Perdistes.",0
over BYTE "Juego Terminado",0
; Empty variables
minNum BYTE ?
maxNum BYTE ?
randomNumber BYTE ?
myNumber BYTE ?
loopCounter BYTE ?
.code
main proc
call Randomize
; ============== Saludos ================
mov edx, offset startMsg
call writeString
call Crlf
; ============== Give MinValue ================
mov edx, offset minMsg
call writeString
call readInt
mov minNum, al
; ============== Give MaxValue ================
mov edx, offset maxMsg
call writeString
call readInt
mov maxNum, al
;============ Opportunities ==================
mov edx, offset intentos
call writeString
call readInt
mov loopCounter, al
call Crlf
;============= Make random num and save it =============
call Range ; calling Range function
call RandomRange
add al, minNum
mov randomNumber, al
; ======= Call the big baby :) ======
call Looper
Losser: ; Display if you loose
mov edx, offset loss
call writeString
call Crlf
call WaitMsg
invoke ExitProcess,0
main endp
Menor:
mov edx, offset esMenor
call writeString
call Looper
call Crlf
Mayor:
mov edx, offset esMayor
call writeString
call Looper
call Crlf
Winner:
mov edx, offset won
call writeString
jmp Done
call Crlf
Done:
mov edx, offset over
call readString
call Crlf
; =============== funciones =============
Looper proc
; Cuantos intentos tienes?
movzx ecx, loopCounter
MSG_Intentos:
mov edx, offset tienes
call writeString
mov eax, ecx
call writeDec
mov edx, offset adivina
call writeString
;========= escribir numero =================
call readInt
mov myNumber, al
call Compara
loop MSG_Intentos
ret
Looper endp
Compara proc
mov myNumber, al
mov bl, myNumber
cmp bl, randomNumber
call Jumps
ret
Compara endp
Jumps proc ; These aren't working so well, don't know why...
jg Menor
jl Mayor
je Winner
ret
Jumps endp
Range proc
movzx eax, maxNum
sub al, minNum
inc eax
ret
Range endp
end main
; Formula para sacar el range.
; Range = (max - min) + 1
【问题讨论】:
-
我建议在调试器中单步执行您的代码,以了解哪里可能出错。使用调试器是一种有价值的开发工具,可以提高您对事物可能工作或可能不工作的认识。您的代码不会太长,因此您应该能够轻松地逐个语句地单步执行它。
标签: loops assembly procedure masm irvine32