Merge pull request #63 from Russell-S-Harper/development

Simplifying code section
This commit is contained in:
Russell-S-Harper 2021-07-07 21:19:57 -04:00 committed by GitHub
commit 542af5f598
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 18 deletions

View File

@ -4,9 +4,8 @@
* = $300 ; any address outside of page zero is okay because all code is relocatable
CODE(DEMO)
RCD(DEMO)
START
CMN
SET(R0, 9.4662)
SET(R1, SQRT2)
@ -17,14 +16,15 @@ START
POP(R4)
SET(R5, E)
LDI(R6, R5)
SET(R1, ZERO)
SET(R1, ZER)
INR(R1)
SVI(R1, R6)
LDI(R0, R1)
ESC
BRK
BGN(FACTORIAL)
BEGIN(FACTORIAL)
POP(R1)
SET(R2, 1)
MOD(R3, R1, R2)
@ -36,18 +36,19 @@ _1 TST(R1)
BRA(_1)
_2 PSH(R2)
RTN
END(FACTORIAL)
END(DEMO)
DATA(_)
RDT(_)
; preset constants
DEFINE(PI, 3.14159)
DEFINE(E, 2.71828)
DEFINE(SQRT2, 1.41421)
DEF(PI, 3.14159)
DEF(E, 2.71828)
DEF(SQRT2, 1.41421)
; working space
RESERVE(2)
RES(2)
END(_)

View File

@ -78,23 +78,22 @@
#define EXT(f) .BYTE _EXT_C + (f)
; header for fixed code or data
#define FIXED(l) .BYTE _SM_FXD : .WORD l, _END_##l - l : * = * - 5 : l .(
#define FIX(l) .BYTE _SM_FXD : .WORD l, _END_##l - l : * = * - 5 : l .(
; header for relocatable code: l(abel) => starting offset, length of code
#define CODE(l) .BYTE _RLC_CD : .WORD _start - l, _END_##l - l : * = * - 5 : l .(
#define START &_start
#define RCD(l) .BYTE _RLC_CD : .WORD _rcd - l, _END_##l - l : * = * - 5 : l .( : &_rcd
; header for relocatable data: l(abel) => length of zeroed data, length of preset data
#define DATA(l) .BYTE _RLC_DT : .WORD _END_##l - _zero, _zero - l : * = * - 5 : l .( : &_data
#define RDT(l) .BYTE _RLC_DT : .WORD _END_##l - _zer, _zer - l : * = * - 5 : l .( : &_rdt
; define l(abel), v(alue)
#define DEFINE(l, v) &l .BYTE _SET_V(#v)
#define DEF(l, v) &l .BYTE _SET_V(#v)
; reserve c(ount) & provide an alias for _zero
#define RESERVE(c) &ZERO : &_zero : * = * + (c) * 4
; reserve c(ount) & provide an alias for _zer
#define RES(c) &ZER : &_zer : * = * + (c) * 4
; common begin and end
#define BEGIN(l) l .(
#define BGN(l) l .(
#define END(l) .) : _END_##l
#endif /* __MACROS_H */

View File

@ -39,7 +39,7 @@ int main(int argc, char **argv)
q = strrchr(tokens[i].text, '"');
j = (int)(q - p);
/* Output in .BYTE format - this code is actually dependent on EXP_FRAC */
printf("0, <(%.*s - _data), >(%.*s - _data), 0", j, p, j, p);
printf("0, <(%.*s - _rdt), >(%.*s - _rdt), 0", j, p, j, p);
break;
/* Process each _SET_V("<expression>") command */
case TT_EXPRESSION: