2024 September 28
defer, _start
:, _emit ( n - )
$2A x0 a7 ori, ecall, ;,
:, .h CHAR h x0 a0 ori, _emit ;,
:, .e CHAR e x0 a0 ori, _emit ;,
:, .l CHAR l x0 a0 ori, _emit ;,
:, .o CHAR o x0 a0 ori, _emit ;,
:, .hello ( - )
.h .e .l .l .o cr ;,
' .hello >BODY @ is, _start
ORI Xn,X0,$ABC ; only 12 bit immediate
LUI Xn,$ABCDF000 ; Upper 20 bits loaded as immediate
ADDI Xn,Xn,$F12 ; Lower 12 bits merged in
; BTW, why $ABCDF000 and not $ABCDE000? ;-)
AUIPC Xn,ConstantPool-* ; Xn = PC + (ConstantPool - PC) = ConstantPool
LD Xm,offset(Xn) ; LD = Load Double-word
JAL
instruction, which records a return address in any arbitrary register. JAL X0,branchTarget ; Unconditional JUMP to branchTarget
JAL X1,branchTarget ; Unconditional CALL to branchTarget
...
JAL X31,branchTarget ; Unconditional CALL to branchTarget
JAL X4,forwardLabel
.word arbitrary-data-goes-here ; guaranteed 4-byte alignment!
.byte padding-if-required
forwardLabel:
ORI X5,X0,size-of-data-goes-here
quote,
( reg - cs-quo ) encodes the initial JAL instruction.unquote,
( cs-quo reg - ) encodes the final target and, if reg != 0, calculates the length of the blob skipped.: defer, ( - ) : S", ( - )
CREATE 0 quote, , ( JAL X0,... ) nextReg quote,
DOES> @ THERE - ra jal, ; ( ..place string at HERE.. )
nextReg unquote, ;
: is, ( a - )
' >BODY @ SWAP OVER ( aJAL a aJAL )
- ( aJAL disp )
SWAP mergeU ;
: quote, ( xr -- aJAL )
( Jumps AHEAD, except sets xr to point at code immediately following. )
THERE SWAP 0 SWAP jal, ;
: unquote, ( aJAL xr -- )
( Resolves prior quote, and sets xr to length of block spanned. )
OVER THERE SWAP - 4 - ( aJAL xr len; 4 accounts for JAL insn )
TALIGN >R >R ( aJAL || xr len )
THERE OVER - ( aJAL disp || xr len )
OVER mergeU R> R> ( xr len )
OVER IF
SWAP x0 SWAP ori,
ELSE
2DROP
THEN ;
S", Hello world" _type
sort
routine might work, as in C’s standard library). vectorAddr vectorLength (<< ( a b - f ) 2DUP U< >>) SortVector
\ Code quotation ---^-------------------------^
:, myState ( - )
gp quote, /MY-STATE TALLOT TALIGN x0 unquote, ;,
Thank you for watching; I’ll be happy to answer questions via the Generalities mailing list.