mcc

mcc is a machine code compiler.

Log | Files | << Repositories


tree 46de67c9b0216d7d7cb6faaa970b3cf6da0542c8
parent d09a0e78876208f12290517c1b6514770cffa16b
author esote <esote.net@gmail.com> 1570570565 -0500
committer esote <esote.net@gmail.com> 1570570565 -0500
gpgsig -----BEGIN PGP SIGNATURE-----
 
 iHUEABYIAB0WIQTXAxYDuIzimYoNSPuhTmRAjzzC8gUCXZ0BTAAKCRChTmRAjzzC
 8oL/AP4mSVVwJjl7qii8uDx3mdvaKhRHEq5vdp5HRvD8O+ypWgD9GW8k04mlB3kV
 Db96ztFffR7bnKwp5KtdDieT31p26gk=
 =ECRq
 -----END PGP SIGNATURE-----

Hex example, make with CC

 Makefile                                |  4 ++--
 hello_i386.mcc => ex/hello_i386.mcc     |  0
 hello_x86_64.mcc => ex/hello_x86_64.mcc |  0
 ex/hello_x86_64_hex.mcc                 | 19 +++++++++++++++++++
 4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index f97cf54..7d5d981 100644
--- a/Makefile
+++ b/Makefile
@@ -5,10 +5,10 @@ CFLAGS=		-O2 -fstack-protector -D_FORTIFY_SOURCE=2 -pie -fPIE
 LDFLAGS=	-Wl,-z,now -Wl,-z,relro
 
 $(PROG): $(SRCS)
-	gcc $(CFLAGS) $(LDFLAGS) -o $(PROG).out $(SRCS)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $(PROG).out $(SRCS)
 
 debug: $(SRCS)
-	gcc -g -Wall -Wextra -Wconversion -o $(PROG).out $(SRCS)
+	$(CC) -g -Wall -Wextra -Wconversion -o $(PROG).out $(SRCS)
 
 clean:
 	rm -f $(PROG).out
diff --git a/hello_i386.mcc b/ex/hello_i386.mcc
similarity index 100%
rename from hello_i386.mcc
rename to ex/hello_i386.mcc
diff --git a/hello_x86_64.mcc b/ex/hello_x86_64.mcc
similarity index 100%
rename from hello_x86_64.mcc
rename to ex/hello_x86_64.mcc
diff --git a/ex/hello_x86_64_hex.mcc b/ex/hello_x86_64_hex.mcc
new file mode 100644
index 0000000..5b3f981
--- /dev/null
+++ b/ex/hello_x86_64_hex.mcc
@@ -0,0 +1,19 @@
+; MCC
+
+; Compile with ./mcc.out -h -m 7 hello_x86_64_hex.mcc
+
+C7 04 25 00 20 40 00 48 00 00 00	; mov DWORD [buffer + 0], 'H'	; buffer is 0x402000
+C7 04 25 01 20 40 00 65 00 00 00	; mov DWORD [buffer + 1], 'e'
+C7 04 25 02 20 40 00 6C 00 00 00	; mov DWORD [buffer + 2], 'l'
+C7 04 25 03 20 40 00 6C 00 00 00	; mov DWORD [buffer + 3], 'l'
+C7 04 25 04 20 40 00 6F 00 00 00	; mov DWORD [buffer + 4], 'o'
+C7 04 25 05 20 40 00 21 00 00 00	; mov DWORD [buffer + 5], '!'
+C7 04 25 06 20 40 00 0A 00 00 00	; mov DWORD [buffer + 6], 0xA
+48 B8 01 00 00 00 00 00 00 00		; mov rax, 1			; sys_write
+48 BF 01 00 00 00 00 00 00 00		; mov rdi, 1			; stdout
+48 BE 00 20 40 00 00 00 00 00		; mov rsi, buffer
+48 BA 07 00 00 00 00 00 00 00		; mov rdx, 0x7			; buffer size
+0F 05					; syscall
+48 B8 3C 00 00 00 00 00 00 00		; mov rax, 60			; sys_exit
+48 BF 00 00 00 00 00 00 00 00		; mov rdi, 0			; exit success
+0F 05					; syscall