Skip to content

Instantly share code, notes, and snippets.

@ccckmit
Last active August 29, 2015 14:17
Show Gist options
  • Save ccckmit/d29f59dbed9f22a54568 to your computer and use it in GitHub Desktop.
Save ccckmit/d29f59dbed9f22a54568 to your computer and use it in GitHub Desktop.
CPU0 組合語言的祖譯過程
D:\ccc\code\ch12>make
gcc.exe -D__DEBUG__ -c Parser.c -o Parser.o -g3
gcc.exe -D__DEBUG__ -c Tree.c -o Tree.o -g3
gcc.exe -D__DEBUG__ -c Lib.c -o Lib.o -g3
gcc.exe -D__DEBUG__ -c Scanner.c -o Scanner.o -g3
gcc.exe -D__DEBUG__ -c Array.c -o Array.o -g3
gcc.exe -D__DEBUG__ -c Compiler.c -o Compiler.o -g3
gcc.exe -D__DEBUG__ -c HashTable.c -o HashTable.o -g3
gcc.exe -D__DEBUG__ -c Generator.c -o Generator.o -g3
gcc.exe -D__DEBUG__ -c Assembler.c -o Assembler.o -g3
gcc.exe -D__DEBUG__ -c Cpu0.c -o Cpu0.o -g3
gcc.exe -D__DEBUG__ -c OpTable.c -o OpTable.o -g3
gcc.exe -D__DEBUG__ main.c Parser.o Tree.o Lib.o Scanner.o Array.o Compiler.o Ha
shTable.o Generator.o Assembler.o Cpu0.o OpTable.o -DTARGET=TEST -o test
gcc.exe -D__DEBUG__ main.c Parser.o Tree.o Lib.o Scanner.o Array.o Compiler.o Ha
shTable.o Generator.o Assembler.o Cpu0.o OpTable.o -DTARGET=C0C -o c0c
gcc.exe -D__DEBUG__ main.c Parser.o Tree.o Lib.o Scanner.o Array.o Compiler.o Ha
shTable.o Generator.o Assembler.o Cpu0.o OpTable.o -DTARGET=AS0 -o as0
gcc.exe -D__DEBUG__ main.c Parser.o Tree.o Lib.o Scanner.o Array.o Compiler.o Ha
shTable.o Generator.o Assembler.o Cpu0.o OpTable.o -DTARGET=VM0 -o vm0
D:\ccc\code\ch12>dir *.exe
磁碟區 D 中的磁碟沒有標籤。
磁碟區序號: EC3F-6E7A
D:\ccc\code\ch12 的目錄
2015/03/13 上午 09:39 87,715 as0.exe
2015/03/13 上午 09:39 87,715 c0c.exe
2015/03/13 上午 09:39 87,715 test.exe
2015/03/13 上午 09:39 87,715 vm0.exe
4 個檔案 350,860 位元組
0 個目錄 235,570,753,536 位元組可用
D:\ccc\code\ch12>dir *.as0
磁碟區 D 中的磁碟沒有標籤。
磁碟區序號: EC3F-6E7A
D:\ccc\code\ch12 的目錄
找不到檔案
D:\ccc\code\ch12>dir *.asm0
磁碟區 D 中的磁碟沒有標籤。
磁碟區序號: EC3F-6E7A
D:\ccc\code\ch12 的目錄
2010/03/16 下午 03:21 414 ArraySum.asm0
2010/04/01 下午 02:39 49 Ex4_1.asm0
2010/04/02 上午 11:02 75 Exp.asm0
2010/04/08 下午 04:32 1,442 for2.asm0
2013/03/22 下午 04:15 288 idSum.asm0
2013/03/22 下午 04:09 270 idSum_bak.asm0
2013/03/15 下午 04:48 883 spTest1.asm0
2010/04/08 下午 04:29 1,021 square_sum.asm0
2010/03/30 下午 02:28 164 sum.asm0
2009/06/10 下午 04:50 186 sum_old.asm0
2010/05/05 下午 02:51 781 test.asm0
2013/03/15 下午 03:51 462 test0315.asm0
2009/06/17 下午 04:37 751 test1.asm0
2010/03/30 下午 02:28 164 複製 -sum.asm0
14 個檔案 6,950 位元組
0 個目錄 235,570,753,536 位元組可用
D:\ccc\code\ch12>as0 sum.asm0
as0 <asmFile> <objFile>
D:\ccc\code\ch12>as0 sum.asm0 sum.obj0
Assembler:asmFile=sum.asm0 objFile=sum.obj0
===============Assemble=============
LD R1, sum
LD R2, i
LDI R3, 10
LDI R4, 1
FOR: CMP R2, R3
JGT EXIT
ADD R1, R2, R1
ADD R2, R4, R2
JMP FOR
EXIT: RET
i: RESW 1
sum: WORD 0
=================PASS1================
0000 LD R1, SUM L 0 (NULL)
0004 LD R2, I L 0 (NULL)
0008 LDI R3, 10 L 8 (NULL)
000C LDI R4, 1 L 8 (NULL)
0010 FOR: CMP R2, R3 A 10 (NULL)
0014 JGT EXIT J 23 (NULL)
0018 ADD R1, R2, R1 A 13 (NULL)
001C ADD R2, R4, R2 A 13 (NULL)
0020 JMP FOR J 26 (NULL)
0024 EXIT: RET J 2C (NULL)
0028 I: RESW 1 D F0 (NULL)
002C SUM: WORD 0 D F2 (NULL)
===============SYMBOL TABLE=========
0024 EXIT: RET J 2C (NULL)
002C SUM: WORD 0 D F2 (NULL)
0010 FOR: CMP R2, R3 A 10 (NULL)
0028 I: RESW 1 D F0 (NULL)
=============PASS2==============
0000 LD R1, SUM L 0 001F0028
0004 LD R2, I L 0 002F0020
0008 LDI R3, 10 L 8 0830000A
000C LDI R4, 1 L 8 08400001
0010 FOR: CMP R2, R3 A 10 10230000
0014 JGT EXIT J 23 2300000C
0018 ADD R1, R2, R1 A 13 13121000
001C ADD R2, R4, R2 A 13 13242000
0020 JMP FOR J 26 26FFFFEC
0024 EXIT: RET J 2C 2C000000
0028 I: RESW 1 D F0 00000000
002C SUM: WORD 0 D F2 00000000
==========Save to ObjFile:sum.obj0==========
001F0028002F00200830000A08400001102300002300000C131210001324200026FFFFEC2C000000
0000000000000000
請按任意鍵繼續 . . .
D:\ccc\code\ch12>vm0 sum.obj0
===VM0:run sum.obj0 on CPU0===
PC=00000004 IR=001F0028 SW=00000000 R[01]=0X00000000=0
PC=00000008 IR=002F0020 SW=00000000 R[02]=0X00000000=0
PC=0000000C IR=0830000A SW=00000000 R[03]=0X0000000A=10
PC=00000010 IR=08400001 SW=00000000 R[04]=0X00000001=1
PC=00000014 IR=10230000 SW=80000000 R[12]=0X80000000=-2147483648
PC=00000018 IR=2300000C SW=80000000 R[00]=0X00000000=0
PC=0000001C IR=13121000 SW=80000000 R[01]=0X00000000=0
PC=00000020 IR=13242000 SW=80000000 R[02]=0X00000001=1
PC=00000010 IR=26FFFFEC SW=80000000 R[15]=0X00000010=16
PC=00000014 IR=10230000 SW=80000000 R[12]=0X80000000=-2147483648
PC=00000018 IR=2300000C SW=80000000 R[00]=0X00000000=0
PC=0000001C IR=13121000 SW=80000000 R[01]=0X00000001=1
PC=00000020 IR=13242000 SW=80000000 R[02]=0X00000002=2
PC=00000010 IR=26FFFFEC SW=80000000 R[15]=0X00000010=16
PC=00000014 IR=10230000 SW=80000000 R[12]=0X80000000=-2147483648
PC=00000018 IR=2300000C SW=80000000 R[00]=0X00000000=0
PC=0000001C IR=13121000 SW=80000000 R[01]=0X00000003=3
PC=00000020 IR=13242000 SW=80000000 R[02]=0X00000003=3
PC=00000010 IR=26FFFFEC SW=80000000 R[15]=0X00000010=16
PC=00000014 IR=10230000 SW=80000000 R[12]=0X80000000=-2147483648
PC=00000018 IR=2300000C SW=80000000 R[00]=0X00000000=0
PC=0000001C IR=13121000 SW=80000000 R[01]=0X00000006=6
PC=00000020 IR=13242000 SW=80000000 R[02]=0X00000004=4
PC=00000010 IR=26FFFFEC SW=80000000 R[15]=0X00000010=16
PC=00000014 IR=10230000 SW=80000000 R[12]=0X80000000=-2147483648
PC=00000018 IR=2300000C SW=80000000 R[00]=0X00000000=0
PC=0000001C IR=13121000 SW=80000000 R[01]=0X0000000A=10
PC=00000020 IR=13242000 SW=80000000 R[02]=0X00000005=5
PC=00000010 IR=26FFFFEC SW=80000000 R[15]=0X00000010=16
PC=00000014 IR=10230000 SW=80000000 R[12]=0X80000000=-2147483648
PC=00000018 IR=2300000C SW=80000000 R[00]=0X00000000=0
PC=0000001C IR=13121000 SW=80000000 R[01]=0X0000000F=15
PC=00000020 IR=13242000 SW=80000000 R[02]=0X00000006=6
PC=00000010 IR=26FFFFEC SW=80000000 R[15]=0X00000010=16
PC=00000014 IR=10230000 SW=80000000 R[12]=0X80000000=-2147483648
PC=00000018 IR=2300000C SW=80000000 R[00]=0X00000000=0
PC=0000001C IR=13121000 SW=80000000 R[01]=0X00000015=21
PC=00000020 IR=13242000 SW=80000000 R[02]=0X00000007=7
PC=00000010 IR=26FFFFEC SW=80000000 R[15]=0X00000010=16
PC=00000014 IR=10230000 SW=80000000 R[12]=0X80000000=-2147483648
PC=00000018 IR=2300000C SW=80000000 R[00]=0X00000000=0
PC=0000001C IR=13121000 SW=80000000 R[01]=0X0000001C=28
PC=00000020 IR=13242000 SW=80000000 R[02]=0X00000008=8
PC=00000010 IR=26FFFFEC SW=80000000 R[15]=0X00000010=16
PC=00000014 IR=10230000 SW=80000000 R[12]=0X80000000=-2147483648
PC=00000018 IR=2300000C SW=80000000 R[00]=0X00000000=0
PC=0000001C IR=13121000 SW=80000000 R[01]=0X00000024=36
PC=00000020 IR=13242000 SW=80000000 R[02]=0X00000009=9
PC=00000010 IR=26FFFFEC SW=80000000 R[15]=0X00000010=16
PC=00000014 IR=10230000 SW=80000000 R[12]=0X80000000=-2147483648
PC=00000018 IR=2300000C SW=80000000 R[00]=0X00000000=0
PC=0000001C IR=13121000 SW=80000000 R[01]=0X0000002D=45
PC=00000020 IR=13242000 SW=80000000 R[02]=0X0000000A=10
PC=00000010 IR=26FFFFEC SW=80000000 R[15]=0X00000010=16
PC=00000014 IR=10230000 SW=40000000 R[12]=0X40000000=1073741824
PC=00000018 IR=2300000C SW=40000000 R[00]=0X00000000=0
PC=0000001C IR=13121000 SW=40000000 R[01]=0X00000037=55
PC=00000020 IR=13242000 SW=40000000 R[02]=0X0000000B=11
PC=00000010 IR=26FFFFEC SW=40000000 R[15]=0X00000010=16
PC=00000014 IR=10230000 SW=00000000 R[12]=0X00000000=0
PC=00000024 IR=2300000C SW=00000000 R[00]=0X00000000=0
PC=00000028 IR=2C000000 SW=00000000 R[00]=0X00000000=0
===CPU0 dump registers===
IR =0x2c000000=738197504
R[00]=0x00000000=0
R[01]=0x00000037=55
R[02]=0x0000000b=11
R[03]=0x0000000a=10
R[04]=0x00000001=1
R[05]=0x00000000=0
R[06]=0x00000000=0
R[07]=0x00000000=0
R[08]=0x00000000=0
R[09]=0x00000000=0
R[10]=0x00000000=0
R[11]=0x00000000=0
R[12]=0x00000000=0
R[13]=0x00000000=0
R[14]=0xffffffff=-1
R[15]=0x00000028=40
請按任意鍵繼續 . . .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment