X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=math.asm;h=3b82bd49ccef3e290bc65a6e324ab17fc576e4a1;hb=b49fed131d5a7806d0737bdc6f9b693c64753cf2;hp=d25d14cd3da5aa77ce1082d63df771280c38ac85;hpb=f3bc3b97f37dd7bc012c152374d4185c734b3a7e;p=rrq%2Frrqforth.git diff --git a/math.asm b/math.asm index d25d14c..3b82bd4 100644 --- a/math.asm +++ b/math.asm @@ -4,38 +4,22 @@ ;; ( n1 n2 -- n3 ) ;; n3 is the sum of n1 and n2 pop rax - add [rsp],rax + add qword [rsp],rax next WORD p_minus, '-',fasm ;; ( n1 n2 -- n3 ) ;; n3 is the result of subtracting n2 from n1 pop rax - sub [rsp], rax + sub qword [rsp], rax next 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 @@ -56,4 +40,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 +