Go Back   Project64 Forums > General Discussion > Open Discussion

Reply
 
Thread Tools Display Modes
  #1  
Old 15th December 2014, 07:40 PM
Tarek701's Avatar
Tarek701 Tarek701 is offline
Member
 
Join Date: Mar 2009
Posts: 58
Lightbulb CajeASM v7.2 (Stable) - MIPS R4300i Assembler for N64

CajeASM - A MIPS R4300i Assembler
CajeASM is, as the title states, a MIPS R4300i Assembler and soon a PowerPC Assembler for GC and Wii. If you aren't aware yet, what exactly "Assembly" is, let me sum it up for you:

Assembly is basically a low-level language. With assembly we give the game or to be more specific the CPU "commands" to do something. That could be a very simple task like adding 1 and 1 or a more complex task like calling a subroutine(or better known as function) and passing arguments.

Download Link:
http://origami64.net/attachment.php?aid=72

To assemble something in CajeASM, just watch this video. It shows a sample ASM Code assembled to a SM64 ROM.

Tutorials:
SM64 Hacking - CajeASM : How to assemble an ASM File to your ROM

If you know assembly, you can do a lot of nice stuff.

Stuff and projects which was coded with CajeASM:

FLUDD by Kazeshin(aka Kaze):

(Full Video: FLUDD)

Shop Guy by Tarek701/Cajetan (aka me):

(Full Video + Download Link: Shop Guy v0.2)

More Objects Patch by Kazeshin(aka Kaze):

