Skip to content

Instantly share code, notes, and snippets.

View crcx's full-sized avatar

Charles Childers crcx

View GitHub Profile
~~~
:pipe> (s-s) file:R unix:popen [ file:read-line ] [ unix:pclose ] bi ;
:>pipe> (ss-s) swap 'echo_"%s"_|_%s s:format dup s:put nl pipe> ;
:>pipe (ss-) >pipe> drop ;
:prefix:^ (?ss-s) [ s:format ] dip '%s_%s s:format pipe> ; immediate
~~~
```
'-a '%s ^uname s:put
```
: MATRIX ( m[rows] n[cols] -- c-addr )
HERE >R
SWAP , ,
R>
DUP @ SWAP
DUP 1 CELLS + @ SWAP
>R
* CELLS ALLOT
R>
;
@crcx
crcx / see.md
Last active December 28, 2018 19:05

SEE

crc: d:words but no d:see ?

Retro includes a disassembler as part of the Autopsy debugger, but it's not quite a replacement for a traditional see as it requires both a starting address and the length. I decided to implement a see word using the disassembler. (This will likely be rolled into Autopsy soon).

Implementation

RETRO: a Modern, Pragmatic Forth

Welcome to RETRO, my personal take on the Forth language. This is a modern system primarily targetting desktop, mobile, and servers, though it can also be used on some larger (ARM, MIPS32) embedded systems.

The language is Forth. It is untyped, uses a stack to pass data between functions called words, and a dictionary which tracks the word names and data structures.

RETRO: a Modern, Pragmatic Forth

Welcome to RETRO, my personal take on the Forth language. This is a modern system primarily targetting desktop, mobile, and servers, though it can also be used on some larger (ARM, MIPS32) embedded systems.

The language is Forth. It is untyped, uses a stack to pass data between functions called words, and a dictionary which tracks the word names and data structures.

14838 'zr...... i
14839 'du...... i
14840 'lica.... i
14841 #8660 d [possibly `n:put`]
14842 'lica.... i
14843 #8615 d [possibly `sp`]
14844 'lica.... i
14845 #2847 d [possibly `n:dec`]
14846 'lica.... i
14847 #14837 d [possibly `foo`]
14838 'zr...... i
14839 'du...... i
14840 'lica.... i
14841 #8660 d [possibly `n:put`]
14842 'lica.... i
14843 #8615 d [possibly `sp`]
14844 'lica.... i
14845 #2847 d [possibly `n:dec`]
14846 'liju.... i
14847 #14837 d [possibly `foo`]

Comparison of Address/Length Strings

This implements a word to compare address/length strings (or other data) in RETRO.


cmp-bytes fetches a byte from each memory location and compares them.

:cmp-bytes (ss-ssf

A standard RETRO image only supports decimal base numbers. This shows a way to add support for multiple bases. (Borrowing from KipIngram and zy]x[yz in #forth irc channel).

Once loaded, numbers can be used like:

#[-][decimal radix:]digits

Examples:

#100

backtrace
#0 0x00000008008debbd in _pthread_mutex_init_calloc_cb () from /lib/libc.so.7
#1 0x00000008008d868f in _pthread_mutex_init_calloc_cb () from /lib/libc.so.7
#2 0x00000008008d9767 in _pthread_mutex_init_calloc_cb () from /lib/libc.so.7
#3 0x00000008008c0baf in _malloc_thread_cleanup ()
from /lib/libc.so.7
#4 0x00000008008e1bba in malloc ()
from /lib/libc.so.7
#5 0x000000080097b35d in memcpy ()
from /lib/libc.so.7