6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 16, 2024 5:18 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: 6502 CMP question
PostPosted: Sun Mar 07, 2004 8:01 am 
Offline

Joined: Sun Mar 07, 2004 7:49 am
Posts: 2
Location: Argentina
Im programming a 6502 emulator for a NES emulator im making. Im using "MOS Microcomputers Programmer Manual" as a reference and its quite decent, but i have the following problem/question regarded de CMP,CPX, CPY Instructions:

The manual says: "This instruction subtracts the contents of memory from the contents of the accumulator", but it says that the simbolic notation is:
A - M.

Becouse im emulating the instructions with real x86 instructions i want to know if "substract memory from acumlator (M - A)", or "substratc acumulator from memory (A - M).

Thanks. :(

_________________
- Ateneo -


Top
 Profile  
Reply with quote  
 Post subject: Re: 6502 CMP question
PostPosted: Sun Mar 07, 2004 9:41 am 
Offline

Joined: Thu Oct 23, 2003 9:07 am
Posts: 12
> Im programming a 6502 emulator for a NES emulator im making.
> I have the following problem/question regarded de CMP,CPX, CPY Instructions

[Not sure which way]

It's (A-M) and (Y-M) and (X-M),
Sprow.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Mar 07, 2004 9:47 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
The 'A - M' notation in the manual is correct, the contents of the memory (M) is subtracted from the accumulater (A) to set the flags. The result of the subtraction itself is not stored.

The memory value M depends on the addressing mode you use. For example in an immediate compare (CMP #$20) the memory value is the immediate data ($20). If some other form of addressing was used (CMP $70, CMP $1234, CMP ($70),Y, etc.) then CPU resolves the address to locate the memory value.

After the compare the flags tell you the relative sizes of the two values.
    If A and M are the same (e.g. use BEQ to test for A == B ) then the subtraction will set the zero flag, otherwise it will be clear (e.g. use BNE to test for A != B).
    If A and M are considered as unsigned values then if the carry flag is clear A was smaller then M (e.g. use BCC to test for A < M). It will be set if A was not smaller (e.g. use BCS to test for A >= M).

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: