summaryrefslogtreecommitdiffstats
path: root/src/emu/asm.c
blob: caca72a51247895ebaa2e729e790c322e642df05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <stdint.h>

#include "cpu.h"
#include "log.h"
#include "opc.h"

uint32_t compile(const char *line)
{
	char mnem[4];
	int32_t a = 0, b = 0, c = 0;

	/* arithmetic & logic */
	if (sscanf(line, "%3s r%2d, r%2d, r%2d", mnem, &a, &b, &c) == 4)
		return mnemonic2opc(mnem) | ((a & 0x1F) << 21) | ((b & 0x1F) << 16) | ((c & 0x1F) << 11);

	/* load/store & branch */
	if (sscanf(line, "%3s r%2d, r%2d, %d", mnem, &a, &b, &c) == 4)
		return mnemonic2opc(mnem) | ((a & 0x1F) << 21) | ((b & 0x1F) << 16) | (c & 0xFFFF);

	if (sscanf(line, "%3s r%2d, %d", mnem, &b, &c) == 3)
		return mnemonic2opc(mnem) | ((b & 0x1F) << 16) | (c & 0xFFFF);

	/* jump */
	if (sscanf(line, "%3s r%2d", mnem, &a) == 2)
		return mnemonic2opc(mnem) | ((a & 0x1F) << 21);

	/* misc */
	if (sscanf(line, "%3s", mnem) == 1)
		return mnemonic2opc(mnem);

	return 0xFFFFFFFF;
}