added max and min
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Thu, 17 Jun 2021 07:13:43 +0000 (17:13 +1000)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Thu, 17 Jun 2021 07:13:43 +0000 (17:13 +1000)
adoc/p_max.adoc [new file with mode: 0644]
adoc/p_min.adoc [new file with mode: 0644]
math.asm
reference.adoc
wordindex.adoc

diff --git a/adoc/p_max.adoc b/adoc/p_max.adoc
new file mode 100644 (file)
index 0000000..b2ced15
--- /dev/null
@@ -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 (file)
index 0000000..b34ad96
--- /dev/null
@@ -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.
index 3b82bd49ccef3e290bc65a6e324ab17fc576e4a1..6248da98ab9bdf7b872337ac195d33974f6a670e 100644 (file)
--- a/math.asm
+++ b/math.asm
 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. 
index b9f9b29c321d25b75a07719e675e1dd10baa752f..132644040acc4ca276ab7febaa27654da411a793 100644 (file)
@@ -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[]
index 7cecd32542f837412ab2d7687c6969a76542931d..6e54229a7199675511328b1da1ba9aac7032f203 100644 (file)
@@ -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}