I'm writing a rock, paper, scissors game and having some issues.  This is my error when debugging: Unhandled exception at 0x00000002 in Project.exe: 0xC0000005: Access violation. I get the error right after the Play procedure is executed.

If anyone could take a look.  I would appreciate it!  :)


INCLUDE Irvine32.inc




.data

intro BYTE "Rock = 1, Paper = 2, Scissors = 3",0
prompt1 BYTE "Player 1: ",0
prompt2 BYTE "Player 2: ",0
point1 BYTE "Points for Player 1: ",0
point2 BYTE "Points for Player 2: ",0
win1 BYTE "Player 1 wins!",0
win2 BYTE "Player 2 Wins!",0
ties BYTE "Ties: ",0
tied BYTE "Its a tie!",0

var BYTE 4 ;variable to access stack parameters

.code

main PROC

mov edx, OFFSET intro
call WriteString
call crlf
call crlf
call Play

call CalcTotal

mov edx, OFFSET point1
call WriteString ;Display points for player 1
call WriteDec
mov eax, ebx
mov edx, OFFSET point2
call WriteString ;Display points for player 2
call WriteDec
mov eax, ecx
mov edx, OFFSET ties ;Display ties
call WriteString
call WriteDec

.IF eax > ebx ;Compare to see who wins
mov edx, OFFSET win1
call WriteString
.ELSEIF eax < ebx
mov edx, OFFSET win2
call WriteString
.ELSE
mov edx, OFFSET tied
call WriteString
.ENDIF



exit
main ENDP

;-------------------------------------------------------------------------------------
Play PROC
;Prompts for the players rock, paper or scissors 10 times.
;Receives: Nothing
;Returns: 20 values on the stack
;-------------------------------------------------------------------------------------
mov ecx, 10


L1:
PMT1:
mov edx, OFFSET prompt1
call WriteString ;prompts player 1 for move
call ReadDec
.IF eax < 1 || eax > 3
jmp PMT1
.ENDIF
push eax ;puts the first value on the stack
PMT2:
mov edx, OFFSET prompt2
call WriteString ;prompts player 2 for move
call ReadDec
.IF eax < 1 || eax > 3
jmp PMT2
.ENDIF
push eax ;puts the second value on the stack
call crlf
loop L1 ;loops 10x
ret
Play ENDP

;-----------------------------------------------------------------------------------
CalcTotal PROC
;Accesses vales entered by players, compares them and gives points to winning player
;Receives: 20 values on stack as parameters
;Returns: eax, ebx, ecx as number of wins
;-----------------------------------------------------------------------------------
mov esi, 10         ;loop counter
mov eax, 0
push ebp
mov esp, ebp ;ebp set as base pointer
mov , al ;set accumlator for ties
mov , al ;set accumulator for player 1s points
mov , al ;set accumulator for player 2s points
L1:
add var, 4
mov al, ;mov player 2s choice to al
add var, 4
mov dl, ;mov player 1s choice to dl
.IF al == 1 && dl == 1 ;compare for points
jmp TIE
.ELSEIF al == 1 && dl == 2
jmp PLAY1PT
.ELSEIF al == 1 && dl == 3
jmp PLAY2PT
.ELSEIF al == 2 && dl == 2
jmp TIE
.ELSEIF al == 2 && dl == 1
jmp PLAY2PT
.ELSEIF al == 2 && dl == 3
jmp PLAY1PT
.ELSEIF al == 3 && dl == 3
jmp TIE
.ELSEIF al == 3 && dl == 1
jmp PLAY1PT
.ELSEIF al == 3 && dl == 2
jmp PLAY2PT
.ENDIF

TIE:
inc DWORD PTR ;increment score values
jmp HERE
PLAY1PT:
inc DWORD PTR ; ""
jmp HERE
PLAY2PT:
inc DWORD PTR ; ""
HERE:
sub esi, 1
jnz L1

mov ecx,
mov eax,
mov ebx,

mov esp, ebp
pop ebp
ret 80 ;clean up the stack
CalcTotal ENDP


END main
Posted on 2011-05-01 21:27:51 by k33N67

push eax
call crlf
loop L1


Looks like you're pushing eax (10 times!) and never popping it, so "Play" isn't going to "ret" properly. Why are you pushing eax?

Best,
Frank


Posted on 2011-05-02 03:03:02 by fbkotler
and some of the functions are trashing registers used in the main loop (ecx for instance)
Posted on 2011-05-02 03:08:50 by evlncrn8


push eax
call crlf
loop L1


Looks like you're pushing eax (10 times!) and never popping it, so "Play" isn't going to "ret" properly. Why are you pushing eax?

Best,
Frank



l


Part of the instruction is to use only one variable throughout the program, so I used the stack to preserve the user input values to later access and compare them in CalcTotal. 
Posted on 2011-05-02 07:33:23 by k33N67