ASM6 Operands?

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
asm6hackr
Posts: 60
Joined: Fri Dec 29, 2023 4:03 pm

ASM6 Operands?

Post by asm6hackr »

In the readme in asm6f, at https://github.com/freem/asm6f, there is no mention of operands. Where is a list of operands supported by ASM6? I looked in both readme.txt and readme-original.txt.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: ASM6 Operands?

Post by Dwedit »

(Looks up the word in a dictionary)

Seems like the only thing that could be considered an "Operand" would be a number or symbol used in a compile-time mathematical expression? Like "lda MySymbol+4" would have "MySymbol" and "4" as operands of the Plus operator.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
segaloco
Posts: 280
Joined: Fri Aug 25, 2023 11:56 am
Contact:

Re: ASM6 Operands?

Post by segaloco »

From the source:

Code: Select all

char mathy[]="!^&|+-*/%()<>=,";
enum prectypes {WHOLEEXP,ORORP,ANDANDP,ORP,XORP,ANDP,EQCOMPARE,COMPARE,SHIFT,PLUSMINUS,MULDIV,UNARY};//precedence levels
enum operators {NOOP,EQUAL,NOTEQUAL,GREATER,GREATEREQ,LESS,LESSEQ,PLUS,MINUS,MUL,DIV,MOD,AND,XOR,OR,ANDAND,OROR,LEFTSHIFT,RIGHTSHIFT};//all operators
char prec[]={WHOLEEXP,EQCOMPARE,EQCOMPARE,COMPARE,COMPARE,COMPARE,COMPARE,PLUSMINUS,PLUSMINUS,MULDIV,MULDIV,MULDIV,ANDP,XORP,ORP,ANDANDP,ORORP,SHIFT,SHIFT};//precedence of each operator
//get operator from str and advance str
int getoperator(char **str) {
	*str+=strspn(*str,whitesp);	 //eatwhitespace
	(*str)++;
	switch(*(*str-1)) {
		case '&':
			if(**str=='&') {
				(*str)++;
				return ANDAND;
			} else
				return AND;
		case '|':
			if(**str=='|') {
				(*str)++;
				return OROR;
			} else
				return OR;
		case '^':
			return XOR;
		case '+':
			return PLUS;
		case '-':
			return MINUS;
		case '*':
			return MUL;
		case '%':
			return MOD;
		case '/':
			return DIV;
		case '=':
			if(**str=='=')
				(*str)++;
			return EQUAL;
		case '>':
			if(**str=='=') {
				(*str)++;
				return GREATEREQ;
			} else if(**str=='>') {
				(*str)++;
				return RIGHTSHIFT;
			} else
				return GREATER;
		case '<':
			if(**str=='=') {
				(*str)++;
				return LESSEQ;
			} else if(**str=='>') {
				(*str)++;
				return NOTEQUAL;
			} else if(**str=='<') {
				(*str)++;
				return LEFTSHIFT;
			} else
				return LESS;
		case '!':
			if(**str=='=') {
				(*str)++;
				return NOTEQUAL;
			}
			// fall through
		default:
			(*str)--;
			return NOOP;
	}
}
This is the routine that reduces an operator down to a preprocessor symbol identifying the operation. Pretty sure that should describe what each character turns into pretty well.
asm6hackr
Posts: 60
Joined: Fri Dec 29, 2023 4:03 pm

Re: ASM6 Operands?

Post by asm6hackr »

@Dwedit I found this on a NESASM respository, https://github.com/ClusterM/nesasm/blob ... u_inst.txt. I was wondering if there was a comparable list for ASM6.
User avatar
segaloco
Posts: 280
Joined: Fri Aug 25, 2023 11:56 am
Contact:

Re: ASM6 Operands?

Post by segaloco »

asm6hackr wrote: Sat Jan 20, 2024 2:10 pm @Dwedit I found this on a NESASM respository, https://github.com/ClusterM/nesasm/blob ... u_inst.txt. I was wondering if there was a comparable list for ASM6.
Ah those are typically called opcodes or more precisely mnemonics, along with the various addressing modes. That shouldn't differ too much between assemblers, the main difference I see in this set is using square brackets instead of parentheses for various types of dereferencing. I would hope it's a safe assumption that in lieu of an official word from an assembler author, the syntax matches that of the MCS6500 Family Programming Manual.

By the way, you're typically fine using the most general form of an addressing mode. For instance, zeropage vs absolute versions of otherwise comparable addressing modes, different assemblers give you ways to say you specifically want absolute always, but often times the resulting operation may be different if the base pointer is found to be a zeropage address. Usually it's good to know how to force a particular size when disassembling something though.
asm6hackr
Posts: 60
Joined: Fri Dec 29, 2023 4:03 pm

Re: ASM6 Operands?

Post by asm6hackr »

@segaloco So usually the big differences between assemblers is the directives and opcodes, correct?
User avatar
segaloco
Posts: 280
Joined: Fri Aug 25, 2023 11:56 am
Contact:

Re: ASM6 Operands?

Post by segaloco »

Basically if it isn't in the architecture manual, the author is infinitely less on the hook for supporting it. Some assemblers are quite expansive with macros, conditional directives, constant arithmetic, while others are quite spartan, I've heard the Apple II Miniassembler described this way.

A common pattern is for provided directives to begin with a "." taking after the UNIX assembler tradition (in turn influenced by the main DEC PDP-11 assembler, and whatever that traces back through.) There's also considerations for whether the assembler is a straight shot or a separate linker is provided.

