Jump to content

Recommended Posts

I noticed that this line..

if player2y < player1y && player1y < player2y + 24 then _wait
outputs this assembly
LDA player2y
CMP player1y
BCS .skipL01207
; complex condition detected
LDA player2y
CLC
ADC #24
PHA
TSX
PLA
LDA player1y
CMP 1,x
if ((* - ._wait) < 127) && ((* - ._wait) > -128)
bcc ._wait
else
bcs .20skip_wait
jmp ._wait
.20skip_wait
endif
.skipL01207
what does this do and why?
PHA
TSX
PLA
LDA player1y
CMP 1,x

 

Is that why you should use <= and >= instead?

My wild guess is that there either isn't a smaller then or bigger then in assembly, that one of them also checks if equal to, so that part adds 1 to compensate for that?

Link to comment
https://forums.atariage.com/topic/286002-bb-to-assembly-question/
Share on other sites

Have you tried experimenting with flipping the second condition around?

 

Try:

if player2y < player1y && player2y + 24 > player1y then _wait

 

and look at the code that produces.

 

 

what does this do and why?
PHA
TSX
PLA
LDA player1y
CMP 1,x

 

Is that why you should use <= and >= instead?

My wild guess is that there either isn't a smaller then or bigger then in assembly, that one of them also checks if equal to, so that part adds 1 to compensate for that?

 

The code puts a copy of A, which is the result of player2y+24), onto the stack. Then performs the comparison with player1y.

PHA TSX PLA -- puts A on the stack and puts the stack pointer into X and then "pops" A from the stack... A still exists on the stack since pop only reads the value and moves the stack pointer without clearing that spot.

 

CMP 1,x access that copy of A on the stack using the saved pointer which needs 1 added since the stack pointer always points at the next available spot and not the last value added.

 

If TSX was moved outside of the PHA PLA then it would be CMP 0,x instead.

 

 

To answer the other portion of your last question, < and >= are the simplest cases to handle in assembly (equal and not equal are also simple cases).

 

For good information about doing comparisons in assembly:

http://6502.org/tutorials/compare_instructions.html

 

Hopefully I explained that clearly enough :)

  • Like 1

Thanks for the quick and detailed info!

 

I will try changing it around next time I encounter it, I changed it to this which seems to work fine

 

asm
LDA player2y
CMP player1y
BCS .skipwait
CLC
ADC #24
CMP player1y
bcs ._wait
.skipwait
end

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...