# we have a mult.asm. Can anyone do it for division.asm

10 messages
Open this post in threaded view
|

## we have a mult.asm. Can anyone do it for division.asm

 This post was updated on . CONTENTS DELETED The author has deleted this message.
Open this post in threaded view
|

## Re: we have a mult.asm. Can anyone do it for division.asm

 CONTENTS DELETED The author has deleted this message.
Open this post in threaded view
|

## Re: we have a mult.asm. Can anyone do it for division.asm

 Administrator What type of algorithm are you expected to write? The division equivalent of the project 4 Mult.asm would be simple repeated subtraction. ```quotient = 0 while dividend >= divisor dividend = dividend - divisor quotient = quotient + 1 ```This will be really slow for large dividend / small divisor combinations. Do you have a .tst file that shows what range of values you need to divide? --Mark
Open this post in threaded view
|

## Re: we have a mult.asm. Can anyone do it for division.asm

 CONTENTS DELETED The author has deleted this message.
Open this post in threaded view
|

## Re: we have a mult.asm. Can anyone do it for division.asm

 Administrator That sounds like you can use the algorithm I posted above.  The code will be very similar except that you are incrementing R2 and subtracting R1 from R0. --Mark
Open this post in threaded view
|

## Re: we have a mult.asm. Can anyone do it for division.asm

 CONTENTS DELETED The author has deleted this message.
Open this post in threaded view
|

## Re: we have a mult.asm. Can anyone do it for division.asm

 Administrator You must write your own ASM code.  Use the pseudocode I posted above.  Here's a concrete example for 13 / 4 = 3: ```dividend divisor quotient 13 >= 4 0 -4 +1 9 >= 4 2 -4 +1 5 >= 4 3 -4 +1 1 < 4 4 stop ```The final dividend value is the remainder, if it's needed. --Mark
Open this post in threaded view
|

## Re: we have a mult.asm. Can anyone do it for division.asm

 In reply to this post by david CONTENTS DELETED The author has deleted this message.
 Administrator Labels are case sensitive; you have @Count and @count which are two different variables. R0>=R1 R0=R0-R1 These are not Hack instructions.  You need to do comparisons by subtracting and using conditional jumps.  What you want is something like. @R0 D-M @R1 D=D-M @END D;JLT I highly recommend that you start by writing the pseudocode as comments and then fill in the ASM that does the pseudocode. ```// quotient = 0 @R2 // quotient M=0 // while dividend >= divisor { (LOOP) @R0 // dividend D=M @R1 // divisor D=D-M @END D;JLT // dividend = dividend - divisor more code here // quotient = quotient + 1 more code here // } (END) @END 0;JMP ```--Mark