Jump to content

Photo

bB to assembly question


2 replies to this topic

#1 Lillapojkenpćön OFFLINE  

Lillapojkenpćön

    Chopper Commander

  • 155 posts

Posted Fri Dec 14, 2018 6:26 AM

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?



#2 splendidnut OFFLINE  

splendidnut

    Chopper Commander

  • 130 posts
  • Location:PA/NY Border

Posted Fri Dec 14, 2018 6:54 AM

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/tuto...structions.html

 

Hopefully I explained that clearly enough :)



#3 Lillapojkenpćön OFFLINE  

Lillapojkenpćön

    Chopper Commander

  • Topic Starter
  • 155 posts

Posted Fri Dec 14, 2018 7:46 AM

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





0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users