Skip to content

Commit 8a5826f

Browse files
committed
Add a math library and use macro
1 parent b9b7e66 commit 8a5826f

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

os/math.asm

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@include <arithmetic>
2+
@include <flow>
3+
@include <util>
4+
5+
/// Arguments: A, B
6+
/// Return: A
7+
mul:
8+
push B, C
9+
mv C, B
10+
mv B, A
11+
jz C, [.done]
12+
.loop
13+
add A, B
14+
dec C
15+
jnz C, [.loop]
16+
.done:
17+
pop C, B
18+
ret

src/assembler/macros.asm

+13-3
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,23 @@
277277
add %reg, 1
278278
}
279279
; 16-bit
280-
(%low:reg, %high:reg) {
280+
(%high:reg, %low:reg) {
281281
add %low, 1
282282
adc %high, 0
283283
}
284284
}
285285

286286
/// Decrements the given value
287-
@macro dec (%reg:reg) {
288-
sub %reg, 1
287+
@macro dec {
288+
; 8-bit
289+
(%reg:reg) {
290+
sub %reg, 1
291+
}
292+
; 16-bit
293+
(%high:reg, %low:reg) {
294+
sub %low, 1
295+
sbb %high, 0
296+
}
289297
}
290298

291299
/// Bitwise inverts the given byte
@@ -310,3 +318,5 @@
310318
@macro nop () {
311319
mv A, A ; shortest instruction with no side effects: 3 clock cycles
312320
}
321+
322+
@macro use(%label:ident|label) {}

0 commit comments

Comments
 (0)