To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcxOpen lugnet.robotics.rcx in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / 1622
1621  |  1623
Subject: 
Re: h8/300 16-bit multiply
Newsgroups: 
lugnet.robotics.rcx
Date: 
Mon, 4 Mar 2002 19:32:54 GMT
Viewed: 
2920 times
  
Thanks.  I have a version just 2 words longer that doesn't use the ROM
code.  Basically it's the ROM's code, trimmed down after assuming high
words are zero initially.  It's completely untested though, so there
may be a bug.

CODE UM*
    \ 16x16=32 multiply
    \ R6 is first argument, top of stack is second, overwritten with result
    \ R0,R1,R2 are scratch
    \
    mov.w   @R7, R5
    mov.w   R6, R1      \ keep copies of arguments
    mov.w   R5, R2
    mov.b   R6h, R6l    \ Ah*Bh
    mulxu.b R5h, R6
    mulxu.b R1l, R5     \ Al*Bl
    mov.b   R1l, R0l    \ Al*Bh
    mulxu.b R2h, R0
    add.b   R0l, R5h    \ add to result
    addx.b  R0h, R6l
    addx.b  #0, R6h
    mov.b   R1h, R0l    \ Ah*Bl
    mulxu.b R2l, R0
    add.b   R0l, R5h    \ add to result
    addx.b  R0h, R6l
    addx.b  #0, R6h
    mov.w   R5, @R7     \ low word of result
    next
END-CODE

Yes, it's for my own Forth; given that it's for Mindstorms, reinventing
the wheel is supposed to be half the fun.

By the way:  in your code a "MOV.W #0x0000,r5" takes 4 bytes,
whereas "SUB.W r5,r5" takes only 2 bytes.

--
Darin Johnson
    Support your right to own gnus.



Message has 1 Reply:
  RE: h8/300 16-bit multiply
 
(...) <snipped code...> Are you sure that it works for signed numbers :-) (...) If you like, I can give you some notes on how my Forth was developed. I'm using a simple pseudo-assembler that lets me port this Forth to a new processor in less than a (...) (23 years ago, 4-Mar-02, to lugnet.robotics.rcx)

Message is in Reply To:
  RE: h8/300 16-bit multiply
 
(...) The easiest thing is to cast your 16 bit values to 32 bits and use the built-in 32x32 multiply... Here's the code from pbForth that does it. (It's written in a pseudo- assebler, but you can probably figure it out...) #---...--- # UM* UM* ( u1 (...) (23 years ago, 4-Mar-02, to lugnet.robotics.rcx)

4 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR