Announcement

Collapse
No announcement yet.

a question about HuC6280(65C02) assembly instructions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • a question about HuC6280(65C02) assembly instructions

    I start to study 6502 assembly from documents files and pdf which name is Programming the 65816.
    My study is going on very extremely slowly because It is too difficult to understand means of english sentence for myself which has full of programming terminology. (I have tried to search for any 6502 assembly relate books in local library.but I can't found any assembly books of previous generation,It seems that All of Korean regard old technical books as trash and to study this old generation stuff is a needless waste of time excepting me :P)

    Bytheway, I encountered a TST instraction a few days ago when I use mednafen debugger on some tg16 games.

    E90A:STA $1801
    E90D:TST #$40 $500A ;93 80 00 18
    E911:BEQ $E944

    I saw it from below link which contains most of list of Opcodes(instraction) for HuC6280 CPU which is alternate version of 65C02
    http://shu.emuunlim.com/download/pcedocs/pce_cpu.html
    It said that (TST)
    "Function Logically AND together the immediate operand with the data at the effective address specified by the operand. This sets each bit for which the corresponding immediate argument bit is set, making it an ideal opcode for masking data. N and V and Z are set as in the BIT opcode instruction. "

    I'm tempted to experiment that I change the value of address of $500A to 80(hex) and change PC to E90D and
    initialize value of status register(P) to 0 then press S(one Step).
    It changes status register to 82(hex) and it converts to 10000010 in binary in windows calculator.
    It sets N and Z flag.
    N V T B D I Z C
    M7 M6 0 - - - Z -
    but As far as I know, It is not able to set any flags because it is 40(hex) & 80(hex) which results in 0 not 82(hex) or 1000010(binary).
    I cannot make out the exact role(function) of this TST opcode(instruct) at all..Is there anyone who know 65c02 assembly opcode and would you explain this TST opcode with some examples for easier understanding?
    Any reply would be appreciated. Thanks in advance.
    Last edited by bshi02; 08-06-2012, 08:20:34 AM.

  • #2
    It's basically a bitwise AND that sets flags and discards its results. It sets the Zero flag because the result of 0x80 AND 0x40 is zero. As far as I can tell, the Negative flag is set because the memory value has its sign-bit set to 1 (0x80). I'm not sure what the value in that is.

    Typical usage would probably be:
    TST $40, $500A
    BNE do_stuff_when_bit_is_set

    Comment

    Working...
    X