Assemlby语言猜数字游戏

时间:2015-10-21 17:36:31

标签: loops assembly procedure masm irvine32

我遇到了这个程序的问题,不知道是什么问题。在这个“猜数字游戏”中,用户告诉游戏的最小数量和最大数量范围。然后用户告诉他必须玩多少机会。

有两个主要问题: 1.循环计数器不起作用 我的条件跳跃表现很少。

请注意,我正在将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

1 个答案:

答案 0 :(得分:1)

  
      
  1. 循环计数器不起作用
  2.   
Menor:
mov edx, offset esMenor
call writeString
;;;;;;;;;;;;;;;;;;;;;;;;;;call Looper
call Crlf
RET

Mayor:
mov edx, offset esMayor
call writeString
;;;;;;;;;;;;;;;;;;;;;;;;;;call Looper
call Crlf
RET

您无法从这两个代码中调用 Looper !只需ret即可让您回到自己的循环中。

  
      
  1. 我的条件跳跃行为很少
  2.   
Compara proc
 mov myNumber, al
 mov bl, myNumber
 cmp bl, randomNumber
 jl Menor ;;;;;;;;jg Menor
 jg Mayor ;;;;;;;;jl Mayor
 je Winner
 ret
Compara endp

使用其他条件跳转,不要将标志的解释放在不同的过程中。不需要在程序入口处定义标志!