Skip to content

Commit 1838708

Browse files
committed
minor changes
1 parent 4893f0e commit 1838708

5 files changed

Lines changed: 31 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ NewASM features many instructions, around 70 of them. Here is a list:
159159
8. [Union-related instructions](docs/instructions/union.md)
160160
9. [Switch block instructions](docs/instructions/switch.md)
161161
10. [I/O port-related instructions](docs/instructions/ioports.md)
162-
162+
11. [Calculated calls and returns](docs/instructions/calc.md)
163163

164164
***
165165
#### Language concepts

changelog/build29.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Welcome to **`NewASM`**: an interpreted low-level programming language which com
2424
.start
2525
mov rax, *rax ; this will get removed immediatelly
2626
```
27+
+ Added instructions for calculated calls and returns, mimicking how real functions that C/C++ compiler generates.
2728

2829
## Fixed issues
2930

docs/instructions/calc.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Calculated calls and returns
2+
3+
> [!WARNING]
4+
> This feature was added in build 29.
5+
6+
```asm
7+
.start
8+
jmp main
9+
:label
10+
mov tlr, "Hello from func"
11+
call std::ios::writeln
12+
retc
13+
:main
14+
callc label
15+
mov tlr, "Hello from proc"
16+
call std::ios::writeln
17+
ret 0
18+
```

src/runtime/common/opcodes.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,14 @@ namespace newasm
8383
{71, newasm::core::lang_inf::instruction_set.at(newasm::core::lang_inf::mod__)},
8484
{72, newasm::core::lang_inf::instruction_set.at(newasm::core::lang_inf::loop)},
8585
{73, newasm::core::lang_inf::instruction_set.at(newasm::core::lang_inf::movx)},
86+
{74, newasm::core::lang_inf::instruction_set.at(newasm::core::lang_inf::callc)},
87+
{75, newasm::core::lang_inf::instruction_set.at(newasm::core::lang_inf::retc)},
88+
{76, newasm::core::lang_inf::instruction_set.at(newasm::core::lang_inf::xcgh)},
89+
{77, newasm::core::lang_inf::instruction_set.at(newasm::core::lang_inf::retf)},
90+
{78, newasm::core::lang_inf::instruction_set.at(newasm::core::lang_inf::await__)},
8691

87-
{100, newasm::core::lang_inf::instruction_set.at(newasm::core::lang_inf::__say)}
92+
{99, newasm::core::lang_inf::instruction_set.at(newasm::core::lang_inf::__say)},
93+
{100, newasm::core::lang_inf::instruction_set.at(newasm::core::lang_inf::Link___)}
8894
};
8995
}
9096
}

src/runtime/lang_inf.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,41 +109,34 @@ namespace newasm
109109
const int await__ = 50;//
110110
const int retf = 51;//
111111
const int vmov = 52;//
112-
113112
const int switch__ = 53;//
114113
const int case__ = 54;//
115114
const int default__ = 55;//
116-
117115
const int in__ = 56;//
118116
const int out__ = 57;//
119-
120117
const int cast__ = 58;//
121118
const int async__ = 59;//
122-
123119
const int lea = 60;//
124120
const int thread__ = 61;//
125-
126121
const int send = 62;//
127122
const int recv = 63;//
128-
129123
const int del = 64;//
130124
const int movaddr = 65;//
131-
132125
const int jz = 66;//
133126
const int jnz = 67;//
134127

135128
const int movasx = 68;//
136129
const int movas = 69;//
137-
138130
const int sel = 70;//
139131
const int align = 71;//
140-
141132
const int merge = 72;//
142133
const int evt = 73;//
143134

144135
const int mod__ = 74;//
145136
const int loop = 75;//
146137
const int movx = 76;//
138+
const int callc = 77;//
139+
const int retc = 78;//
147140

148141
/// @brief //////
149142
const int Link___ = 99;
@@ -241,6 +234,8 @@ namespace newasm
241234
{loop, "loop"},
242235

243236
{movx, "movx"},
237+
{callc, "callc"},
238+
{retc, "retc"},
244239

245240
{__say, "__say"},
246241
{Link___, "link"}

0 commit comments

Comments
 (0)