From: Ralph Ronnquist Date: Fri, 28 May 2021 06:56:01 +0000 (+1000) Subject: added / (div) primitive X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=6d4bf76e83379163ae7e027807f79f6cb14a9799;p=rrq%2Frrqforth.git added / (div) primitive --- diff --git a/adoc/p_div.adoc b/adoc/p_div.adoc new file mode 100644 index 0000000..bbd1ba0 --- /dev/null +++ b/adoc/p_div.adoc @@ -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 +.... diff --git a/adoc/p_divmod.adoc b/adoc/p_divmod.adoc index 5e8f2a9..432e379 100644 --- a/adoc/p_divmod.adoc +++ b/adoc/p_divmod.adoc @@ -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: diff --git a/math.asm b/math.asm index c678d11..3b82bd4 100644 --- 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 + diff --git a/reference.adoc b/reference.adoc index 4c79c23..832820d 100644 --- a/reference.adoc +++ b/reference.adoc @@ -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[] diff --git a/wordindex.adoc b/wordindex.adoc index b3cd87b..6ee602e 100644 --- a/wordindex.adoc +++ b/wordindex.adoc @@ -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}