changeset 25:e84ea6c0d359

add README
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 11 Oct 2024 15:33:59 +0900
parents aecd80408312
children 8550260c18fa
files .DS_Store CMakeLists.txt README.md s-code-arm-mac.c
diffstat 4 files changed, 21 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
Binary file .DS_Store has changed
--- a/CMakeLists.txt	Wed Oct 26 17:37:18 2022 +0900
+++ b/CMakeLists.txt	Fri Oct 11 15:33:59 2024 +0900
@@ -1,4 +1,5 @@
 cmake_minimum_required(VERSION 3.24)
+project(compiler-example)
 add_definitions("-Wall -g")
 enable_testing()
 set(CMAKE_C_FLAGS_DEBUG "-O")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Fri Oct 11 15:33:59 2024 +0900
@@ -0,0 +1,10 @@
+# How to build small compiler examples
+
+# on macOS
+
+```
+ brew install cmake
+ export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
+ cmake -DCMAKE_MAKE_PROGRAM=make 
+```
+
--- a/s-code-arm-mac.c	Wed Oct 26 17:37:18 2022 +0900
+++ b/s-code-arm-mac.c	Fri Oct 11 15:33:59 2024 +0900
@@ -73,7 +73,8 @@
 void
 emit_compare()
 {
-    printf("\tldr x1,[sp, 8]!\n");
+    printf("\tldr x1,[sp]\n");
+    printf("\tadd sp,sp,#8\n");
     printf("\tcmp x0,x1\n");
 }
 
@@ -111,16 +112,20 @@
 emit_calc(enum opcode op)
 {
     if(op==O_DIV ) {
-        printf("\tldr x1,[sp , #16]! \n");
+        printf("\tldr x1,[sp]\n");
+        printf("\tadd sp,sp,8\n");
         printf("\tsdiv x0 ,x1 , x0\n");
     } else if( op==O_DIV_R ) {
-        printf("\tldr x1,[sp , #16]! \n");
+        printf("\tldr x1,[sp]\n");
+        printf("\tadd sp,sp,#8\n");
         printf("\tsdiv x1 ,x0 , x0\n");
     } else if(op==O_SUB) {
-        printf("\tldr x1,[sp , #16]! \n");
+        printf("\tldr x1,[sp]\n");
+        printf("\tadd sp,sp,#8\n");
         printf("\tsub x1 ,x0 , x0\n");
     } else {
-        printf("\tldr x1,[sp , #16]! \n");
+        printf("\tldr x1,[sp]\n");
+        printf("\tadd sp,sp,#8\n");
         printf("\t%s x1 ,x0 , x0\n",opcode[op]);
     }
 }