(Full Video + Download Link: More Objects Patch

Technical (Geeky):
==================
Well, for a while I've been learning a lot about how to write parsers and lexers and decided to write my first assembler, respectively for MIPS. Yes, I know there are already a lot of MIPS Assemblers exist out there. But this one was specially made for Nintendo 64 ROMs. It supports all MIPS III opcodes, supports pseudo-instructions (BGT (Greater Than), BLT (Lesser Than), BGE (Greater or Equal To), BLE (Less or Equal To, and a few more), defines(something like variables, but not directly), labels, directives (.org -> to put your code in a specific address, .ascii/.asciiz(zero-string terminated) -> to write ASCII string directly into the ROM)

A few examples here:

(Btw, this is Notepad++ with my MIPS Syntax Highlighter. It's included in CajeASM.)

In the beginning, there's a "define" or "variable", whatever you want to call it.
"#" tells the assembler that the value is "decimal" and is converted to hexadecimal later.
"%" tells the assembler that the value is "binary".
"$" or "0x" tells the assembler that the value is hexadecimal aka normal.

We later call "CoinAmount" in our ORI Instruction by writing @CoinAmount.

Then there are labels like "Print" and "Exit", which we jump to depending on what the current coin amount is.

If anyone wants to try it out, it can be downloaded from SMWCentral:
http://sm64-hacks.square7.ch/CajeASM%20v6.0.zip

It has a frontend (GUI) after it turned out that 99% of the people I knew couldn't use cmd.

What do you think? Good, bad? Could I add anything else here?
__________________
==========================
Familiar with MIPS r4300i ASM, Basic stuff in C.

Last edited by Tarek701; 30th April 2015 at 12:29 PM. Reason: CajeASM v7.2 released
Reply With Quote
  #2  
Old 23rd December 2014, 12:03 AM
HatCat's Avatar
HatCat HatCat is offline
Alpha Tester
Project Supporter
Senior Member
 
Join Date: Feb 2007
Location: In my hat.
Posts: 16,260
Default

Doesn't appear to be compliant with true MIPS syntax--at least, it's not compliant to RSP assembly language. (Tokens such as `T1', `R0' and `zero' are invalid; it has to be called `$0' in RSP asm.) I suppose you might go on EFNet IRC if you'd like more user feedback.

Sounds like a nice project though. thought about doing one too, good luck
Reply With Quote
  #3  
Old 26th December 2014, 01:58 AM
Tarek701's Avatar
Tarek701 Tarek701 is offline
Member
 
Join Date: Mar 2009
Posts: 58
Default

Quote:
Originally Posted by HatCat View Post
Doesn't appear to be compliant with true MIPS syntax--at least, it's not compliant to RSP assembly language. (Tokens such as `T1', `R0' and `zero' are invalid; it has to be called `$0' in RSP asm.) I suppose you might go on EFNet IRC if you'd like more user feedback.

Sounds like a nice project though. thought about doing one too, good luck
The MIPS Syntax wasn't broken here. Used all the standards from the official MIPS documentation. The only thing which is an exception would be the use of the "defines" or "variables" like I call them and the pseudo-instructions BGT, BGE, BLE, BLT which are basically SLT. But you are right about RSP asm.

Actually, I had the idea of allowing RSP asm too. However, I wasn't able to find any documentation on it and was too inexperienced with it. If you have any good documentation about it, that would be really helpful.
__________________
==========================
Familiar with MIPS r4300i ASM, Basic stuff in C.
Reply With Quote
  #4  
Old 5th January 2015, 06:02 PM
Tarek701's Avatar
Tarek701 Tarek701 is offline
Member
 
Join Date: Mar 2009
Posts: 58
Default

So, CajeASM v5.11 is out. Features a lot of new stuff, labels no longer need to be prefixed with "!" tokens anymore. I really don't know how I came up with that stupid crap anyway. So, 0.0034 times faster coding, woo! There's now an .include directive, which also imports labels and defines/variables. You can basically use the labels to create your own subroutines and later JAL to them.

There's also much more changes. I'm gonna list up the general changes here:
  • [ADD]: .include directive, which let's you allow to include other asm files to your main asm file. It also imports labels and variables/defines.
  • [ADD]: Defines are now handled properly when load with LUI. LUI only loads the upper half of the define, while all other lower half instructions like ADDIU, ORI, etc. load the lower half of the define.
  • [FIX]: Comments won't get messed up anymore.
  • [DEL]: Labels no longer need to be prefixed with a "!" token.
  • [ADD]: New Pseudo-Instructions: BEQI, BNEI, BGTI, BLEI, BGEI, BLTI.
  • [ADD]: A complete rewritten and up-to date CajeASM Manual.
  • [FIX]: Labels being unaligned (missing 4 in counter) and branching wrong.
  • [FIX]: Include path not correctly specified.
  • [FIX]: Base Instructions Instructions (LH, SH, LB, SB, LW, SW, etc.) couldn't take shortened values. (if you wrote 0x0, then CajeASM didn't recognize it)

As I said above, defines are a bit more "clever" now when load into LUI and ADDIU, LH, etc. instructions.

To show off an example:
[Coins]: 0x8034B218

LUI T0, @Coins
LH T1, @Coins(T0)

LUI would only load the upper half of Coins, in our case: 0x8034. And LH will load the lower half of Coins, here 0xB218.

So, translated this will look like following:

LUI T0, 0x8034
LH T1, 0xB218(T0)

This would load the value from 0x8033B218 to T1. (It's 0x8033B218, as the value 0xB218 is over 0x7FFF and therefore negative. If it's aligned to a 32-bit value, 0xB218 has to be kept negative and so it adds 0xFFFFB218 to 0x80340000, resulting in our real address, 0x8033B218. Just saying)
__________________
==========================
Familiar with MIPS r4300i ASM, Basic stuff in C.
Reply With Quote
  #5  
Old 10th January 2015, 07:07 PM
HatCat's Avatar
HatCat HatCat is offline
Alpha Tester
Project Supporter
Senior Member
 
Join Date: Feb 2007
Location: In my hat.
Posts: 16,260
Default

A mate of mine uses MARS [dis-]assembler for MIPS programming.
In that software I believe (not sure) you had to prefix register names with $.

So it would have been $zero, $at, $v0 instead of ZERO, AT, V0 ...

Just something I remembered I guess, dunno if you ever had any thoughts about supporting multiple syntax's.
Reply With Quote
  #6  
Old 16th January 2015, 03:11 PM
Tarek701's Avatar
Tarek701 Tarek701 is offline
Member
 
Join Date: Mar 2009
Posts: 58
Default

Quote:
Originally Posted by HatCat View Post
A mate of mine uses MARS [dis-]assembler for MIPS programming.
In that software I believe (not sure) you had to prefix register names with $.

So it would have been $zero, $at, $v0 instead of ZERO, AT, V0 ...

Just something I remembered I guess, dunno if you ever had any thoughts about supporting multiple syntax's.
The syntax for the registers was directly copied from LemASM. Also, as far as I know, the only real good N64 ROM Debugger(with Disassembler) is Nemu64 also by Lemmy which uses the same syntax for register names (without the "$" symbol before reg names) and so I decided to do it that way too. So people could dump ASM Code using Nemu64, modify it and directly patch it to ROM via CajeASM.

Also, the "$" symbol is used already for hex values.

If you think that you have to write register names like ZERO, AT, V0, ... etc. in upper-case, well that's not true. You could also lowercase them or write them like this zeRo or aT and CajeASM still recognizes it. I just do this in my examples, because it feels better and more structured to me. But no one is forced to do it.
__________________
==========================
Familiar with MIPS r4300i ASM, Basic stuff in C.
Reply With Quote
  #7  
Old 16th January 2015, 04:01 PM
HatCat's Avatar
HatCat HatCat is offline
Alpha Tester
Project Supporter
Senior Member
 
Join Date: Feb 2007
Location: In my hat.
Posts: 16,260
Default

That's fine; I don't mind it being case-insensitive. My post was about "multiple" syntax's anyway, so that generally coincides.

Quote:
Originally Posted by Tarek701 View Post
The syntax for the registers was directly copied from LemASM. Also, as far as I know, the only real good N64 ROM Debugger(with Disassembler) is Nemu64 also by Lemmy which uses the same syntax for register names (without the "$" symbol before reg names) and so I decided to do it that way too. So people could dump ASM Code using Nemu64, modify it and directly patch it to ROM via CajeASM.

Also, the "$" symbol is used already for hex values.
You can get some more information about it from the new MIPS site:
http://www.imgtec.com/mips/architectures/mips32.asp

They have a quick reference card here for those who lack the remaining docs:
http://www.imgtec.com/downloads/fact...-QRC-01.01.pdf

Check the second page of that card. Here you will see MIPS Tech. giving 2 assembly language examples--both of which prefix register names with $ and never capitalize the register names (again I don't mind that you allow it optionally).

From what I could tell by looking, much of Nemu64 disassembler, was most likely not written by Lemmy himself (there were some others who worked on nemu). However, it is true that '$' conflicts with different assembly languages...some asm langs make $ for hexadecimals, others use it for register names, others use it for binary numbers...it's one of those inconsistent things you can see in any assembly code and know it means something different each time.

LemAsm, Niew64, anarko's disassemblers--they were all written for N64 usage, not from official tools (older versions of these assemblers had some bugs and wrong assumptions about the MIPS ecosystem). It's usually easy for an emulation author to change the rules while writing one's own assembler for a relatively undocumented system. Most of the emulators were written without even proper English language; the only emulator I can think of that thoroughly relied on official MIPS documentation was Project64, and even that disassembles MIPS/RSP code with some syntactical contradictions to other debuggers/disassemblers.
Reply With Quote
  #8  
Old 17th January 2015, 02:30 PM
Tarek701's Avatar
Tarek701 Tarek701 is offline
Member
 
Join Date: Mar 2009
Posts: 58
Default

Quote:
Originally Posted by HatCat View Post
That's fine; I don't mind it being case-insensitive. My post was about "multiple" syntax's anyway, so that generally coincides.



You can get some more information about it from the new MIPS site:
http://www.imgtec.com/mips/architectures/mips32.asp

They have a quick reference card here for those who lack the remaining docs:
http://www.imgtec.com/downloads/fact...-QRC-01.01.pdf

Check the second page of that card. Here you will see MIPS Tech. giving 2 assembly language examples--both of which prefix register names with $ and never capitalize the register names (again I don't mind that you allow it optionally).

From what I could tell by looking, much of Nemu64 disassembler, was most likely not written by Lemmy himself (there were some others who worked on nemu). However, it is true that '$' conflicts with different assembly languages...some asm langs make $ for hexadecimals, others use it for register names, others use it for binary numbers...it's one of those inconsistent things you can see in any assembly code and know it means something different each time.

LemAsm, Niew64, anarko's disassemblers--they were all written for N64 usage, not from official tools (older versions of these assemblers had some bugs and wrong assumptions about the MIPS ecosystem). It's usually easy for an emulation author to change the rules while writing one's own assembler for a relatively undocumented system. Most of the emulators were written without even proper English language; the only emulator I can think of that thoroughly relied on official MIPS documentation was Project64, and even that disassembles MIPS/RSP code with some syntactical contradictions to other debuggers/disassemblers.
Yes, I agree. As you said, because I mostly used LemASM for N64 Hacking before (and many others too), I didn't really think any further into it and took the "$" symbol for hexadecimal values (+ allowing '0x' prefix). And yeah, I saw a couple of disassemblers already using the "$" as prefix symbol for registers, like in IDA Pro. As I said, CajeASM was specially made for N64 ASM Hacking and as most N64 Hackers used LemASM and were pretty accustomed to it, having a "$" as register prefix might be not a good idea. Maybe I can get it into CajeASM as alternative.

Generally for debugging RSP code, I decided to use IDA Pro. It seems to disassemble it pretty well. (By sight, not really sure if it's 100% accurate though)



Pretty sad, that there's no official doc for RSP out there. It would make things so much more easier. But I know that it's about vectors, scalars and this kind of stuff. But I'm kinda wondering what instructions like VSAW (Vector SAW, as like in cut a vector?), etc. do.
__________________
==========================
Familiar with MIPS r4300i ASM, Basic stuff in C.
Reply With Quote
  #9  
Old 17th January 2015, 02:44 PM
HatCat's Avatar
HatCat HatCat is offline
Alpha Tester
Project Supporter
Senior Member
 
Join Date: Feb 2007
Location: In my hat.
Posts: 16,260
Default

Nice! That does look like a good disassembly of the RSP; it even highlights the illegal LDV instructions in red (unaligned addr). (They're illegal, but intended. You could also execute reserved/invalid opcodes on the RSP. [krom] on EFnet has been taking a lot of interesting notes about reversing what those do.)

The only thing I can think of that is inaccurate with IDA Pro's disasm is the vector elements...I guess technically it's fine to do this with DIS-assembly, but in RSP assembly language you have to specify either nothing at all, [0q], [1q], [0h], [1h], [2h], [3h], or [#] where # is an octal digit, for scalar-whole "broadcasting mode" (as some other patents would refer to it for more public vector units). Instead, IDA pro just says [#] 0-15--there are indeed 16 possible values, but saying [8], [9], ...[15] isn't a valid token for the asm.

Last edited by HatCat; 17th January 2015 at 02:47 PM.
Reply With Quote
  #10  
Old 17th January 2015, 02:58 PM
Tarek701's Avatar
Tarek701 Tarek701 is offline
Member
 
Join Date: Mar 2009
Posts: 58
Default

Quote:
Originally Posted by HatCat View Post
Nice! That does look like a good disassembly of the RSP; it even highlights the illegal LDV instructions in red (unaligned addr). (They're illegal, but intended. You could also execute reserved/invalid opcodes on the RSP. [krom] on EFnet has been taking a lot of interesting notes about reversing what those do.)

The only thing I can think of that is inaccurate with IDA Pro's disasm is the vector elements...I guess technically it's fine to do this with DIS-assembly, but in RSP assembly language you have to specify either nothing at all, [0q], [1q], [0h], [1h], [2h], [3h], or [#] where # is an octal digit, for scalar-whole "broadcasting mode" (as some other patents would refer to it for more public vector units). Instead, IDA pro just says [#] 0-15--there are indeed 16 possible values, but saying [8], [9], ...[15] isn't a valid token for the asm.
Yes, IDA Pro is really cool on this. They even have a really professional decompiler and damn it's really good. Too bad, that IDA Pro 6.5 doesn't have it for MIPS.

I'm kinda confused now on the elements. I took now the example VSUB;

VSUB v10, v14, v13[0]

010010 1 0000 01101 01110 01010 010001
{COP2} {El} {VS} {VT} {VD} {VSUB}

That's what I got now. I have no idea what that "1" means (maybe a flag, like carry flag?)

From a syntactic point of view, you meant to make CajeASM assemble RSP asm elements like in hex values or octal values?:
VSUB v10, v14, v13[0x1]
VSUB v10, v14, v13[0xA]
VSUB v10, v14, v13[0xB]
VSUB v10, v14, v13[17] // octal
etc.
__________________
==========================
Familiar with MIPS r4300i ASM, Basic stuff in C.

Last edited by Tarek701; 17th January 2015 at 03:15 PM.
Reply With Quote
Reply

Tags
assembler, mips, r4300i, sm64, tarek701

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 01:53 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.