From: Ralph Ronnquist Date: Thu, 17 Jun 2021 07:13:43 +0000 (+1000) Subject: added max and min X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=a625fdad0d2d7723188c78b761d7ea8294464017;p=rrq%2Frrqforth.git added max and min --- diff --git a/adoc/p_max.adoc b/adoc/p_max.adoc new file mode 100644 index 0000000..b2ced15 --- /dev/null +++ b/adoc/p_max.adoc @@ -0,0 +1,12 @@ +// math.asm: WORD p_max, 'MAX',fasm + +anchor:p_max[] + +=== Word: MAX + +.... +Data stack: ( v1 v2 -- v3 ) +.... + +"MAX" is a function word that selects the greatest of v1 and v2. To +that end, the values are 64-bit signed integers. diff --git a/adoc/p_min.adoc b/adoc/p_min.adoc new file mode 100644 index 0000000..b34ad96 --- /dev/null +++ b/adoc/p_min.adoc @@ -0,0 +1,12 @@ +// math.asm: WORD p_min, 'MIN',fasm + +anchor:p_min[] + +=== Word: MIN + +.... +Data stack: ( v1 v2 -- v3 ) +.... + +"MIN" is a function word that selects the least of v1 and v2. To that +end, the values are 64-bit signed integers. diff --git a/math.asm b/math.asm index 3b82bd4..6248da9 100644 --- a/math.asm +++ b/math.asm @@ -32,6 +32,26 @@ p_abs_end: next + WORD p_max, 'MAX',fasm + ;; ( a b -- c ) + ;; c is the least a and b + pop rax + cmp rax,qword [rsp] + jle p_max_end + mov qword [rsp],rax +p_max_end: + next + + WORD p_min, 'MIN',fasm + ;; ( a b -- c ) + ;; c is the least a and b + pop rax + cmp rax,qword [rsp] + jge p_min_end + mov qword [rsp],rax +p_min_end: + next + WORD p_negate, 'NEGATE',fasm ;; ( n1 -- n2 ) ;; Negate n1, giving its arithmetic inverse n2. diff --git a/reference.adoc b/reference.adoc index b9f9b29..1326440 100644 --- a/reference.adoc +++ b/reference.adoc @@ -201,6 +201,10 @@ include::adoc/p_lparen.adoc[] include::separator.adoc[] include::adoc/p_malloc.adoc[] include::separator.adoc[] +include::adoc/p_max.adoc[] +include::separator.adoc[] +include::adoc/p_min.adoc[] +include::separator.adoc[] include::adoc/p_minus.adoc[] include::separator.adoc[] include::adoc/p_mult.adoc[] diff --git a/wordindex.adoc b/wordindex.adoc index 7cecd32..6e54229 100644 --- a/wordindex.adoc +++ b/wordindex.adoc @@ -126,6 +126,8 @@ xref:p_load_file[LOAD-FILE] {nbsp} xref:p_args[MAIN-ARGS] {nbsp} xref:p_malloc[MALLOC] {nbsp} +xref:p_min[MIN] {nbsp} +xref:p_max[MAX] {nbsp} xref:p_negate[NEGATE] {nbsp} xref:p_nip[NIP] {nbsp}