Skip to content

Commit

Permalink
Merge pull request #2 from suzukiplan/create-asm-tests
Browse files Browse the repository at this point in the history
Create asm tests: PUSH/POP & bugfix
  • Loading branch information
suzukiplan committed Jul 18, 2016
2 parents e0be8b7 + c6d8bde commit 9f09659
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## Version 0.0.3
- `vgsasm` のテストを追加: PUSH, POP
- bugfix: acu-b, c, d の命令アセンブル結果が不正になる

## Version 0.0.2
- `vgsasm` コマンドを実装 (注意: テスト未実施)

Expand Down
56 changes: 54 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,61 @@ void vgscpu_release_context(void *ctx);
_※VGS APIは実装途中で、今後拡張していきます_
## [WIP] VGS ASM
## VGS ASM
### vgsasm command
```
$ vgsasm [-o output-binary] input-source
```
_現時点ではビルドのみ完了している状態です(テストはまだしていません)_
### syntax
#### comment syntax
C/C++言語形式 の コメント に 対応
```asm
PUSH A /* C形式コメント (複数行可能) */
POP A // C++形式コメント
```

#### literal syntax
- 定数の表記方法は 2進数, 8進数, 10進数, 16進数 の 4種類 を サポート
- 負数表記 は 10進数 の 場合 にのみできる
```asm
LD A, B10101110 // 2進数 (頭に B を付ける)
LD B, 0765 // 8進数 (頭に 0 を付ける)
LD C, 12345678 // 10進数 (頭に - または 1〜9 を付ける)
LD D, $deadbeef // 16進数 (頭に $ を付ける)
```

主記憶のアドレス表記には `[literal]` を用いる
```asm
ST A, [$123] // アドレス $123 から 4byte (32bit) の内容を参照
ST B, [$123]H // アドレス $123 から 2byte (16bit) の内容を参照
ST C, [$123]O // アドレス $123 から 1byte (8bit) の内容を参照
```

#### label syntax
- サフィックス `:` を付けたものがラベルとなる
- ラベルは 1バイト以上 255バイト以下 の 1トークン文字列 とする
- ブランチ命令の飛び先には必ずラベルを用いる (アドレス値の直指定はできない)
```asm
ST A, [$123]
LD B, 100
CMP A, B
JE equal // A = B
JP positive // A > B
JN negative // A < B
equal:
LD C, 0
BRK
positive:
LD C, 1
BRK
negative:
LD C, -1
BRK
```

#### operand syntax
[Operands](#operands) を 参照
5 changes: 4 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ format:
sh tools/format.sh src/cpu/vgscpu_op_acu_c.h
sh tools/format.sh src/cpu/vgscpu_op_acu_d.h
sh tools/format.sh src/test/tp.h
sh tools/format.sh src/test/asmtest.c
for AS in $(VGSASM_SRC); do make format-src SRC=$$AS; done
for TP in $(TESTCASE); do make format-test-src TP=$$TP; done

Expand Down Expand Up @@ -135,8 +136,10 @@ run-test-exec:
@rm ./$(TP)

asm-test:
@sh tools/format.sh src/test/asmtest.c
gcc -I./src/cpu src/test/asmtest.c -o asmtest vgscpu.a
./asmtest src/test/asm_push_pop_a.asm
./asmtest src/test/asm_push_pop_b.asm
./asmtest src/test/asm_push_pop_c.asm
./asmtest src/test/asm_push_pop_d.asm
@rm asmtest
@rm tp.bin
6 changes: 3 additions & 3 deletions src/asm/vgsasm_parse_acu.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ int parse_acu(struct line_data* line, int i, int acu)
case B4:
if (_parse_arl(line, i, B4, acu_op[acu])) return -1;
line[i].oplen++;
memmove(&line[i].op[0], &line[i].op[1], sizeof(line[i].op) - 1);
memmove(&line[i].op[1], &line[i].op[0], sizeof(line[i].op) - 1);
line[i].op[0] = VGSCPU_OP_ACU_B;
return 0;
case C4:
if (_parse_arl(line, i, C4, acu_op[acu])) return -1;
line[i].oplen++;
memmove(&line[i].op[0], &line[i].op[1], sizeof(line[i].op) - 1);
memmove(&line[i].op[1], &line[i].op[0], sizeof(line[i].op) - 1);
line[i].op[0] = VGSCPU_OP_ACU_C;
return 0;
case D4:
if (_parse_arl(line, i, D4, acu_op[acu])) return -1;
line[i].oplen++;
memmove(&line[i].op[0], &line[i].op[1], sizeof(line[i].op) - 1);
memmove(&line[i].op[1], &line[i].op[0], sizeof(line[i].op) - 1);
line[i].op[0] = VGSCPU_OP_ACU_D;
return 0;
}
Expand Down
11 changes: 5 additions & 6 deletions src/test/asm_push_pop_a.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@
*/

start:
LD D, -1

LD A, $deadbeef
LD A, $deadbeef
PUSH A
PUSH AH
PUSH AO

POP AO
CMP A, $ef
CMP A, $ef
JNE test-failed

POP AH
CMP A, $beef
CMP A, $beef
JNE test-failed

POP A
CMP A, $deadbeef
CMP A, $deadbeef
JNE test-failed

LD D, 1
BRK

test-failed:
LD D, -1
BRK
28 changes: 28 additions & 0 deletions src/test/asm_push_pop_b.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
PUSH/POP B の テストプログラム
*/

start:
LD B, $deadbeef
PUSH B
PUSH BH
PUSH BO

POP BO
CMP B, $ef
JNE test-failed

POP BH
CMP B, $beef
JNE test-failed

POP B
CMP B, $deadbeef
JNE test-failed

LD D, 1
BRK

test-failed:
LD D, -1
BRK
28 changes: 28 additions & 0 deletions src/test/asm_push_pop_c.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
PUSH/POP C の テストプログラム
*/

start:
LD C, $deadbeef
PUSH C
PUSH CH
PUSH CO

POP CO
CMP C, $ef
JNE test-failed

POP CH
CMP C, $beef
JNE test-failed

POP C
CMP C, $deadbeef
JNE test-failed

LD D, 1
BRK

test-failed:
LD D, -1
BRK
28 changes: 28 additions & 0 deletions src/test/asm_push_pop_d.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
PUSH/POP D の テストプログラム
*/

start:
LD D, $deadbeef
PUSH D
PUSH DH
PUSH DO

POP DO
CMP D, $ef
JNE test-failed

POP DH
CMP D, $beef
JNE test-failed

POP D
CMP D, $deadbeef
JNE test-failed

LD D, 1
BRK

test-failed:
LD D, -1
BRK
2 changes: 1 addition & 1 deletion src/test/asmtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ int main(int argc, char* argv[])
gettimeofday(&tvStart, NULL);
#endif
if (vgscpu_run(c)) {
puts("failed");
printf("failed: %s\n", vgscpu_get_last_error(c));
return 4;
}
#ifndef _WIN32
Expand Down

0 comments on commit 9f09659

Please sign in to comment.