added / (div) primitive
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Fri, 28 May 2021 06:56:01 +0000 (16:56 +1000)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Fri, 28 May 2021 06:56:01 +0000 (16:56 +1000)
adoc/p_div.adoc [new file with mode: 0644]
adoc/p_divmod.adoc
math.asm
reference.adoc
wordindex.adoc

diff --git a/adoc/p_div.adoc b/adoc/p_div.adoc
new file mode 100644 (file)
index 0000000..bbd1ba0
--- /dev/null
@@ -0,0 +1,19 @@
+// math.asm:   WORD p_div,'/',fasm
+
+anchor:p_div[]
+
+=== Word: /
+
+....
+Data stack: ( v1 v2 -- q )
+....
+
+"/" (div) is a function word that replaces a pair of values with the
+results of signed integer division of the first, v1, divided by the
+second, v2. To that end, the values are 64-bit signed integers. The
+result is the integer quotient, q, and the discarded remainder, r,
+where q and r are the respectively largest and smallest integers to
+satisfy the formula:
+....
+       v1 = q * v2 + r
+....
index 5e8f2a9034005d846e7a946556ceede4a1ea0f40..432e37926f3ce572a935dc8986f71d155a06d6fd 100644 (file)
@@ -10,7 +10,7 @@ Data stack: ( v1 v2 -- q r )
 
 "/MOD" (div-mod) is a function word that replaces a pair of values
 with the results of signed integer division of the first, v1, divided
-by the scond, v2. To that end, the values are 64-bit signed integers.
+by the second, v2. To that end, the values are 64-bit signed integers.
 The result is the integer quotient, q, and the remainder, r, where q
 and r are the respectively largest and smallest integers to satisfy
 the formula:
index c678d116d253a36486274e8f8fb4536eae550837..3b82bd49ccef3e290bc65a6e324ab17fc576e4a1 100644 (file)
--- a/math.asm
+++ b/math.asm
@@ -42,7 +42,7 @@ p_abs_end:
 
        WORD p_divmod,'/MOD',fasm
        ;; ( x y -- q r )
-       ;; divide signed x/y giving quotient q and reminder r
+       ;; divide signed x/y giving quotient q and remainder r
        pop rbx
        pop rax
        xor rdx,rdx
@@ -51,3 +51,13 @@ p_abs_end:
        push rdx
        next
 
+       WORD p_div,'/',fasm
+       ;; ( x y -- q )
+       ;; divide signed x/y giving quotient q and discard remainder
+       pop rbx
+       pop rax
+       xor rdx,rdx
+       idiv rbx
+       push rax
+       next
+
index 4c79c23c1d218ff29ea77be8c65e97e2a8395a03..832820de18b63cb6879ccf0584c660ffc3ad46c4 100644 (file)
@@ -12,6 +12,7 @@ include::adoc/p_colon.adoc[]
 include::adoc/p_comma.adoc[]
 include::adoc/p_create.adoc[]
 include::adoc/p_decimal.adoc[]
+include::adoc/p_div.adoc[]
 include::adoc/p_does.adoc[]
 include::adoc/p_evaluate_stream.adoc[]
 include::adoc/p_here.adoc[]
index b3cd87bf9c49a82de8fe5f8339b634ef2c352f97..6ee602e6f6af878835a16fee8ce1c4e55a53c6b0 100644 (file)
@@ -1,38 +1,41 @@
 
 == Index of word links
 
-xref:p_colon[:] {nbsp}
-xref:p_comma[', (comma)'] {nbsp}
-xref:p_dot['. (dot)'] {nbsp}
-xref:p_double_quote["] {nbsp}
-xref:p_equal[= ] {nbsp}
-xref:p_left_bracket[[] {nbsp}
-xref:p_lessequal[<] {nbsp}
+xref:p_colon[: (colon)] {nbsp}
+xref:p_semicolon[: (semi-colon)] {nbsp}
+xref:p_comma[, (comma)] {nbsp}
+xref:p_dot[. (dot)] {nbsp}
+xref:p_double_quote[" (double-quote)] {nbsp}
+xref:p_quote[' (single-quote)] {nbsp}
+xref:p_left_bracket[[ (left bracket)] {nbsp}
+xref:p_right_bracket[\] (right bracket)] {nbsp}
+
 xref:p_lessthan[<] {nbsp}
+xref:p_equal[= ] {nbsp}
+xref:p_greaterthan[>] {nbsp}
 xref:p_lparen[(] {nbsp}
 xref:p_minus[ - ] {nbsp}
 xref:p_mult[*] {nbsp}
 xref:p_plus[+] {nbsp}
-xref:p_right_bracket[']'] {nbsp}
-
+xref:p_div[/] {nbsp}
+{nbsp}
 xref:p_0equal[0=] {nbsp}
 xref:p_0less[0<] {nbsp}
-xref:p_Ccomma[C,] {nbsp}
+xref:p_lessequal[\<=] {nbsp}
+xref:p_unequal[!=] {nbsp}
 xref:p_greaterequal[>= ] {nbsp}
-xref:p_greaterthan[>] {nbsp}
-xref:p_gtR[>R] {nbsp}
-xref:p_lessequal[<=] {nbsp}
+xref:p_Ccomma[C,] {nbsp}
 xref:p_literal_string[S"] {nbsp}
+xref:p_gtR[>R] {nbsp}
 xref:p_Rget[R@] {nbsp}
 xref:ef:p_Rgt[R>] {nbsp}
-xref:p_unequal[!=] {nbsp}
 
 
 xref:data_stack[DATA-STACK] {nbsp}
 xref:return_stack[RETURN-STACK] {nbsp}
-
+{nbsp}
 xref:p_0branch[0BRANCH] {nbsp}
-
+{nbsp}
 xref:p_2drop[2DROP] {nbsp}
 xref:p_2dup[2DUP] {nbsp}
 xref:p_2over[2OVER] {nbsp}