Skip to content

Commit 2ff70dd

Browse files
committed
Finish explaining built-in macros
1 parent fd91a1c commit 2ff70dd

File tree

2 files changed

+140
-3
lines changed

2 files changed

+140
-3
lines changed

README.md

+137
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ Example:
338338

339339
The assembly is divided into segments, specified with the `@cseg` and `@dseg` directives,
340340
and organized by the `@org` directive.
341+
The `@org` directive will apply to the current segment, and can only be specified once per segment.
341342
Segments can be used to organize blocks of data and code throughout the address space.
342343

343344
#### Code Segments
@@ -473,6 +474,21 @@ jnz 1
473474
* [JLE](#jle-macro)
474475
* [JGT](#jgt-macro)
475476
* [JGE](#jge-macro)
477+
* [JEQ](#jeq-macro)
478+
* [JZ](#jz-macro)
479+
* [CALL](#call-macro)
480+
* [RET](#ret-macro)
481+
* [MV16](#mv16-macro)
482+
* [ADD16](#add16-macro)
483+
* [SUB16](#sub16-macro)
484+
* [INC](#inc-macro)
485+
* [DEC](#dec-macro)
486+
* [NOT](#not-macro)
487+
* [AND](#and-macro)
488+
* [XOR](#xor-macro)
489+
* [SHL](#shl-macro)
490+
* [NOP](#nop-macro)
491+
* [USE](#use-macro)
476492

477493
#### PUSH Macro
478494

@@ -620,6 +636,127 @@ Jumps to the location pointed to by the HL registers if *x* >= *y*.
620636

621637
Jumps to *location* if *x* >= *y*.
622638

639+
#### JEQ Macro
640+
641+
`jeq`
642+
643+
Jumps to the address pointed to by the HL registers if the `E` flag in the status register is set.
644+
645+
`jeq location: label`
646+
647+
Jumps to *location* if the `E` flag in the status register is set.
648+
649+
`jeq x: reg, y: reg|imm`
650+
651+
Jumps to the location pointed to by the HL registers if *x* == *y*.
652+
653+
`jeq x: reg, y: reg|imm, location: label`
654+
655+
Jumps to *location* if *x* == *y*.
656+
657+
#### JZ Macro
658+
659+
`jz condition: reg|imm, location: label`
660+
661+
Jumps to *location* if *condition* is 0.
662+
663+
#### CALL Macro
664+
665+
`call`
666+
667+
Pushes the return address to the stack and jumps to the address pointed to by the HL registers.
668+
Designed to be paired with the `ret` macro.
669+
670+
`call location: label`
671+
672+
Pushes the return address to the stack and jumps to *location*.
673+
Designed to be paired with the `ret` macro.
674+
675+
#### RET Macro
676+
677+
`ret`
678+
679+
Jumps to the address stored at the *top* of the stack.
680+
681+
#### MV16 Macro
682+
683+
`mv16 high: reg, low: reg, imm: imm`
684+
685+
Moves a 16-bit immediate integer into the provided registers.
686+
687+
#### ADD16 Macro
688+
689+
`add16 h0: reg, l0: reg, h1: reg|imm, l1: reg|imm`
690+
691+
Adds two 16-bit integers.
692+
*h0* and *l0* make up the high and low bytes of the first operand,
693+
with *h1* and *l1* making up the high and low bytes of the second operand.
694+
695+
#### SUB16 Macro
696+
697+
`sub16 h0: reg, l0: reg, h1: reg|imm, l1: reg|imm`
698+
Subtracts two 16-bit integers.
699+
*h0* and *l0* make up the high and low bytes of the first operand,
700+
with *h1* and *l1* making up the high and low bytes of the second operand.
701+
702+
#### INC Macro
703+
704+
`inc reg: reg`
705+
706+
Adds 1 to the value contained in *reg*, storing the result back in *reg*.
707+
708+
`inc high: reg, low: reg`
709+
710+
Adds 1 to the 16-bit value contained in *high* and *low*,
711+
storing the result back in *high* and *low*.
712+
713+
#### DEC Macro
714+
715+
`dec reg: reg`
716+
717+
Subtracts 1 from the value contained in *reg*, storing the result back in *reg*.
718+
719+
`dec high: reg, low: reg`
720+
721+
Subtracts 1 from the 16-bit value contained in *high* and *low*,
722+
storing the result back in *high* and *low*.
723+
724+
#### NOT Macro
725+
726+
`not reg: reg`
727+
728+
Performs a bitwise NOT operation on *reg*, storing the result back in *reg*.
729+
730+
#### AND Macro
731+
732+
`and x: reg, y: reg|imm`
733+
734+
Performs a bitwise AND operation on *x* and *y*, storing the result in *x*.
735+
736+
#### XOR Macro
737+
738+
`and x: reg, y: reg|imm`
739+
740+
Performs a bitwise XOR operation on *x* and *y*, storing the result in *x*.
741+
742+
#### SHL Macro
743+
744+
`shl reg: reg`
745+
746+
Performs a logical shift left on *reg*, storing the result back in *reg*
747+
748+
#### NOP Macro
749+
750+
`nop`
751+
752+
Performs an operation that has no effect, taking 4 clock cycles (the same as `ADD`).
753+
754+
#### USE Macro
755+
756+
`use label: label|ident`
757+
758+
Eliminates the `warning: unused label definition` message for *label*.
759+
623760
## Emulator
624761

625762
## Tests

examples/box.asm

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
@define WALL 0xBA
1414
@define DASH 0xCD
1515

16-
@org 0x0000
17-
jmp [_start]
18-
1916
/// math = ./math
2017
@include <math/mul.asm>
2118

19+
@cseg
20+
@org 0x0000
21+
2222
_start:
2323
call [draw_top]
2424
call [draw_bottom]

0 commit comments

Comments
 (0)