X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=math.asm;h=6248da98ab9bdf7b872337ac195d33974f6a670e;hb=a625fdad0d2d7723188c78b761d7ea8294464017;hp=5547b57c136372053e937d9ad82a61449d4d9c4a;hpb=fc23b0f6fecc27bceb7f1f781bc78d3133cbbd4c;p=rrq%2Frrqforth.git diff --git a/math.asm b/math.asm index 5547b57..6248da9 100644 --- a/math.asm +++ b/math.asm @@ -16,26 +16,10 @@ WORD p_mult, '*',fasm ;; ( n1 n2 -- n3 ) - ;; Multiply n1 by n2 giving the product n3. - ;; [rsp{8}] * [rsp+8{8}] - ;; dd00 = [rsp+4{4}]*[rsp+12{4}] ignored - ;; needs checking !! - ;; - ;; 0cc0 = [rsp{4}]*[rsp+12{4}] - mov eax, dword [rsp] - imul dword [rsp+12] - mov ebx,eax - ;; 0bb0 = [rsp+4{4}]*[rsp+8{4}] - mov eax, dword [rsp+4] - imul dword [rsp+8] - add ebx, eax - ;; 00aa = [rsp{4}]*[rsp+8{4}] - mov eax, dword [rsp] - imul dword [rsp+8] - add ebx, edx - shl rbx,32 - mov eax,eax ; ensure zero-extending eax - add rax, rbx + ;; multiply n1 * n2 to n3 ignoring overflow + pop rax + pop rbx + imul rax,rbx push rax next @@ -48,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. @@ -56,4 +60,24 @@ p_abs_end: mov qword [rsp],rax next - + WORD p_divmod,'/MOD',fasm + ;; ( x y -- q r ) + ;; divide signed x/y giving quotient q and remainder r + pop rbx + pop rax + xor rdx,rdx + idiv rbx + push rax + 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 +