Quality of documentation is something to consider when putting together a toolkit. If you search and search and can't find what you're easily able to find for other assemblers, that may be telling of how much mileage you'll actually get out of the thing. For me the above is plain enough that I wouldn't necessarily cite a lack of documentation on the operators as a reason not to use asm6f. It could stand to be documented but I was able to find it in like a minute.

Edit: P.S. there's also the matter of what is and isn't the job of the assembler. There are plenty of macro systems that preclude an assembler from necessary needing to support its own. For instance, if I had to use a painfully spartan assembler, I'd bring m4(1) into the picture for all my macro needs. It's in POSIX and has a lot to offer. Flip side though is now everyone using your code needs one more tool. Better m4(1) which is in a decades old standard than some other thing you can't trust to run everywhere.
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: ASM6 Operands?

Post by Fiskbit »

Instruction mnemonics do not vary across assemblers. Normally, addressing mode syntax doesn't vary, either, but NESASM has unusual syntax for indirect addressing. Directives and operators (such as the low byte (<) and high byte (>) unary operators) are not part of the language and assemblers can do whatever they want.
User avatar
Gilbert
Posts: 564
Joined: Sun Dec 12, 2010 10:27 pm
Location: Hong Kong
Contact:

Re: ASM6 Operands?

Post by Gilbert »

Fiskbit wrote: Sat Jan 20, 2024 2:40 pm Instruction mnemonics do not vary across assemblers.
They should not vary, at least normally, as the mnemonic names were officially set by the designers of the CPU (save for some specific requirements in certain assemblers, e.g. most of the assemblers on the Apple ][ restricted the letters used to CAPITAL letters only).

However, in some rare cases, people did use different names for the same mnemonics.

I remember toying around with a FDS hacking software BiTD (couldn't remember its name). It could load a file from a disk and show a disassembly of the content (i.e. it's in fact a hex viewer with disassembly feature). However, the opcodes and syntax were all alien to me. It used something like JZ instead of BEQ, etc., which confused me as I had some knowledge of 6502 assembly since the 80's (and knew that the Famicom used a 6502 CPU core) and I didn't have experience with assembly on other CPUs such as 80XX, yet. I (later) speculated that those people who wrote the hacking tool didn't know anything about the 6502 (as it was said that Nintendo intentionally chose a CPU that was not popular in Japan at the time to make it hard to develop on the system) and they reverse engineered the CPU themselves and called the opcodes with whatever names they came up with, based on other CPU architecture that they're familiar with.

Another example is Martin's NO$NES emulator. This is how its debugger looks like:
no$debugger.png
But it was probably done deliberately so that people developing for/hacking different systems could have something more unified to work with, as all the NO$ emulators use the same interface. They could be changed back to the official mnemonics if you choose "Native 65XX Style" from "Option -> Debugger Setup -> Disassembler Syntax".
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: ASM6 Operands?

Post by Fiskbit »

That looks like x86 mnemonics and syntax applied to 6502. Weird, but interesting!
User avatar
segaloco
Posts: 280
Joined: Fri Aug 25, 2023 11:56 am
Contact:

Re: ASM6 Operands?

Post by segaloco »

Gilbert wrote: Sat Jan 20, 2024 9:35 pm
Fiskbit wrote: Sat Jan 20, 2024 2:40 pm Instruction mnemonics do not vary across assemblers.
They should not vary, at least normally...
UNIX is another case of this. The assembler adds specific aliases for syscall related bits, with trap being aliased to "sys" and "bec" and "bes" being provided as alternatives for bcc/bcs (as the carry bit was used for error reporting from syscalls.)

Then there's stuff like a6 on the M68000 being aliased to "fp" and r6 on PDP-11 being "sp". Many CPU architectures tend to have a vendor syntax and an "AT&T syntax", the latter owing to how many platforms UNIX (and as a result, its assembler suite) was ported to. 6502 doesn't fall into this category as there isn't a strong UNIX tradition on it. Not that 6502 has much room for those "isms", there aren't src/dest operations so you don't run into ordering issues like you do elsewhere. A is a so no real squabbling over sticking say a "%" on the front of it or not to denote it is a register. My only gripe with the prevailing stuff though is not having consistency on use of "$" vs "0x" for hexadecimal expressions.

Fun aside, but the earliest use I've ever found regarding "$" as a delimiter in computing applications is that the name of application cards for some early IBM mainframe all started with "$" which lead to its use as a popular shell prompt character, not sure when it got picked up as a hexadecimal delimiter along the way...
User avatar
Hamtaro126
Posts: 818
Joined: Thu Jan 19, 2006 5:08 pm

Re: ASM6 Operands?

Post by Hamtaro126 »

I think that the only way to tell, is also between assemblers, and various opcodes between CPU types, such as 6502/6507/65c02/HuC6280/65(c)816/etc.

Also... Like they said already, Syntax also applies to every CPU when using ASM code. Using your NESASM (is it using NESASM3 by chance?) code in ASM6/CA65 requires a little work...

6502 opcodes all are the same on NES, including Unofficial opcodes, if you are going on a 16/32-bit 6502-like console, Unofficial opcodes won't do!

I officially suggest staying with official opcodes, using the 6502, as well to port to other 65 family CPUs if needed...

EDIT 1: Corrected Terminology for friendlyness rule!
AKA SmilyMZX/AtariHacker.
Post Reply